[SciPy-User] Alternatives to scipy.optimize
Sat Feb 25 23:21:05 CST 2012
On Sat, Feb 25, 2012 at 9:21 PM, Erik Petigura <firstname.lastname@example.org> 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.
> 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.
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
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
> 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:
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
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.)
> However, it doesn't allow for linear fitting.
> SciPy-User mailing list
More information about the SciPy-User