question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Moffat1D and Moffat2D derivatives

See original GitHub issue

The derivatives in Moffat1D are wrong:

https://github.com/astropy/astropy/blob/2b8fe1305b2689d8b2715f98985e36f2c7d5c0d9/astropy/modeling/functional_models.py#L2223

They should be replaced by:

    @staticmethod
    def fit_deriv(x, amplitude, x_0, gamma, alpha):
        """One dimensional Moffat model derivative with respect to parameters"""

        fac = (1 + (x - x_0) ** 2 / gamma ** 2)
        d_A = fac ** (-alpha)
        d_x_0 = (2 * amplitude * alpha * (x - x_0) * d_A / (fac * gamma ** 2))
        d_gamma = (2 * amplitude * alpha * (x - x_0) ** 2 * d_A /
                   (fac * gamma ** 3))
        d_alpha = -amplitude * d_A * np.log(fac)
        return [d_A, d_x_0, d_gamma, d_alpha]

In Moffat2D:

https://github.com/astropy/astropy/blob/2b8fe1305b2689d8b2715f98985e36f2c7d5c0d9/astropy/modeling/functional_models.py#L2301

only derivative wrt gamma is wrong. It should be

        d_gamma = 2 * amplitude * alpha * d_A * rr_gg / ((1 + rr_gg) * gamma ** 3)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
adonathcommented, Nov 9, 2018

I remember that for the Beta1D and Beta2D models I computed the derivatives and reference values in a notebook using using Sympy (http://nbviewer.jupyter.org/gist/adonath/6088712). So I’m pretty sure it used to be correct at that time. Maybe when the rename to Moffat1D and Moffat2D happened, the parametrization changed as well and the derivatives where not adapted? From a quick look in the code it seems there are no unit tests for the model derivatives.

@ycopin I didn’t check whether your proposed formulae are correct, please check against Sympy or some other algebra library and post the result as a reference. In case you still find the current formulae are incorrect, would you mind preparing a minimal pull request with the correct ones? Ideally one should add unit tests for the model derivatives, but this is a somewhat larger project…

0reactions
ycopincommented, Sep 30, 2020

I’m sorry I introduced a bug in Moffat2D derivatives… 😕 As mentioned earlier, verifying the formal derivatives using e.g. Wolfram is not necessarily sufficient, but one should check the actual implementation, thanks @saimn for doing so (even if the tested implementation might not be the most efficient). I still wonder why this implementation error was not caught by a test comparing formal and numerical derivatives…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Moffat1D — Astropy v5.2
Moffat1D (amplitude=1, x_0=0, gamma=1, alpha=1, **kwargs)[source]¶ ... One dimensional Moffat model derivative with respect to parameters ...
Read more >
astropy.modeling.functional_models — Astropy v1.2.dev14793
... Box1D, Moffat1D, Lorentz1D """ amplitude = Parameter(default=1) mean ... amplitude, mean, stddev): """ Gaussian1D model function derivatives.
Read more >
Moffat1D — Astropy v1.0.4
One dimensional Moffat model. Parameters: amplitude : float. Amplitude of the model. x_0 : float. x position of the ...
Read more >
python-astropy-4.0.2-bp153.1.10 - SUSE Package Hub
[#10697] Fix calculation of the Moffat2D derivative with respect to gamma. ... [#8052] * Fix ``Moffat1D`` and ``Moffat2D`` derivatives.
Read more >
astropy Changelog - pyup.io
determine a matrix of partial derivatives of each world coordinate with ... Fix ``Moffat1D`` and ``Moffat2D`` derivatives. [8108] astropy.nddata
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found