12
$\begingroup$

Does anyone know the default algorithm used in NonlinearModelFit? The documentation gives several possible algorithms, but I can't figure out what it uses if you do not specify the algorithm.

Thanks.

$\endgroup$
2
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Commented Feb 8, 2015 at 23:25
  • $\begingroup$ The Answer to 21823 has some information. $\endgroup$
    – bbgodfrey
    Commented Feb 9, 2015 at 0:08

1 Answer 1

13
$\begingroup$

From Introduction to Local Minimization:

With Method -> Automatic, the Wolfram Language uses the quasi-Newton method unless the problem is structurally a sum of squares, in which case the Levenberg-Marquardt variant of the Gauss-Newton method is used.

To confirm, I use the first example in FindFit >> Options >> Method and compare the output for various settings for the Method option:

Possible settings for Method include "ConjugateGradient", "Gradient", "LevenbergMarquardt", "Newton", "NMinimize", and "QuasiNewton", with the default being Automatic.

model = a Exp[-b (x - c)^2] + d Sin[ω x + ϕ];
data = Table[{x, model /. {a -> 2, b -> 1, c -> 0, d -> 2, ω -> 0.67, ϕ -> 0.1}}, 
           {x, -5, 5, .1}] + RandomReal[.25, 101];

methods = {Automatic, "ConjugateGradient", "Gradient", "LevenbergMarquardt",
           "Newton", "NMinimize", "QuasiNewton"};

nlms = Quiet@ NonlinearModelFit[data, model, {a, b, c, d, ω, ϕ}, x, 
                 Method -> #]["ParameterTable"] & /@ methods; 
Grid[Partition[Labeled[#, #2, Top] & @@@ Transpose[{nlms, methods}], 3], Spacings -> {5, 5}]

enter image description here

$\endgroup$
6
  • $\begingroup$ Perfect! Thank you so much. $\endgroup$ Commented Feb 9, 2015 at 14:33
  • $\begingroup$ @user3037237, my pleasure. Welcome to mma.se. $\endgroup$
    – kglr
    Commented Feb 9, 2015 at 15:34
  • $\begingroup$ How to tell if Mathematica thinks your problem is a sum of squares? is there anyway to query the fit to ask what it used? $\endgroup$ Commented Oct 12, 2018 at 2:31
  • $\begingroup$ @TomMozdzen, good question. I don't know the answer ottomh. $\endgroup$
    – kglr
    Commented Oct 12, 2018 at 7:03
  • $\begingroup$ @kglr I suppose I could use your code above and substitute my fitting equation and a sample data set and compare outputs as you have done above. Finding out should be a single simple command I would think. Do you know where the various methods are documented? I haven't found the page where they give you the full list of options. $\endgroup$ Commented Oct 12, 2018 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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