How to implement fmincon() in Java for a multivariable optimization with nonlinear constraints and upper / lower boundaries?
10 次查看(过去 30 天)
显示 更早的评论
I am translating some MATLAB code using fmicon(...) function into Java. I have been working with Cobyla, but I am not able to get the result to converge to the same solution (or even close) obtained in MATLAB.
IN MATLAB:
The call to fmincon has the form:
options=optimset('Algorithm','interior-point','Display','off');
X=fmincon(@objective,Q_old,[],[],[],[],lowerlim,upperlim,@constraint,options);
Where:
- objective(X) is a function taking X (a vector with 24 samples)
- constraint(X) is a non-linear constraint function
function [c, ceq]=constraint(X)
[ ... function of X : g(X) ..]
%g(X) < 1
c=g(V)-0.99;
ceq = [];
end
- lowerlim and upperlim are lb (lower bound) and ub (upper bound)
JAVA TRANSLATION:
I am using a Java implementation of the Cobyla library ("jcobyla"), trying to converge to the same X result as Matlab's optimization does.
It is simple to set Cobyla to obtain a good X result when no boundaries or constrains are applied. However, I am not able to successfully apply the constraint function nor the boundaries (though I defined both in the code, behaving as their equivalent in MATLAB). The Java cobyla solver stops optimizing at a certain X_suboptimal value, no matter how many times we iterate from there. I am not supplying any non-default parameters to Matlab's fmincon solver.
More information regarding my Cobyla code:
The Java "jcobyla" library implementing Cobyla can perform the min optimization, with the function:
CobylaExitStatus result = Cobyla.findMinimum(calcfc, NUM_VARIABLES, NUM_CONSTRAINTS, X0, _RHO_BEG, _RHO_END, iprint, MAX_NUM_FUNC_ITERATIONS);
Where
- calcfc is used to define the objective function (objective(X)) and the constraint function (constraint(X))
- The Cobyla internal parameter RHO controls the size of the simplex -- the value of RHO is reduced automatically from RHOBEG to RHOEND during execution. ( RHOEND, then, appears to be the same as the XTolerance parameter for the Matlab solver, where the default value = 1 e-10 ).
|
My questions are:
1.Is there a better Java library/method to mimic Matlab's fmincon solver when performing a multivariable optimization with non linear constraints and upper / lower boundaries? I am not particularly committed to jcobyla, so if there's a better option, I'm open to suggestions.
2. If Cobyla is the best option, how can it be configured in a proper manner? It appears that Matlab, when running fmincon, determines the step size in a way that's not transparent to the user. Cobyla simply steps from RHO_BEG to RHO_END, but Matlab appears to recalculate the step size as it goes, which may be causing Cobyla's failure to get the same answer that fmincon does.
1 个评论
Sorin C
2016-12-21
For example if you have boundary conditions such as 1<=x0<=2 and 0<=x1<=4 how can you represent that in Cobyla in the con double[] array? I could not get that yet...
回答(2 个)
Sean de Wolski
2016-12-21
Why not use Compiler SDK to build a Java Class directly and avoid rewriting anything?
0 个评论
Walter Roberson
2016-6-21
See FiniteDifferenceStepSize in http://www.mathworks.com/help/optim/ug/fmincon.html#inputarg_options for a description of how the step size is determined. The default value appears to be sqrt(eps)
Note: you need R2016a or later to set that option. I notice you are using legacy names so you might perhaps be working with an earlier version.
2 个评论
Walter Roberson
2016-6-24
I know little about Java or available Java libraries. I was responding to your remark,
"It appears that Matlab, when running fmincon, determines the step size in a way that's not transparent to the user."
by pointing to the documentation about how the step size is determined.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Java Package Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!