10
$\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$
  • $\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 Feb 8 '15 at 23:25
  • $\begingroup$ The Answer to 21823 has some information. $\endgroup$ – bbgodfrey Feb 9 '15 at 0:08
12
$\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$
  • $\begingroup$ Perfect! Thank you so much. $\endgroup$ – user3037237 Feb 9 '15 at 14:33
  • $\begingroup$ @user3037237, my pleasure. Welcome to mma.se. $\endgroup$ – kglr Feb 9 '15 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$ – Tom Mozdzen Oct 12 '18 at 2:31
  • $\begingroup$ @TomMozdzen, good question. I don't know the answer ottomh. $\endgroup$ – kglr Oct 12 '18 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$ – Tom Mozdzen Oct 12 '18 at 7:23

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.