Setting options in fmincon
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')
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);
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
Jay Land
on 23 Sep 2019
Jay Land
on 23 Sep 2019
Matt J
on 23 Sep 2019
Well, you have 2 problems. The first problem is that fun(x) is not differentiable at points where fun(x)=0. This is because the abs() operation in your objective function is not differentiable. fmincon is a derivative-based solver, so this violates one of its assumptions.
The second problem is that you have multiple local minima, which you can see by plotting a line connecting the fmincon output x with your xtrue,
L=@(alpha) fun(x+alpha*(xtrue-x));
fplot(@(t) arrayfun(L,t),[-1.2,1.2])

Steven Lord
on 23 Sep 2019
Let's take a look at the message fmincon displayed (I'm running in release R2019a.)
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current step is less than
the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
Certain sections of the exit message are hyperlinks to sections of the documentation, including the entire first line. The section of the documentation to which that line links itself links to another page in the documentation that provides several potential reasons why fmincon may have returned a local minimum.
As for optimoptions returning an options object that does not reflect the changes made by a previous optimoptions call, as Matt J indicated that's the correct behavior. optimoptions creates an object that you can pass into an optimization function. It does not change "global options" or anything like that, though you're not the first person to assume that's how it functions.
Jay Land
on 23 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.
Categories
Find more on Solver Outputs and Iterative Display 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!