You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
@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?
@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
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?
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.
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.
Activity
astrofrog commentedon Oct 3, 2013
@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?
nden commentedon Oct 3, 2013
@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
astrofrog commentedon Oct 3, 2013
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?
nden commentedon Oct 3, 2013
@astrofrog Yes, that's a good way too. I have to find the function in scipy which estimates derivatives.
astrofrog commentedon Oct 3, 2013
@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?
eteq commentedon Oct 4, 2013
scipy.misc.derivativeis 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 appropriatedxfor an arbitrary model.nden commentedon Oct 8, 2013
scipy.misc.derivuses central differences whilescipy.optimize.leastsquses forward differences. I want to use the same algorithm as inscipy.optimize.leastsqbut it's not exposed in python. There's risk of introducing new bugs by writing my ownapproximate_jacobian, so I am going to leave the test as it is for now - comparing parameters.