[SciPy-User] leastsq

Frédéric Parrenin parrenin.ujf@gmail....
Thu Jun 27 08:04:16 CDT 2013

Dear Josef,

Thank you for your answer.
OK to use the curve_fit function with a change of variables to have a
diagonal covariance matrix.

However, here are two questions/remarks:
- Curve_fit takes as input both the parameters to fit and a variable x
where the data are 'located'. This approach seems sub-optimal since in many
inverse problems, the function is evaluated for all x at a time. Running
the function independently N times will significantly decrease the
computation time.
Maybe in this case the best thing to do is to declare that x is empty, but
how to do that in practice?
- It is not very clear from the scipy doc
what the function f is supposed to return. Is it just a scalar function or
can it be a ndarray or even something else?

Some more complex examples in the doc would really help to better
understand how it works.

Best regards,

Frédéric Parrenin

2013/6/26 <josef.pktd@gmail.com>

> On Wed, Jun 26, 2013 at 12:26 PM, Frédéric Parrenin
> <parrenin.ujf@gmail.com> wrote:
> > Dear all,
> >
> > I am experimenting the optimize module of scipy.
> > My optimization problem is a leastsq problem.
> > However, the leastsq function seems to be not appropriate for two
> reasons:
> > - there is no possibility to specify a covariance matrix between the
> leastsq
> > terms. They are supposed to be independent, which is a too strong
> assumption
> > in my case.
> > - the analyzed covariance matrix (i.e. the inverse of the jacobian of the
> > cost function) cannot be simply outputed.
> >
> > Of course I could use a more generic optimization function, like the
> > minimize one.
> > However this seems sub-optimal because the minimisation of a least
> squares
> > problem can dealt more efficiently (the jacobian of the cost function
> can be
> > approximated using the jacobian of the terms to minimize).
> >
> > Can anybody help me?
> > Are there plans to improve the leastsq function?
> leastsq is a low level function and I think we should not load it up
> with any options.
> for weighted least-squares the more highlevel interface with
> additional results is optimize.curve_fit.
> However it doesn't allow for a full covariance matrix for the errors.
> If you want to use leastsq with a full covariance matrix, then you
> could transform both sides yourself, similar to what is done in
> curve_fit, but with the cholesky of the inverse covariance matrix.
> We use that in statsmodels.GLS, but only for linear models.
> But, if there a large number of observations, then using the full
> covariance matrix is inefficient, and in many cases a more direct
> transformation can be used.
> nonlinear least squares is still largely missing in statsmodels.
> I don't know if any of the other packages that are based on leastsq
> have the option.
> Josef
> >
> > Best regards,
> >
> > Frédéric Parrenin
> >
> >
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User@scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> >
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@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/20130627/28a6c0ca/attachment.html 

More information about the SciPy-User mailing list