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

1 view (last 30 days)
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

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 4 Jun 2013
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 Comments
Shashank Prasanna
Shashank Prasanna on 4 Jun 2013
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:
Amir Patel
Amir Patel on 5 Jun 2013
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

Sign in to comment.

More Answers (2)

Alan Weiss
Alan Weiss on 4 Jun 2013
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 Comments
Farshid R
Farshid R on 26 Sep 2022
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
Farshid R
Farshid R on 26 Sep 2022
https://www.mathworks.com/matlabcentral/answers/1812615-optimization-with-fmincon-command-in-simulink

Sign in to comment.


Matt J
Matt J on 4 Jun 2013
Edited: Matt J on 4 Jun 2013
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.

Community Treasure Hunt

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

Start Hunting!