Skip to content

fix derivatives in some models #1524

Closed

Description

@nden

The derivatives of some of the models are incorrect.
I wrote a test which fits a model to the same data in two ways - using the derivative function and estimating the derivatives and requires the parameters to agree within some tolerance. Four models fail the test.

While I am working on a patch to fix these four derivatives, I am wondering what the best way to test them is. Is the above test sufficient? Any other ideas?

Activity

  1. ghost assigned on Oct 3, 2013
  2. astrofrog commented on Oct 3, 2013

    @astrofrog
    Member

    @nden - to make sure I understand, you are comparing the derivative returned by the derivative function to the one you compute numerically from the function itself?

  3. nden commented on Oct 3, 2013

    @nden
    ContributorAuthor

    @astrofrog I am actually comparing the parameters after fitting twice - once using the derivative function to compute the derivatives and once with estimated derivatives using

    fitter(x, y, estimate_jacobian=True)
    
  4. astrofrog commented on Oct 3, 2013

    @astrofrog
    Member

    Ah I see - so what I was suggesting is different and might be a good idea to implement too - without doing any fitting, just compare the derivative in case where it's defined to the one you estimate directly from the model values? (just for some set of parameters). What do you think?

  5. nden commented on Oct 3, 2013

    @nden
    ContributorAuthor

    @astrofrog Yes, that's a good way too. I have to find the function in scipy which estimates derivatives.

  6. astrofrog commented on Oct 3, 2013

    @astrofrog
    Member

    @nden - if there isn't one, you could just do it by hand, i.e. just evaluate the model at two very close x values?

  7. eteq commented on Oct 4, 2013

    @eteq
    Member

    scipy.misc.derivative is what you want, I think - that does finite difference derivatives of arbitrary python functions. The main problem is that it doesn't have a built-in way to determine the appropriate dx (oddly, the default is 1, which is often very wrong). So you might need to implement some mild iterative approach do estimate an appropriate dx for an arbitrary model.

  8. nden commented on Oct 8, 2013

    @nden
    ContributorAuthor

    scipy.misc.deriv uses central differences while scipy.optimize.leastsq uses forward differences. I want to use the same algorithm as in scipy.optimize.leastsq but it's not exposed in python. There's risk of introducing new bugs by writing my own approximate_jacobian, so I am going to leave the test as it is for now - comparing parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions