[BUG] Fix wrong chi-squared identity in ChiSquared._energy_x#965
Open
ANANYA542 wants to merge 1 commit intosktime:mainfrom
Open
[BUG] Fix wrong chi-squared identity in ChiSquared._energy_x#965ANANYA542 wants to merge 1 commit intosktime:mainfrom
ANANYA542 wants to merge 1 commit intosktime:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
###Description
The closed-form _energy_x formula used
chi2.cdf(xi, k + 1)for the partial expectation integral, but the correct identity ischi2.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 + 1for 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:
cdf_k1 = chi2.cdf(xi, k + 1)tocdf_k2 = chi2.cdf(xi, k + 2).k+2formula.Verification:
I created a verification script that compares the fixed _energy_x against direct numerical integration for various values of
kandx. All errors are now at machine precision (< 1e-11).The screenshot depicting the entire verification has been attatched below:
Does your contribution introduce a new dependency? If yes, which one?
No.
What should a reviewer concentrate their feedback on?
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
How to: add yourself to the all-contributors file in the
skproroot directory (not theCONTRIBUTORS.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 pluscodeif you also fixed the bug in the PR).maintenance- CI, test framework, release.See here for full badge reference
For new estimators
docs/source/api_reference/taskname.rst, follow the pattern.Examplessection.python_dependenciestag and ensureddependency isolation, see the estimator dependencies guide.