4
$\begingroup$

With NMinimize (or many other functions), when an answer is found without any warnings, this means that a certain convergence criterium was achieved. It could be that the convergence specified in AccuracyGoal was achieved, or the one given by PrecisionGoal. A pedestrian way to know which one was used is to redo the computations a couple of times changing the values of those options. But this is not feasible in my case.

How to know which convergence criterium was used? Say, could one print the criterium along with the answer, without computing the expression more than once?

$\endgroup$
3
$\begingroup$

You can add a hook to Optimization`NMinimizeDump`converge to capture the errors (in the input xstep and in the objective function fstep):

Internal`InheritedBlock[{Optimization`NMinimizeDump`converge},
 PrependTo[DownValues@Optimization`NMinimizeDump`converge,
  HoldPattern[Optimization`NMinimizeDump`converge[args__] /; ! TrueQ[$in]] :> 
   Block[{$in = True},
    {xStep, xNew, fStep, fNew, atol, rtol} = {args};
    Optimization`NMinimizeDump`converge[args]]
  ];
 NMinimize[Sin[Tan[x]/2], x, AccuracyGoal -> 9, PrecisionGoal -> 8]
 ]
{xStep, xNew, fStep, fNew, atol, rtol}
% /. {xStep_, xNew_, fStep_, fNew_, atol_, rtol_} :>
  {LessEqual[Norm[xStep] / (atol + rtol * Norm[xNew]), 1 / 2]
   , LessEqual[Norm[fStep] / (atol + rtol * Norm[fNew]), 1 / 2]
   (*,Less[Min[fStep / (1 + fNew + -fStep)], -1000]*)}
(*
  {-1., {x -> -1.26263}}
  {{0.}, {-1.26263}, {0.}, {-1.}, 1/1000000000, 1/100000000}
  {True, True}
*)

The parameter atol ia the absolute tolerance defined by AccuracyGoal and rtol is the relative tolerance defined by PrecisionGoal. The LessEqual comparisons are the criteria for determining convergence. (The commented criterion is the test for divergence.)

Each numerical function uses different criteria, which are implemented each in their own way. See this answer for a general discussion of the ways AccuracyGoal and PrecisionGoal determine convergence criteria. The OP mentioned NMinimize explicitly, which is the command I looked into.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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