fmincon and Getting "Solution" Before Convergence Tolerance is Hit

7 次查看(过去 30 天)
I'm running a relatively large and slow fitting routine through fmincon – there are 12 bounded parameters. As a result, on the available machines we have, the fit has taken several days, so far. I also set the tolerance to be way lower than we need, for our purposes. As a result, when the function output is plotted (to the Optimization PlotFcns window), the function output has effectively converged (each iteration does not change, to within what I need). Is there a way to stop the script and get the current "solution" (the current values fmincon has), without re-running the script?
I'm looking to save several days' worth of time here.

采纳的回答

Adam Danz
Adam Danz 2019-9-9
编辑:Adam Danz 2019-9-10
From the Editor, press the pause button (first panel below). Execution will eventually pause but it may not be within the function that contains your call to fmincon() so you'll need to step through using the 'step' button in the 2nd panel below until you get to the fmincon outputs. You can save all of the existing variables so you can later reload them and start where you left off.
[addendum]
If the editor is not already open, you can press the "New Script" button from the Home tab to open the editor and then follow the instructions above.
To determine the current file and line number, run dbstack() from the command window.
  4 个评论
Blenndrman
Blenndrman 2019-9-10
Good to know about various tricks to store variables along the way. I'm certainly not a programmer by trade, and have never built such an unwieldy code before. Thanks!
Adam Danz
Adam Danz 2019-9-10
编辑:Adam Danz 2019-9-10
For these kinds of long running processes it's a good idea to occasionally save the data from within the program. For example, every 'n' iterations save all variables so that if the program breaks 10 days from now you can start off at the most recently saved state.
Another good idea is to set the "pause on errors" option (from the Editor in r2019a, click the down arror under 'Run" and select Pause on errors). That way if there is an error the code will pause at the error before breaking. All of the internal variables will hold their values which gives you a chance to do a postmortem in order to debug and fix the problem (and again, save the variables).
A guy in my lab had to run an analysis that took 2 years on a cluster of computers just because a reviewer asked for an additional figure. You can be sure that program backed up the progress occasionally.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2019-9-9
When you use fmincon(), you can designate an output function separately from plot functions.
The outputfcn will get the current state for each iteration. You can save copies of the best solution you found so far (or all solutions, if you prefer). Then when you click STOP in the plotfcn, the outputfcn should in theory execute once with 'done' state, which you can then use to save the values to somewhere the user can get to.
  1 个评论
Blenndrman
Blenndrman 2019-9-10
So this will be for the next time I run the code, certainly – I'll be able to set this up. I guess I was wondering about a currently-still-running script. Thanks, though, It's a useful tool that I didn't realize existed.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get 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