[SciPy-User] Alternatives to scipy.optimize

josef.pktd@gmai... josef.pktd@gmai...
Sat Feb 25 23:21:05 CST 2012


On Sat, Feb 25, 2012 at 9:21 PM, Erik Petigura <eptune@gmail.com> wrote:
> Thanks for getting back to me!
>
> I'd like to minimize p1 and p2 together.  Let me try to describe my problem
> a little better:
>
> I'm trying to fit an exoplanet transit light curve.  My model is a box + a
> polynomial trend.
>
> https://gist.github.com/1912265
>
> The polynomial coefficients and the depth of the box are linear parameters,
> so I want to fit them using linear least squares.  The center and width of
> the transit are non-linear so I need to fit them with an iterative approach
> like optimize.fmin.  Here's how I implemented it.
>
> https://gist.github.com/1912281

Took me a while to work my way through it, especially that you have a
linear coefficient in front of the nonlinear part.

The idea of calculating the nonlinear part by setting the linear
coefficients to "neutral" values is nice.
Is (((p-pNL0)/dpNL0)**2).sum() a penalization term? Since your
objective function is quadratic optimize.leastsq might work better
than fmin.
The next numpy version will have a vander function to build Legendre
polynomials. (Or maybe it already has, I'm on 1.5)

The next thing will be to get the covariance matrix for the parameter
estimates :)

>
> There is a lot unpacking and repacking the parameter array as it gets passed
> around between functions.  One option that might work would be to define
> functions based on a "parameter object".  This parameter object could have
> attributes like float/fix, linear/non-linear.  I found a more object
> oriented optimization module here:
>
> http://newville.github.com/lmfit-py/

The easiest is to just write some helper functions to stack or unstack
the parameters, or set some to fixed. In statsmodels we use this in
some cases (as methods since our models are classes), also to
transform parameters.
Since often this affects groups of parameters, I don't know if the
lmfit approach would helps in this case.

(Personally, I like numpy arrays with masks or fancy indexing, which
is easy to understand. Ast manipulation scares me.)

Josef

>
> However, it doesn't allow for linear fitting.
>
> Erik
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>


More information about the SciPy-User mailing list