Description
From using the joint fitter and the example in the gallery, I noticed there was a bug with the fitter when I pulls out the initial guesses for the parameters to be fitted.
In the model_to_fit_params class method, all the fittable parameter's initial values are put together during its first call. Inspecting the returned value from the method (called fparams in the function), the initial values are [1.0, 5.0, 5.0, 5.0]. The final two values should be for the two stddev values but they are not.
The for loop in the function loops through a list in order that it is also deleting entries from. This means the last two values in fparams using the example actually come from the mean parameters from both models instead. I.e., the method pulls the wrong initial values for the fitting.
This is not really an issue for the example given as a good solution is still found but, obviously, this bug would make fitting a nightmare if these parameters are either in or have to vary in completely different orders of magnitude.
I have a very simple fix for this which can be found in PR #20074 .
Expected behavior
Essentially, in the gallery example the first initial guesses should be made up from the ones given in the initialisation of JointFitter (here [1.0, 5.0]) for the joint parameters. These are held in self.initvals for the JointFitter object. The other parameters being fitted (stddev1 and stddev2) should be pulled from the model initialised values ( i.e., [1.0, 1.0]) from gjf1 and gjf2.
How to Reproduce
- Download the
JointFitter gallery example.
- After
fit_joint is declared, initialising JointFitter, inpect the value of fit_joint.fitparams
- The wrong values are shown. Prints
[1.0, 5.0, 5.0, 5.0] but should be [1.0, 5.0, 1.0, 1.0]
# example gallery code above...
fit_joint = fitting.JointFitter(
[gjf1, gjf2], {gjf1: ["area", "mean"], gjf2: ["area", "mean"]}, [1.0, 5.0]
)
print("Extracted initial fit parameter guesses:", fit_joint.fitparams)
Versions
import astropy
astropy.system_info()
# Paste the result here
platform
--------
platform.platform() = 'macOS-26.5.2-arm64-arm-64bit'
platform.version() = 'Darwin Kernel Version 25.5.0: Tue Jun 9 22:18:58 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6000'
platform.python_version() = '3.12.12'
packages
--------
astropy 0.1.dev41496+g1587fba4e
numpy 2.5.1
scipy 1.18.0
matplotlib 3.11.0
pandas --
pyerfa 2.0.1.5
Description
From using the joint fitter and the example in the gallery, I noticed there was a bug with the fitter when I pulls out the initial guesses for the parameters to be fitted.
In the
model_to_fit_paramsclass method, all the fittable parameter's initial values are put together during its first call. Inspecting the returned value from the method (calledfparamsin the function), the initial values are[1.0, 5.0, 5.0, 5.0]. The final two values should be for the twostddevvalues but they are not.The for loop in the function loops through a list in order that it is also deleting entries from. This means the last two values in
fparamsusing the example actually come from themeanparameters from both models instead. I.e., the method pulls the wrong initial values for the fitting.This is not really an issue for the example given as a good solution is still found but, obviously, this bug would make fitting a nightmare if these parameters are either in or have to vary in completely different orders of magnitude.
I have a very simple fix for this which can be found in PR #20074 .
Expected behavior
Essentially, in the gallery example the first initial guesses should be made up from the ones given in the initialisation of
JointFitter(here[1.0, 5.0]) for the joint parameters. These are held inself.initvalsfor theJointFitterobject. The other parameters being fitted (stddev1andstddev2) should be pulled from the model initialised values ( i.e.,[1.0, 1.0]) fromgjf1andgjf2.How to Reproduce
JointFittergallery example.fit_jointis declared, initialisingJointFitter, inpect the value offit_joint.fitparams[1.0, 5.0, 5.0, 5.0]but should be[1.0, 5.0, 1.0, 1.0]Versions