Repository navigation
[BUG] fix NormalMixture energy to use the component means - #1209
Open
Mudassiruddin7 wants to merge 1 commit into
Open
Mudassiruddin7 wants to merge 1 commit into
Mudassiruddin7 wants to merge 1 commit into
Conversation
`NormalMixture._energy_self` ignored the component means and used a variance-weighted average in `2 * sqrt(2 * avg_sigma_sq / pi)`, which is off by a factor of sqrt(2) even for a single component and does not depend on the means at all. The energy E|X - Y| of two i.i.d. mixture draws is the weighted sum over component pairs of the folded-normal mean with d = mu_k - mu_l and s^2 = sigma_k^2 + sigma_l^2. Compute that, which also fixes CRPS values obtained from `energy`. Fixes sktime#1184
Mudassiruddin7
requested review from
felipeangelimvieira and
fkiraly
as code owners
October 8, 2026 17:26
This branch has not been deployed
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.
Reference Issues/PRs
Fixes #1184.
What does this implement/fix? Explain your changes.
NormalMixture._energy_selfdid not compute E|X - Y|. It dropped the component means and used2 * sqrt(2 * avg_sigma_sq / pi)with a variance-weighted average, which is off by a factor of sqrt(2) even for one component (1.5958 instead of 1.1284 for a standard normal) and cannot change with the means. Sinceenergyis tagged exact, CRPS values computed from it were wrong too.For two independent mixture draws, E|X - Y| is the pair sum
sum_k sum_l pi_k pi_l E|N_k - N_l|. Each term is the mean of a folded normal, withd = mu_k - mu_lands^2 = sigma_k^2 + sigma_l^2:d * erf(d / (s * sqrt(2))) + s * sqrt(2 / pi) * exp(-d^2 / (2 s^2)). That is what_energy_selfnow computes, for any number of rows, components and outputs, and it still sums over outputs like before.I checked it against the closed form and numerical quadrature of
2 * integral of F (1 - F)for the three cases in #1184 (1.1284, 2.5224, 10.5642), a three-component mixture, and a batched two-row, two-output example, and they agree to five decimals. The CRPS example in the issue now gives 0.6054, the value fromscoringrulesthat the issue quotes.Does your contribution introduce a new dependency? If yes, which one?
No.
What should a reviewer concentrate their feedback on?
(n_samples, K, K, n_outputs), so memory grows with the square of the number of components. That seemed fine for mixture density networks, where K is small, but say if you'd rather loop over components.Did you add any tests for the change?
Yes, in
test_normal_mixture.py: energy against quadrature for four mixtures, the single-component case against2 sigma / sqrt(pi), a batched example with per-row weights and two outputs, and CRPS fromenergyagainst its defining integral. Seven of the thirteen tests in the file fail on the old formula. The 120 tests inskpro/distributionsandskpro/metricsthat involveNormalMixture, energy or CRPS pass.Any other comments?
_energy_xwas already correct and is unchanged.PR checklist
For all contributions