Question

Using the scipy.optimize.minimize() function I went trough different results using different methods for the same objective function. To evaluate the goodness-of-fit I use to look at the reduced chi squared as a first criterion. After some time I ended with this useful guide http://newville.github.io/lmfit-py/fitting.html#Minimizer where it is specified that the reduced chi squared is set as attribute of the Minimizer object returned from the minimize() function. But if I do

minobj = scipy.optimize.minimize(...)
minobj.redchi

I get

 AttributeError: redchi

Meanwhile minobj.message and minobj.success are correctly displayed. Any guess?

Was it helpful?

Solution

The documentation is a little misleading --- if you look at lmfit/minimizer.py, and do a string search for "redchi" in the entire file, it only appears once, and that is in the leastsq() method. So basically, it only calculates the reduced chi squared for least-squares fitting.

If you're feeling up to it, you could add redchi to the other methods in the appropriate places, fork the lmfit github repo, and commit your changes.

OTHER TIPS

In addition to Ashwin's answer, you could always just use:

result = lmfit.minimize(...)
x2 = result.chisqr
nfree = result.nfree
red_x2 = x2/nfree
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top