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

조회 수: 3 (최근 30일)
Amir Patel
Amir Patel 2013년 6월 4일
댓글: Farshid R 2022년 9월 26일
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

채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 6월 4일
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
Shashank Prasanna
Shashank Prasanna 2013년 6월 4일
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 2013년 6월 5일
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

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Alan Weiss
Alan Weiss 2013년 6월 4일
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
Farshid R
Farshid R 2022년 9월 26일
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 2022년 9월 26일
https://www.mathworks.com/matlabcentral/answers/1812615-optimization-with-fmincon-command-in-simulink

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2013년 6월 4일
편집: Matt J 2013년 6월 4일
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.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by