Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JointFitter obtains incorrect initial values for fitting #20073

Copy link
Copy link

Description

@KriSun95
Issue body actions

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

  1. Download the JointFitter gallery example.
  2. After fit_joint is declared, initialising JointFitter, inpect the value of fit_joint.fitparams
  3. 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
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.