Can Fmincon recover from an error in evaluating the cost function?

Hi
I'm using fmincon to determine the optimal torque trajectory for a mutlibody simulation. I've approximated the input torque as piece-wise linear function.
I'm using fmincon as I would like to minimize the time it takes to bring the system to rest - this is my "cost function". This is determined by simulation of my model and then determining the cost. A similar approach is done to evaluate my nonlinear constraints.
Unfortunately, sometimes if the torque trajectory attempted by fmincon is too great, the simulation crashes with the message "Derivative input 1 of 'optimModel/Integrator1' at time 0.359 is Inf or NaN" and then the function stops. This is understandable as the body system spins around violently.
Is there a way for fmincon to recover from this? ie. to assign a cost to this value and move to the next attempt?
Or alternatively, does Global Optimization toolbox have functions with provision to do this? I realize that my cost function must obviously be non-smooth and some solutions cause instability in my simulation.
Any suggestions would be much appreciated.
Kind Regards
Amir

 Akzeptierte Antwort

Shashank Prasanna
Shashank Prasanna am 4 Jun. 2013

0 Stimmen

Alan will correct me if I am wrong, but fmincon is derivative based and not particularly good friends with non-smooth problems, You can try a different solver based on this information for the nature of your cost function:
I would ask you to try fminsearch first to see if you get somewhere, but you seem to have bound constraints. fminbnd can do bounds but for single variable cost functions.
Alternatively you can gravitate towards Global Optim solutions based on this decision table:

3 Kommentare

Hi Shashank
Thank you for the comments.
Yes, unfortunately I cannot use fminsearch or fminbnd because I have a multivariable cost function.
from this link: http://www.mathworks.com/help/gads/choosing-a-solver.html#bsbjg7m , I am gravitating towards 'patternsearch'. Would it do the trick?
I thought of another idea though: I place a "monitor block" in my simulink model and then stop the simulation if the angular positions get too large. Then I can re-assign the cost to some large value. This will however make the cost function even more "non-smooth" if that makes sense.
I realise stopping the simulation like that would cause fmincon difficulty in convergence. But I could randomly seed it and run fmincon several times.
Would this work?
Thanks
Amir
Yes patternsearch will be able to handle this type of problem, but would be slower. If you are not doing the optimization online or during simulation then this is a good place to start. You could also try multistart and globalsearch which run a chosen solver with different starting points. Secondly if you don't mind changing your cost function, then you could try Matt J suggestion on fitting a spline which would be differentiable.
This link may be of help on what to do when a solver fails:
Hi Shashank
My optimization is not online so a slower solution is ok.
I think I'm going to try my luck with the global optimization toolbox.
Thanks for all the input and comments.
Amir

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Alan Weiss
Alan Weiss am 4 Jun. 2013

0 Stimmen

The sqp and interior-point algorithms are robust to evaluation failures, as long as the initial point x0 has a well-defined objective there. See the release notes for R2011a.
Alan Weiss
MATLAB mathematical toolbox documentation

9 Kommentare

Hi Alan
Thank you for the quick response. I've been using the 'Active-Set' algorithm.
What do you mean by "well-defined objective" at initial point x0?
Amir
Hi
Just a follow up, I tried 'interior point' and I got the same error.
Does it have something to with my objective function not being well defined?
Regards
Amir
Matt J
Matt J am 4 Jun. 2013
Bearbeitet: Matt J am 4 Jun. 2013
What do you mean by "well-defined objective" at initial point x0?
It means that when you evaluate the function at x0, you get a finite real number.
Thank you for clarifying.
However, my initial estimates do indeed return a finite, real cost value.
It's just that during the search, the optimization tries torque on the Upper bound, which cause my simulation to break.
Does Global Search or Multistart have the same issue? If not, I am going to purchase GO toolbox.
GlobalSearch and MultiStart use fmincon as their local solver. They simply start it from a variety of initial points.
It is possible that the initial point you have, x0, has a finite objective value, but the finite differencing steps that fmincon take to estimate the derivative of the objective function lead to NaN. If there is no finite derivative, fmincon cannot proceed.
So I suggest you try a different value of x0 yourself, and turn on iterative display. If you use interior-point fmincon, then once it has started it should be able to proceed.
Alan Weiss
MATLAB mathematical toolbox documentation
Hi,
Could I require a question about optimization?
@Farshid R Yes you can ask questions about optimization, but unless it's related to the exact question asked nine years ago you should ask it as a new question rather than asking it in this old question's comments. Use the Ask link at the top of the page to ask it as a new question.
Thank you. Sorry, I replied late. The link to my question is:
https://www.mathworks.com/matlabcentral/answers/1812615-optimization-with-fmincon-command-in-simulink
https://www.mathworks.com/matlabcentral/answers/1812615-optimization-with-fmincon-command-in-simulink

Melden Sie sich an, um zu kommentieren.

Matt J
Matt J am 4 Jun. 2013
Bearbeitet: Matt J am 4 Jun. 2013

0 Stimmen

I've approximated the input torque as piece-wise linear function.
A piece-wise linear input will obviously not have bounded derivatives. To achieve bounded derivatives in FMINCON, you could and probably should approximate the torque using a 2nd order smooth function instead, e.g. using the SPLINE command or with the 'cubic' option of any of MATLAB's interpolation commands.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by