6
$\begingroup$

Assume I have some data to which I am fitting a curve. The curve is nonlinear, so I am using NonlinearModelFit. Let's assume I want to see the process of how a curve fits. Is there a good way to do that?

Would something along the lines of setting MaxIterations to 100 and then looking at the fit and then starting the fit again (initializing the values with the results from the first 100 iterations) work? Or are there intermediate values in the fitting process that will be lost?

$\endgroup$

1 Answer 1

10
$\begingroup$

You could use StepMonitor

data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {6, 4}, {7, 5}};
nlm = NonlinearModelFit[data, Log[a + b x^2], {a, b}, x, 
  StepMonitor :> 
   Print["R^2 = ",
     1 - Total[(data[[All,  2]] - (Log[a + b x^2] 
     /. {x -> data[[All, 1]]}))^2]/ Total[(data[[All, 2]] - Mean[data[[All, 2]]])^2]]]
$\endgroup$
0

Your Answer

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

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