Moffat1D and Moffat2D derivatives
See original GitHub issueThe derivatives in Moffat1D are wrong:
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:
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:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I remember that for the
Beta1D
andBeta2D
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 toMoffat1D
andMoffat2D
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…
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…