How to implement fmincon() in Java for a multivariable optimization with nonlinear constraints and upper / lower boundaries?

10 views (last 30 days)
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 Comment
Sorin C
Sorin C on 21 Dec 2016
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...

Sign in to comment.

Answers (2)

Sean de Wolski
Sean de Wolski on 21 Dec 2016
Why not use Compiler SDK to build a Java Class directly and avoid rewriting anything?

Walter Roberson
Walter Roberson on 21 Jun 2016
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 Comments
Caterina Lazaro
Caterina Lazaro on 24 Jun 2016
Thank for the fast response Walter Roberson! We were also targeting the FiniteDifferenceStepSize of MATLAB to try generating the same step size
delta = v.*sign′(x).*max(abs(x),TypicalX);
  • where sign′(x) = sign(x) except sign′(0) = 1.
  • v = sqrt(eps)
However, JCobyla does not provide a direct way of including the step size into its calculations. That's why we tried to get some guidance on how configuring JCobyla or even using a different solution in Java to implement fmincon.
Thank you, Caterina Lazaro
Walter Roberson
Walter Roberson on 24 Jun 2016
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.

Sign in to comment.

Categories

Find more on Java Package Integration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!