Following Szabolcs advice, it seems that the Documentation page for EvaluationMonitor
contains all what you need for Method -> "Newton"
:
data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {6, 4}, {7, 5}};
Clear[evalCount];
evalCount[_] = 0;
nlm = NonlinearModelFit[data, Log[a + b x^2], {a, b}, x,
EvaluationMonitor :> ++evalCount["Function"],
Gradient -> {"Symbolic", EvaluationMonitor :> ++evalCount["Gradient"]},
Method -> {"Newton",
"Hessian" -> {"Symbolic", EvaluationMonitor :> ++evalCount["Hessian"]}}];
TableForm[evalCount /@ #, TableHeadings -> {#, None}] &@{"Function", "Gradient",
"Hessian"}
Other Method
s take different suboptions, for example "LevenbergMarquardt"
:
Clear[evalCount];
evalCount[_] = 0;
nlm = NonlinearModelFit[data, Log[a + b x^2], {a, b}, x,
EvaluationMonitor :> ++evalCount["Function"],
Gradient -> {"Symbolic", EvaluationMonitor :> ++evalCount["Gradient"]},
Method -> {"LevenbergMarquardt",
"Residual" -> {"Symbolic", EvaluationMonitor :> ++evalCount["Residual"]},
"Jacobian" -> {"Symbolic", EvaluationMonitor :> ++evalCount["Jacobian"]}}];
TableForm[evalCount /@ #, TableHeadings -> {#, None}] &@{"Function", "Gradient",
"Residual", "Jacobian"}
Although I'm not sure why inside of Method
suboptions EvaluationMonitor
does not catch anything for NonlinearModelFit
...
FindMinimum
documentation on how to useEvaluationMonitor
andStepMonitor
. Also look at the tutorial on unconstrained and constrained optimization (Tutorials at top of relevant doc pages) and the FindMinimumPlot functions from ExtraPackages -> Optimization -> UnconstrainedProblems.m (this is used in the tutorials). $\endgroup$