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 Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by