Skip to content

Pin the fit weight convention with an analytic weighted-least-squares test #370

Closed

Description

@rozyczko

Summary

_prepare_fit_arrays returns weights = 1/sigma and passes them as weights=dy to easy_science_multi_fitter.fit (src/easyreflectometry/fitting.py:122, 254). The internal chi^2 helper (fitting.py:138) consistently treats the same array as sigma-denominators, but whether the EasyScience core fitter expects 1/sigma, sigma, or 1/sigma^2 is not pinned by any numerical test. This is the single most load-bearing assumption in the fitting stack: if the convention is wrong, every fitted parameter uncertainty (and the chi^2-based model comparison) is wrong.

Suggested fix

Add a test that fits a straight line (or single-layer reflectivity) with known heteroscedastic errors and asserts both the parameter values and the parameter covariance against the analytic WLS solution. If the convention turns out mismatched, fix _prepare_fit_arrays accordingly.

Related observations in the same area (can be folded in or split):

  • mcmc_sample (fitting.py:358-437) silently applies the Mighell transform (default hybrid) to zero-variance points feeding the Bayesian likelihood — Mighell is a chi-square bias correction, not a likelihood; at minimum warn (the least-squares path does).
  • DataSet1D.ye defaults to np.zeros_like(x) (data/data_store.py:108), i.e. zero variance, which the fitter then masks/transforms wholesale; "no uncertainties supplied" deserves a loud error.

Found during deep code review (DEEP_ANALYSIS.md §4.10).

Activity

  1. added
    [scope] bug
    [priority] high
    on Jun 12, 2026
  2. added 2 commits that reference this issue on Jul 30, 2026
  3. rozyczko commented on Sep 11, 2026

    @rozyczko
    MemberAuthor

    The issue is no longer valid. It was fixed in the "Core fixes" merge, commit 01c07d5, whose message includes "fixing #370 (#388)".

  4. added a commit that references this issue on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [priority] high[scope] bug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions