Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SciPy global minimum curve fit

I'm using scipy.optimize.curve_fit, but I suspect it is converging to a local minimum and not the global minimum.

I tried using simulated annealing in the following way:

def fit(params):
 return np.sum((ydata - specf(xdata,*params))**2)

p = scipy.optimize.anneal(fit,[1000,1E-10])

where specf is the curve I am trying to fit. The results in p though are clearly worse than the minimum returned by curve_fit even when the return value indicates the global minimum was reached (see anneal).

How can I improve the results? Is there a global curve fitter in SciPy?

like image 726
Gus Avatar asked Mar 22 '11 06:03

Gus


Video Answer


1 Answers

You're right, it only converges towards a local minimum (when it converges) since it uses the Levenburg-Marquardt algorithm. There is no global curve fitter in SciPy, you have to write you own using the existing global optimizers . But be aware, that this still don't have to converge to the value you want. That's impossible in most cases.

The only method to improve your result is to guess the starting parameters quite well.

like image 108
nils Avatar answered Oct 02 '22 13:10

nils