michelucci / Regression-with-Python

1 stars 1 forks source link

Using scipy's genetic algorithm for initial parameter estimation in non-linear optimization #1

Closed zunzun closed 7 years ago

zunzun commented 7 years ago

I see you are writing Python code using scipy.optimize.curve_fit() which has default starting parameter values of all 1.0 for the Levenber-Marquardt solver. These initial parameter values are not always optimal, and for more complex equations usually cause the algorithm to stop in a local error minimum. For this reason the authors of scipy have added a genetic algorithm for initial parameter estimation for use with their non-linear solvers, the module is named scipy.optimize.differential_evolution and uses the Latin Hypercube algorithm to ensure a thorough search of parameter space.

I have used scipy's Differential Evolution genetic algorithm to determine initial parameters for fitting a double Lorentzian peak equation to Raman spectroscopy of carbon nanotubes and found that the results were excellent. The GitHub project, with a test spectroscopy data file, is:

https://github.com/zunzun/RamanSpectroscopyFit

If you have any questions, please let me know. My background is in nuclear engineering and industrial radiation physics, and I love Python, so I will be glad to help.

James Phillips

michelucci commented 7 years ago

Hi James, thanks for your comment. I am aware of the problem. I am also working with spectroscopic signals (Lorentians) and non linear fits (I am also a Physicist by Education). I will check your code and I will be happy to expand my short notes. The notes actually originated from a short post I did to help someone on stackoverflow. The Problem of initial Parameters is a complex one. In my last project I had to fit 3 Lorentians and therefore had 9 Parameters. Sometime is annoying because, as you mention, you won't get to the mininum and have to try different combinations. I will check your Suggestion, add to my note. Then you can have a look at it to see if everything is correct.

Thanks for taking the time to comment it :+1:

Umberto

zunzun commented 7 years ago

Most excellent.

michelucci commented 7 years ago

I added a discussion about Initial Parameters, citing your contribution. Thanks. Will expand with an example where this step is really necessary. Need to find data that I can publish ;-) Thanks again.