I encountered this problem while addressing an answer to this other question.
Here I do the following:
I ask NMaximize to do its job, and I use Reap and Sow with EvaluationMonitor to store the values that it tried in the list called reapSowPoints. At the same time, the objective function also stores the variables that were called in a separate list called functionCalls. These two lists should be the same, but they are actually very different. Why is that?
Here's the code:
myMaximization[vars_, objective_] :=
Reap[
Module[{customFunction},
customFunction[v_ /; VectorQ[v, NumericQ]] :=
Module[{val = objective @@ v},
AppendTo[functionCalls, v];
val];
NMaximize[
{customFunction[vars], Norm @ vars == 1},
vars,
EvaluationMonitor :> Sow[vars]]]]
When I evaluate it I obtain (e.g.):
functionCalls = {};
{result, reapSowPoints} = myMaximization[{x, y}, #1 + #2 &];
Length /@ {functionCalls, reapSowPoints[[1]]}
{1603, 222}
The function was called 1603 times, but Sow appears to have caught only 222 of them.
SowversusSaw. – David G. Stork Dec 01 '16 at 19:20Length /@ DeleteDuplicates /@ {functionCalls, First@reapSowPoints}. It's more a problem withEvaluationMonitorthan withSow. – Michael E2 Dec 02 '16 at 02:14MaxIterations -> 10) than with more (MaxIterations -> 100). – Michael E2 Dec 02 '16 at 11:02NMaximize[]routine. TheEvaluationMonitoris not used in this phase, I believe. – Michael E2 Dec 02 '16 at 11:45