Skip to content

[BUG] Fix wrong chi-squared identity in ChiSquared._energy_x#965

Open
ANANYA542 wants to merge 1 commit intosktime:mainfrom
ANANYA542:fix/chi2-energy-x-identity
Open

[BUG] Fix wrong chi-squared identity in ChiSquared._energy_x#965
ANANYA542 wants to merge 1 commit intosktime:mainfrom
ANANYA542:fix/chi2-energy-x-identity

Conversation

@ANANYA542
Copy link

###Description
The closed-form _energy_x formula used chi2.cdf(xi, k + 1) for the partial expectation integral, but the correct identity is chi2.cdf(xi, k + 2).
This PR fixes the identity and updates the associated docstrings.

This caused silently wrong CRPS/energy scores with errors up to 48%. The fix changes k+1 to k+2 on line 186 and updates both docstrings.

Reference Issues/PRs

fixes #964

What does this implement/fix? Explain your changes.

The chi-squared probability density function satisfies the identity:
t · f_χ²(t; k) = k · f_χ²(t; k + 2)

This is easily proved using the relation Γ(k/2 + 1) = (k/2) · Γ(k/2). Integrating both sides yields:
∫₀ˣ t · f_χ²(t; k) dt = k · F_χ²(x; k+2)

The skpro implementation on line 186 mistakenly used k + 1 for this integral: cdf_k1 = chi2.cdf(xi, k + 1).
This mathematical error produced silently incorrect CRPS/energy scores with errors ranging from 25% to nearly 50%.
Changes in this PR:

  1. Changed cdf_k1 = chi2.cdf(xi, k + 1) to cdf_k2 = chi2.cdf(xi, k + 2).
  2. Updated the class-level docstring to reflect the correct k+2 formula.
  3. Updated the _energy_x method docstring.
    Verification:
    I created a verification script that compares the fixed _energy_x against direct numerical integration for various values of k and x. All errors are now at machine precision (< 1e-11).
    The screenshot depicting the entire verification has been attatched below:
Screenshot 2026-03-18 at 2 22 53 AM

Does your contribution introduce a new dependency? If yes, which one?

No.

What should a reviewer concentrate their feedback on?

  • Verifying the mathematical identity (standard chi-squared partial expectation formula).
  • Ensuring the docstring math formatting renders correctly.

Did you add any tests for the change?

No explicit new tests added, but the mathematical fix makes the closed-form solution match the numerical ground truth.

Any other comments?

PR checklist

For all contributions
  • I've added myself to the list of contributors with any new badges I've earned :-)
    How to: add yourself to the all-contributors file in the skpro root directory (not the CONTRIBUTORS.md). Common badges: code - fixing a bug, or adding code logic. doc - writing or improving documentation or docstrings. bug - reporting or diagnosing a bug (get this plus code if you also fixed the bug in the PR).maintenance - CI, test framework, release.
    See here for full badge reference
  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG]. [BUG] - bugfix, [MNT] - CI, test framework, [ENH] - adding or improving code, [DOC] - writing or improving documentation or docstrings.
For new estimators
  • I've added the estimator to the API reference - in docs/source/api_reference/taskname.rst, follow the pattern.
  • I've added one or more illustrative usage examples to the docstring, in a pydocstyle compliant Examples section.
  • If the estimator relies on a soft dependency, I've set the python_dependencies tag and ensured
    dependency isolation, see the estimator dependencies guide.

The closed-form _energy_x formula used chi2.cdf(xi, k + 1) for the
partial expectation integral, but the correct identity is:

    t * f_chi2(t; k) = k * f_chi2(t; k + 2)

so the integral gives k * F(x; k+2), NOT k * F(x; k+1).

This caused silently wrong CRPS/energy scores with errors up to 48%.
The fix changes k+1 to k+2 on line 186 and updates both docstrings.
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.

[BUG] ChiSquared._energy_x uses wrong chi-squared identity (k+1 instead of k+2), up to 48% error

1 participant