johnyjchan / cubic-spline-interpolation

Cubic Spline Interpolation provides numeric computing formula to interpolate curve. This source code was designed to draw a 3D curve. If you have any question or optimized idea, welcome to contact me.
22 stars 6 forks source link

Using scipy's genetic algorithm for initial parameter estimation in gradient descent #1

Open zunzun opened 7 years ago

zunzun commented 7 years ago

I saw your 3D cubic spline interpolator (with excellent plot) on GitHub, and thought that since you obviously have all of the supporting Python libraries installed you might like try running my scipy non-linear solver, also on github.

A general problem for gradient descent and other non-linear algorithms - particularly for more complex equations - is the choice of initial parameters to start the "descent" in error space. Without good starting parameters, the algorithm will stop in a local error minimum. For this reason the authors of scipy have added a genetic algorithm for initial parameter estimation for use in gradient descent. The module is named scipy.optimize.differential_evolution.

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.

johnyjchan commented 7 years ago

Thank you for reminding me about genetic algorithm. I was seeking for algorithms to estimate the initial triangle form matrix and vector's header/bottom parameters. However, I did not concern about non-linear algorithm. Gradient descent may be great and faster on plot. I'll try yours.

zunzun commented 7 years ago

Try my code both with and without passing the initial parameters to scipy's optimize.curve_fit() - the scipy default initial parameters of all 1.0 are shown to be totally useless. Which is better, fast results that are wrong or slightly slower results that are correct?

Knowing this, the authors of scipy added the Differential Evolution algorithm to scipy.optimize for this purpose, it gives good results in a relatively short time, and uses the Latin Hypercube algorithm for a thorough search of parameter space.