2

Right now, fmincon solves a minimization problem for me. The function to minimize uses parfor for the sake of completeness.

I am using those options

options = optimoptions(@fmincon,'Display','iter', 'MaxIter',1000000,'MaxFunEvals',1000000,'TypicalX',[1e-1,1e-2,1e0,1e1,1e2,1e3, 1e-1])

and unfortunately the evaluation takes much much longer than expected. How can I terminate the evaluation and get the parameter point that fmincon found until now. It should be enough for me, because the funciton value is not really reduced anymore. It is calculating since 12 hours and just at iteration 6550 right now.

So is there a way to terminate fmincon-evaluation and get the current result of the parameterpoint?

Thank you in advance!

Greets, Pejta

Shai
  • 111,146
  • 38
  • 238
  • 371
Pejta
  • 21
  • 2
  • possible duplicate of [matlab: stop and continue execution from debugger possible?](http://stackoverflow.com/questions/3272541/matlab-stop-and-continue-execution-from-debugger-possible) – see also [this](http://stackoverflow.com/q/5888472/2278029), [this](http://stackoverflow.com/q/18859270/2278029), and [this](http://stackoverflow.com/q/19005931/2278029). If you're hoping to save results from code that's already running, you may be out of luck. You have to anticipate this sort of thing. – horchler May 03 '15 at 18:44
  • @horchler not a duplicate, it is very possible to give almost exactly what OP wants – Karl May 03 '15 at 20:42

1 Answers1

2

You can pass a callback to fmincon that will be called every design point.

Output Function

The Outputfcn field of options specifies one or more functions that an optimization function calls at each iteration. Typically, you might use an output function to plot points at each iteration or to display optimization quantities from the algorithm. Using an output function you can view, but not set, optimization quantities.

http://www.mathworks.com/help/optim/ug/optimization-options-reference.html#f11022

options = optimoptions(@solvername,'OutputFcn', @outfun);

specifies OutputFcn to be the handle to outfun. To specify more than one output function, use the syntax

options = optimoptions(@solvername,'OutputFcn',{@outfun, @outfun2});

This should allow you to save your progress every iteration.

Karl
  • 315
  • 2
  • 9