Setting options in fmincon
48 views (last 30 days)
Show older comments
Seems like a simple question, but I have tried all kinds of variants and nothing works. The documanetation on this stinks. All kinds of examples given that give errors.
I just want to lower the optimality tolerance, because my fmincon is not finding the minimum (which is zero) even though its getting to within the default OptimalityTolerance. I need it closer to zero than that. I will probably need to do the same with the StepTolerance.
I have tried using OptimalityTolerance instead of TolFun as well. Neither works.
If I run this as below, and then do a optimoptions('fmincon') at the command line the OptimalityTolerance stays at 1e-6 and my results are no different no matter what I use.
x0=log(1e-20)*ones(5,1)'; lb=log(1e-20)*ones(5,1)'; ub=log(1e-10)*ones(5,1)';
fun = @(x)abs(log(A)-log(cosT)+log(alp(1))+x(1)+log(sum(exp(x-x(1)+log(alp)-log(alp(1)))))-log(ro3^(-5/3)));
options = optimoptions(@fmincon,'TolFun',1e-7);
[x,fval] = fmincon(fun,x0,[],[],[],[],lb,ub,[],options)
optimoptions('fmincon')
0 Comments
Answers (2)
Fabio Freschi
on 23 Sep 2019
TolFun is to be used with optimset. With optimoptions use OptimalityTolerance
opts = optimoptions('fmincon','OptimalityTolerance',1e-12);
0 Comments
Matt J
on 23 Sep 2019
Edited: Matt J
on 23 Sep 2019
If I run this as below, and then do a optimoptions('fmincon') at the command line the OptimalityTolerance stays at 1e-6 and my results are no different no matter what I use.
Doing optimoptions('fmincon') at the command line does not give any information about what settings were used in a previous optimization. It will just display the default fmincon settings at the command line. The real option settings seen by fmincon are those contained in the options object which you created and passed to fmincon. Those settings were correctly made:
>> options
options =
fmincon options:
Options used by current Algorithm ('interior-point'):
(Other available algorithms: 'active-set', 'sqp', 'sqp-legacy', 'trust-region-reflective')
Set properties:
OptimalityTolerance: 1.0000e-07
Default properties:
Algorithm: 'interior-point'
CheckGradients: 0
ConstraintTolerance: 1.0000e-06
Display: 'final'
FiniteDifferenceStepSize: 'sqrt(eps)'
FiniteDifferenceType: 'forward'
HessianApproximation: 'bfgs'
HessianFcn: []
HessianMultiplyFcn: []
HonorBounds: 1
MaxFunctionEvaluations: 3000
MaxIterations: 1000
ObjectiveLimit: -1.0000e+20
OutputFcn: []
PlotFcn: []
ScaleProblem: 0
SpecifyConstraintGradient: 0
SpecifyObjectiveGradient: 0
StepTolerance: 1.0000e-10
SubproblemAlgorithm: 'factorization'
TypicalX: 'ones(numberOfVariables,1)'
UseParallel: 0
As for why your results are not changing, we cannot see what is happening because you have not provided enough of the input variables to run the code. However, it may be that another stopping criterion was reached before the OptimalityTolerance criterion.
You should also be mindful that the OptimalityTolerance is not a way of specifying the distance from the minimum value that you would like the algorithm to stop. No option setting can specify that directly. The OptimalityTolerance sets a tolerance on the first order optimality measure as described here,
6 Comments
Matt J
on 24 Sep 2019
Edited: Matt J
on 24 Sep 2019
Yes, fmincon will search for the 5-dimensional minimum (up to any constraints you specify, of course).
The plot of L(t) is deliberately a restriction of your 5-dimensional objective function to a 1-dimensional cross-sectional line passing through x and xtrue: one-dimensional plots are easier to visualize than 5-dimensional plots. The point was just to show that x and xtrue lie in different basins of the graph of your objective function. Because of the initial guess that you chose, fmincon is caught in the basin of x and cannot reach xtrue. Changing the optimoptions will not help with that.
Also, the plot further demonstrates that your objective has no derivative at either minima. That is likely why fmincon is having trouble converging to better than 1e-7.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!