Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Following Szabolcs adviceSzabolcs 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"}

table

Other Methods 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"}

table

Although I'm not sure why inside of Method suboptions EvaluationMonitor does not catch anything for NonlinearModelFit...

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"}

table

Other Methods 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"}

table

Although I'm not sure why inside of Method suboptions EvaluationMonitor does not catch anything for NonlinearModelFit...

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"}

table

Other Methods 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"}

table

Although I'm not sure why inside of Method suboptions EvaluationMonitor does not catch anything for NonlinearModelFit...

Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

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"}

table

Other Methods 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"}

table

Although I'm not sure why inside of Method suboptions EvaluationMonitor does not catch anything for NonlinearModelFit...