5
$\begingroup$

I am trying to track the evolution of NMinimize using the SimulatedAnnealing options. Simulated annealing has 3 parameters to track: 1) the latest trial point, 2) the latest accepted point, 3) the global minimum found so far.

It seems to me that using stepmonitor tracks quantity 3). Evaluationmonitor tracks either 1) or 2) but I can't figure out which.

My questions are: A) What do stepmonitor/evaluationmonitor actually track? B) How can I track both 1) and 2)?

Simple code to play around with (adapted from NMinimize help):

f[x_, y_] := 20 Sin[π/2 (x - 2 π)] + 20 Sin[π/2 (y - 2 π)] + (x - 2 π)^2 + (y - 2 π)^2;

fS = {f[0., 0]}; fE = {f[0., 0]};

NMinimize[f[x, y], {x, y}, Method -> {"SimulatedAnnealing", "SearchPoints" -> 10, "PerturbationScale" -> 5, "PostProcess" -> False, "InitialPoints" -> {{0, 0}}, "RandomSeed" -> Floor[AbsoluteTime[]]}, EvaluationMonitor :> AppendTo[fE, f[x, y]], StepMonitor :> AppendTo[fS, f[x, y]]]

Dynamic[Show[ListPlot[fS, Joined -> True, PlotStyle -> Blue], ListPlot[fE, Joined -> False, PlotStyle -> Red], PlotRange -> All]]
$\endgroup$
1
  • $\begingroup$ My understanding is, that EvaluationMonitor will be evaluated whenever the function is evaluated. StepMonitor will be evaluated whenever a point is accepted which here should not necessarily be the best point found so far. I would assume that the best point found so far must be accessed by different means. $\endgroup$
    – gwr
    Apr 3, 2016 at 11:15

1 Answer 1

3
$\begingroup$

Trying out with MMA 11.0 strongly indicates that StepMonitor accesses the currently best guess, while EvaluationMonitor seems to access the trial guesses. Both can be accessed simultaneously by setting StepMonitor as well as EvalutationMonitor.

This is seen looking at a function we all know the minimum of ($x^2$), setting the acceptance probability to zero, and sowing the values in both ways. One finds with :

Input

Reap[NMinimize[x^2,x,StepMonitor:>Sow[x],MaxIterations->10,Method->{"SimulatedAnnealing","BoltzmannExponent"->Function[{a,b,c},-\[Infinity]],"SearchPoints"->1,"InitialPoints"->{{1}},"PostProcess"->False,"RandomSeed"->6417}]]
Reap[NMinimize[x^2,x,EvaluationMonitor:>Sow[x],MaxIterations->10,Method->{"SimulatedAnnealing","BoltzmannExponent"->Function[{a,b,c},-\[Infinity]],"SearchPoints"->1,"InitialPoints"->{{1}},"PostProcess"->False,"RandomSeed"->6417}]]

Ouput

{{2.5813*10^-6,{x->0.00160664}},{{1.,0.48412,0.48412,0.48412,0.0497937,0.00160664,0.00160664,0.00160664,0.00160664,0.00160664}}}

{{2.5813*10^-6,{x->0.00160664}},{{1.,0.48412,0.873839,0.826477,0.0497937,0.00160664,0.172293,-0.103134,0.0712828,-0.0540525,0.00160664}}}

Here, we see that the first run (StepMonitor) always returns the best guess, while the second run (EvaluationMonitor) seems to return the random guesses.

In order to have two comparable runs, it is important to set "RandomSeed" as well. Also, "PostProcess" needs to be turned off, in order to stop at values that are really found by guessing randomly. Finally, "SearchPoints" is set to 1, which excludes deflecting different starting points.

Example how both can be tracked simulataneously:

Reap[NMinimize[x^2,x,StepMonitor:>Sow[x,"StepMonitor"], EvaluationMonitor:>Sow[x,"EvaluationMonitor"],MaxIterations->10,Method->{"SimulatedAnnealing","BoltzmannExponent"->Function[{a,b,c},-\[Infinity]],"SearchPoints"->1,"InitialPoints"->{{1}},"PostProcess"->False,"RandomSeed"->6417}]]

{{2.5813*10^-6,{x->0.00160664}},{{1.,0.48412,0.873839,0.826477,0.0497937,0.00160664,0.172293,-0.103134,0.0712828,-0.0540525,0.00160664},{1.,0.48412,0.48412,0.48412,0.0497937,0.00160664,0.00160664,0.00160664,0.00160664,0.00160664}}}

As stated initially, this is not a proof but merely strong indication.

(Edited 16:21 at day of post because my initial answer was wrong).

$\endgroup$
1
  • $\begingroup$ That is my experience as well, with version 10.1 $\endgroup$
    – user38196
    Feb 14, 2017 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.