Skip to content

FitManager: make uncertainty trigger the use of weighted fit#4591

Open
kif wants to merge 8 commits intosilx-kit:mainfrom
kif:4590_weighted_fit
Open

FitManager: make uncertainty trigger the use of weighted fit#4591
kif wants to merge 8 commits intosilx-kit:mainfrom
kif:4590_weighted_fit

Conversation

@kif
Copy link
Copy Markdown
Member

@kif kif commented Apr 29, 2026

related to #4590

PR summary

More intuitive handling of uncertainties

AI Disclosure

  • No AI used
  • AI tool(s) ... used for ...

@t20100
Copy link
Copy Markdown
Member

t20100 commented Apr 29, 2026

From what I understand, your fix doe not correspond to theFitManager docstring:

    :param weight_flag: If this parameter is ``True`` and ``sigmay``
        uncertainties are not specified, the square root of ``y`` is used
        as weights in the least-squares problem. If ``False``, the
        uncertainties are set to 1.
    :type weight_flag: boolean

https://github.com/kif/silx/blob/afdef395d150e0052ec6c484793ea472ef9b8f66/src/silx/math/fit/fitmanager.py#L78-L82

-> If weight flag is False, uncertainties should be ignored...

@kif
Copy link
Copy Markdown
Member Author

kif commented Apr 29, 2026

False is the default value, which is a mistake to me: it should be None and switch to False if no sigmay is provided.
When a user provides uncertainties, it should not crash, especially that I am following the example of the documentation ...

self.sigmay = (
numpy.array(sigmay) if self.fitconfig["WeightFlag"] else None
)
self.fitconfig["WeightFlag"] = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then maybe good to add to the setdata docstring that setting sigmay enables WeightFlag. I agree it is expected but since there looks to be a few ways to set this best to make it explicit.

Did you check how this works from the fit widgets?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I did not check it ... BTW, I doubt this code is used anywhere since the "split Pseudo-Voigt 2" mode could not work at all, since array are not initialized at the proper size.

The code-style is very PyMca-like, fit results would deserve to be dataclass or namedtuple instances, but this is not the use-case for this PR.

Copy link
Copy Markdown
Member

@vasole vasole May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code-style is very PyMca-like, fit results would deserve to be dataclass or namedtuple instances, but this is not the use-case for this PR.

I would prefer the expression "pre python2.6" (released in October 2008). PyMca could not use something that was not existing when it was written.

@kif
Copy link
Copy Markdown
Member Author

kif commented Apr 30, 2026

I just checked, the GUI still works, and the bug about "Split pseudo-Voigt 2" is gone with this PR.

Copy link
Copy Markdown
Member

@t20100 t20100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking the GUI and for looking into this!

Two minor comments, otherwise LGTM

BTW, I doubt this code is used anywhere

Provided the issues you fixed, probably...

Comment thread src/silx/_version.py
Comment on lines +81 to +89
class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: str
serial: int

version_info = _version_info(MAJOR, MINOR, MICRO, RELEV, SERIAL)

version_info = VersionInfo(MAJOR, MINOR, MICRO, RELEV, SERIAL)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it private:

Suggested change
class VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: str
serial: int
version_info = _version_info(MAJOR, MINOR, MICRO, RELEV, SERIAL)
version_info = VersionInfo(MAJOR, MINOR, MICRO, RELEV, SERIAL)
class _VersionInfo(NamedTuple):
major: int
minor: int
micro: int
releaselevel: str
serial: int
version_info = _VersionInfo(MAJOR, MINOR, MICRO, RELEV, SERIAL)

Comment thread src/silx/math/fit/fitmanager.py Outdated
Co-authored-by: Thomas VINCENT <thomas.vincent@esrf.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants