[SciPy-user] curve_fit step-size and optimal parameters

Robert Kern robert.kern@gmail....
Mon Jun 8 15:02:15 CDT 2009

On Mon, Jun 8, 2009 at 14:59, ElMickerino<elmickerino@hotmail.com> wrote:
> Hello Fellow SciPythonistas,
> I've been trying to fit some data with a very simple model of a sine with a
> constant offset.  The data (voltage vs. time) is very clearly sinusoidal
> (see attached program and data file), yet curve_fit fails to find the
> optimal parameters.  I am able to specify very good initial guesses for the
> constant offset, the amplitude of the sinusoid and the frequency; the only
> thing that would be difficult to guess is the phase (I have many, many such
> datasets, all with random phase).  My guess is that since the phase is only
> defined modulo 2pi, the minimization package sees that there are many deep
> minima of chi^2 and so gets confused.  Ideally, I'd like to limit the phase
> to be between 0 and 2*pi to remove this ambiguity.
> My question is, how can I get curve_fit to use a very small step-size for
> the phase, or put in strict limits, and to therefore get a robust fit.  I
> don't want to tune the phase by hand for each of my 60+ datasets.

You really can't. I recommend the A*sin(w*t)+B*cos(w*t)
parameterization rather than the A*sin(w*t+phi) one.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the SciPy-user mailing list