[SciPy-User] robust fit

Sturla Molden sturla at molden.no
Tue May 31 10:10:07 EDT 2011


I've done this for M-estimates using bisquare weights.

If the errors are

    error(x) = y(x) - fit(x)

you want the minimize the sum of squares of weighted
errors:

    werror(x) = weight(error(x)) * error(x)

Provide one function that returns werror for each x[:,n],y[n]
and another that returns the partial derivatives of werror[:]
with respect to x[i,:]. The latter is the Jacobian that you set
as Dfun keyword argument. I.e. if you have m parameters and
n samples in the array x, the Jacobian is an m x n array.

The last thing you need is an initial guess. This will depend
on the problem, so its hard to give an advide. Just be beware
that a least squares fit will not always work.

If the you think deriving the Jacobian is tedious, consider
using SymPy or just let leastsq approximate it (i.e. set
Dfun to None).

Sturla


Den 30.05.2011 12:58, skrev Piter_:
> Hi all.
> Can anybody point me a direction how to make a robust fit of nonlinear
> function using leastsq.
> Maybe someone have seen ready function doing this.
> Thanks.
> Petro.
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list