Skip to content

Various parameter/stats fixes#112

Merged
ChrisRackauckas merged 4 commits into
masterfrom
transforms
Jun 26, 2026
Merged

Various parameter/stats fixes#112
ChrisRackauckas merged 4 commits into
masterfrom
transforms

Conversation

@JamesWrigley

@JamesWrigley JamesWrigley commented Jun 24, 2026

Copy link
Copy Markdown
Member

This has a bunch of fixes that I found when looking into #110:

  • 5d6afa4: always invert the intercept of a linear fit when a y-transform is applied. Fixes ExpCurveFitAlgorithm in its current form fits exp(b+a*x) instead of b*exp(a*x) #110.
  • fe8210a: King fits previously returned the linearized parameters and I don't think can be modeled exactly with LinearCurveFitAlgorithm anyway. The Jacobian was wrong too. Now it has its own algorithm type. This wasn't caught by the tests before because we weren't checking the fitted parameters against the real parameters.
  • 0fea6a4: not sure if this could happen in practice, but there was a branch in the rational polynomial fit code that would take the residuals from the internal linear fit if available. Now they're always computed using the right formula.
  • 110b70d: the Jacobian for linear fits was previously always computed using the linear Jacobian formula, which would give incorrect results for fits with a y-transform since the residuals are always stored in the original y-space. Now we fall back to DI if a y-transform is applied. Should correct the Jacobians (and thus most of the stats functions) for e.g. exp/power fits.

5d6afa4 and fe8210a are technically breaking, but I would consider them a bug fix since I don't think anyone would expect the old behaviour, so I bumped the version to 1.9.3.

Written with a lot of help from Claude 🤖 Alternative to #111.

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Otherwise `yfun(b)` will be returned instead of `b`, which is
confusing (e.g. `log(b)` instead of `b` for exp/power fits)
Fitting King curves is done by linearizing the model, but recovering the
parameters can't be handled by `LinearCurveFitAlgorithm` applying the inverse
y-transform alone because the `A` and `B` parameters of the King model are
related to each other. Previously this also gave inaccurate initial guesses for
`ModifiedKingCurveFitAlgorithm`. The Jacobian was also incorrect since it was
computed using the linear Jacobian formula.

Now there's a `KingCurveFitAlgorithm` type to dispatch on and recover the
parameters, and the correct analytical Jacobian is used.
The old branch would have optionally taken the residuals from the liinearized
model, which would not be correct.
@JamesWrigley JamesWrigley self-assigned this Jun 24, 2026
The residuals of a linear fit are stored in original y-space, so if a transform
was applied to y we would end up computing the Jacobian for a linear model on
them.
@ChrisRackauckas ChrisRackauckas merged commit 390dd90 into master Jun 26, 2026
22 checks passed
@ChrisRackauckas ChrisRackauckas deleted the transforms branch June 26, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExpCurveFitAlgorithm in its current form fits exp(b+a*x) instead of b*exp(a*x)

2 participants