What does this Fmincon error mean?

14 views (last 30 days)
Amir Patel
Amir Patel on 14 Jun 2013
Hi Everyone
I'm doing a constrained optimization where I first generate a few random intial points, I then only keep the feasible ones. I do this by running the objective function to see if it returns a NaN.
Then I use the feasible set of initial values and I call fmincon in a FOR loop. I did this because I was worried about local minima. I have turned on the option to use parallel workers.
However, I'm now receiving a weird error after a certain amount of fmincon executions.
Here is the output:
User objective function returned NaN; trying a new point...
22 590 9.074473e-01 1.382e+01 2.173e+03 1.337e-01
Error using parallel_function (line 589)
Matrix dimensions must agree.
Error stack:
parfinitedifferences>(parfor body) at 158
Error in C:\MATLAB\R2012a
Student\toolbox\shared\optimlib\parfinitedifferences.p>parfinitedifferences (line 118)
Error in C:\MATLAB\R2012a
Student\toolbox\optim\optim\private\computeFinDiffGradAndJac.p>computeFinDiffGradAndJac (line
Error in C:\MATLAB\R2012a Student\toolbox\optim\optim\barrier.p>barrier (line 564)
Error in fmincon (line 841)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = barrier(funfcn,X,A,B,Aeq,Beq,l,u,confcn,options.HessFcn, ...
Error in FreeTailObjConstr (line 70)
[x,fval,exitflag] = fmincon(fun,x0,Aineq,Bineq,Aeq,Beq,LB,UB,cfun,options,param);
Error in multiStartFreeTail (line 113)
[x,fval,exitflag] = FreeTailObjConstr(x0, UB, LB, muVal);
% code
What does this mean???

Answers (2)

Steve Grikschat
Steve Grikschat on 14 Jun 2013
This is a bug with the parallel finite differences approximation code. In particular, how this feature works with "invalid" values (i.e. Inf, NaN, and complex) is broken when it cannot get a real/defined function value. I'll make a bug report for this.
In your problem, does your objective function naturally evaluate to NaN when the input parameters are outside of a constrained region? Or do you do this manually:
if isFeasible(x)
f = ...
f = NaN
If you force the function value to NaN, I suggest trying without that, which will avoid this error. Otherwise, you can use the serial mode (set UseParallel to 'never').
Steve Grikschat
Steve Grikschat on 24 Jun 2013
What you are doing is reasonable. See my original answer for a workaround. See comment below about MultiStart.

Sign in to comment.

Amir Patel
Amir Patel on 17 Jun 2013
Does Multistart have the same bug?
  1 Comment
Steve Grikschat
Steve Grikschat on 24 Jun 2013
It depends where you use the parallel resources.
MultiStart in parallel means that fmincon is run with a different start point on each worker. This disables the parallelism inside fmincon (finite differences). So the bug does not happen here.
If, however, you run MultiStart in serial, but enable parallelism in fmincon, then the bug can happen.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!