Optimization with MultiStart with nonlinear constraint on some of the parameters
3 次查看(过去 30 天)
显示 更早的评论
Hi
I have an optimization problem where I use MultiStart to regress three unknown model parameters to some experimental data. All the parameters are bounded but only two out of three of these parameters follow a nonlinear constraint which I provide using the following code:
c = @(x) 2 - x(2) * (x(3)/r_nm(1))^3;
ceq = @(x) [];
nonlcon_EMT = @(x) deal(c(x),ceq(x));
where r_nm(1) is a known number (fixed). Note that in the function nonlcon_EMT x(1) is not used in the calculation of c or ceq but it is passed to the function. Then I used the following code to perform the regression:
objFcn = @(x) extinction(lambda,Abs(:,2),T,r_nm(1),0,rho(1),rho_CV(1),eta(1),4/3,x(1),x(2),x(3),[ones(1,5),scaleFact],0,400,1000,0);
ms = MultiStart('FunctionTolerance',1e-3,'XTolerance',1e-2,'StartPointsToRun','bounds-ineqs',...
'MaxTime',600,'UseParallel',true);
problem = createOptimProblem('fmincon','x0',[1e-4,0.3,500].*scaleFact,'objective',objFcn,...
'lb',[1e-6,1e-3,25].*scaleFact,...
'ub',[1,0.5,1000].*scaleFact,...
'nonlcon',nonlcon_EMT);
[x,fval(2),exitflag(2)] = run(ms,problem,10);
When I run the code above with 'StartPointsToRun','bounds' there is no problem. Yet, using 'StartPointsToRun','bounds-ineqs' it gives the following error:
Unable to perform assignment because the left and right sides have a different
number of elements.
I was wondering if someone could help me with this problem. Thank you.
0 个评论
回答(1 个)
Alan Weiss
2018-8-15
编辑:Alan Weiss
2018-8-15
Try writing a function file to represent your nonlinear constraints:
function [c,ceq] = nonlcon_EMT(x,r_nm)
ceq = [];
c = 2 - x(2) * (x(3)/r_nm(1))^3;
In your script, after defining r_nm in the workspace, set
nlcon = @(x)nonlcon_EMT(x,r_nm);
and, of course, set nlcon as the nonlinear constraint in your problem structure.
Why might this work? The deal function insists on having two outputs, but when you set inequalities as the start points, MultiStart calls the nonlinear constraint for only the inequality, ignoring the equality constraint (it doesn't matter that your equality constraint is null). By ignoring the equality constraint, I believe that deal throws an error.
Alan Weiss
MATLAB mathematical toolbox documentation
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Programming and Mixed-Integer Linear Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!