Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to extract the Method which is used in functions like NMinimize, FindRoot, FindMinimium, and partners when one doesn't set this option explicitly? Basic example:

NMinimize[x^4 - 3 x^2 - x, x]

What is used as Method here?

I expected to find some setting in SystemOptions[] but was unable to. Obviously AbsoluteOptions[expr] cannot be used in such a case since unlike a e.g. graphic, the minimization result does not contain this option information anymore.

Here is what is stated in the documentation of Method:

With the default setting Method -> Automatic, Mathematica will automatically try to pick the best method for a particular computation.

This tells us the chosen Method depends on the input problem. Therefore, a fixed setting in SystemOptions wouldn't make sense.

Additionally, there exists a document describing some internal implementations. Basically, you can extract most information from there, but I was hoping for a way to extract the used Method during a run.

share|improve this question
For NMinimize[] (from here): "For linear cases, NMinimize and NMaximize use the same methods as LinearProgramming. For nonlinear cases, they use Nelder-Mead methods, supplemented by differential evolution, especially when integer variables are present." – J. M. Nov 15 '12 at 13:10
did you ask this question because its number 4000 :-) – chris Nov 15 '12 at 13:22
This doesn't work, but how come OptionValue doesn't get evaluated when/where the option exist? f[x_, y_] := (x^2 + y^2 - 16)^2; first = True; {sol, {{ mthd}}} = Reap[ NMinimize[f[x, y], {{x, -5, 5}, {y, -5, 5}}, Method -> "DifferentialEvolution", EvaluationMonitor :> If[first, Sow[OptionValue[Method]]; first = False;]]]; mthd – ssch Nov 15 '12 at 13:37
For NMinimize, yes, it is possible. I described how to get diagnostic output here. For your example it seems to be that differential evolution is used. – Oleksandr R. Nov 15 '12 at 14:12
Another possibility: Cases[Trace[NMinimize[x^4 - 3 x^2 - x, x], Optimization`NMinimizeDump`method, TraceInternal -> True], {HoldForm[Optimization`NMinimizeDump`method], m_ /; FreeQ[m, Automatic]} :> m, Infinity] – J. M. Nov 15 '12 at 14:34
up vote 11 down vote accepted

As I described here, we can obtain diagnostic output from NMinimize using an internal variable,

NMinimize; (* Auto-load package, in case we haven't called NMinimize already *)
Optimization`NMinimizeDump`$DiagnosticLevel = 3;

where the 3 means, as mentioned previously, that we would like to receive information at an intermediate level of detail. In fact, this also happens to be the lowest setting that states explicitly which method was used.

Trying your example minimization, we get output showing that differential evolution was used in this case:

NMinimize diagnostic output

Since this method only gives you a printout rather than something you can make use of programmatically, and because this internal option is of course completely undocumented anyway, in practice I'd probably tend to prefer J. M.'s suggestion of just grabbing the value of Optimization`NMinimizeDump`method directly.

share|improve this answer
@J.M. Hmm, it's really hard to decide who get the accept since both answers are valid and solve the problem (initially, I was only interested in the method used by NMinimize!). I give the accept to Olek, since (I think) he did all the digging inside Mathematica-code. – halirutan Nov 19 '12 at 1:08
@hal, no worries; he needs the rep more than me... ;) – J. M. Nov 19 '12 at 15:00
FWIW, the variable Optimization`NMinimizeDump`$DiagnosticLevel seems to have been superseded by the function Optimization`NMinimizeDump`dbPrint. It seems to be called thus: Optimization`NMinimizeDump`dbPrint[level, stuff], where stuff seems to be a list of stuff. The level that shows the method is 2. – Michael E2 May 22 '15 at 17:43

At halirutan's behest: here's one way to reckon out the method used internally by NMinimize[] and cohorts:

Cases[Trace[NMinimize[x^4 - 3 x^2 - x, x], Optimization`NMinimizeDump`method,
            TraceInternal -> True],
      {HoldForm[Optimization`NMinimizeDump`method], m_ /; FreeQ[m, Automatic]} :> m,

where in this case, the output is {HoldForm["DifferentialEvolution"]}. Trying the same tactic on NMinimize[x^2 + y^2, {x, y}] yields {HoldForm["NelderMead"]}.

SFAICT, this only works since the guts of NMinimize[]/NMaximize[] are mostly written in high-level Mathematica; I'm not sure if the internals used can be teased out of FindMinimum[] or FindRoot[] in this manner.

(Here is a related question.)

share|improve this answer
FindMinimum is quite obscure ... – Dr. belisarius Aug 27 '15 at 7:26
Well, that was not implemented in top-level Mathematica code, so yes, not transparent at all. – J. M. Aug 27 '15 at 7:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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