[SciPy-User] scipy.optimize.leastsq not varying fit parameters

Kevin Gullikson kevin.gullikson at gmail.com
Sat Dec 3 23:05:19 EST 2011


can you check all_pars here? To me this looks like const_par is
mutable and constantly extended

Ah, yes that was the problem. I just made my Fit Function take both
lists separately and it seems to work now. Thanks for the speedy reply!

Kevin



On Sat, Dec 3, 2011 at 9:46 PM, <josef.pktd at gmail.com> wrote:

> On Sat, Dec 3, 2011 at 9:53 PM, Kevin Gullikson
> <kevin.gullikson at gmail.com> wrote:
> > I am trying to do a nonlinear least squares fit using
> > scipy.optimize.leastsq. I have done this several times pretty easily for
> > fitting some analytical function. However, now I am fitting the
> parameters
> > of a numerical model to my data. As far as I can tell, the only thing
> that
> > should change is that the fitting function gets much more complicated
> (since
> > I have to generate one of these models at every iteration).
> >
> > My problem is this: leastsq is not varying the parameters, so I keep
> getting
> > the exact same model and eventually it tells me that 'The cosine of the
> > angle between func(x) and any column of the\n  Jacobian is at most
> 0.000000
> > in absolute value'
> >
> > I have played with the epsfcn keyword, increasing it to 0.1 and it still
> > never changes the parameters. What am I doing wrong? I will include some
> > code, but not all since it is quite long:
> >
> > The function call:
> >     fitout = leastsq(ErrorFunction, pars, args=(chips[i], const_pars),
> > full_output=True, epsfcn = 0.1)
> >
> >
> > The Error Function:
> > def ErrorFunction(pars, chip, const_pars):
> >   all_pars = const_pars
> >   all_pars.extend(pars)
>
> can you check all_pars here? To me this looks like const_par is
> mutable and constantly extended
>
> Josef
>
> >   print "Pars: ", pars
> >   model = FitFunction(chip, all_pars)
> >   return chip.y - model.y
> >
> >
> >
> > The Fit Function:
> > def FitFunction(chip, pars):
> >   print pars
> >   temperature = pars[0]
> >   pressure = pars[1]
> >   co2 = pars[2]
> >   co = pars[3]
> >   o3 = pars[4]
> >   wavenum_start = pars[5]
> >   wavenum_end = pars[6]
> >   ch4 = pars[7]
> >   humidity = pars[8]
> >   resolution = pars[9]
> >   angle = pars[10]
> >
> >   #Generate the model:
> >   model = MakeModel.Main(pressure, temperature, humidity, wavenum_start,
> > wavenum_end, angle, co2, o3, ch4, co, chip.x, resolution)
> >   if "FullSpectrum.freq" in os.listdir(TelluricModelDir):
> >     cmd = "rm "+ TelluricModelDir + "FullSpectrum.freq"
> >     command = subprocess.check_call(cmd, shell=True)
> >
> >   return model
> >
> > Kevin Gullikson
> >
> >
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User at scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> >
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20111203/3c414103/attachment.html>


More information about the SciPy-User mailing list