Add spread_squared ensemble variance metric for probabilistic evaluation - #430
Closed
Sir-Sloth-The-Lazy wants to merge 7 commits into
Closed
Add spread_squared ensemble variance metric for probabilistic evaluation#430Sir-Sloth-The-Lazy wants to merge 7 commits into
Sir-Sloth-The-Lazy wants to merge 7 commits into
Conversation
Refactor error map plotting function to heatmap and improve layout computation.
Added a HeatmapDatastore class for testing heatmap plots and updated tests to verify heatmap behavior.
Scale metric heatmap figure size and improve readability for larger outputs.
…ense grid annotation suppression
…cale control - expose optional vmin/vmax args so callers can fix a shared colour scale across multiple heatmaps (e.g. val vs test comparison) - propagate params through the plot_error_map deprecation wrapper - add tests: explicit vmin/vmax respected, cross-run scale consistency - update docstring to document new parameters Follow-up to mllam#376
Implements spread_squared following the existing metric API contract: - Signature: (pred, target, pred_std, mask, average_grid, sum_vars) - Accepts (..., S, N, d_state) ensemble predictions with S at dim=-3 - Uses Bessel's correction (S/(S-1)) for unbiased sample variance - Calls mask_and_reduce_metric internally, consistent with mse/mae/nll - Registered in DEFINED_METRICS as "spread_squared" - Asserts S > 1 (single-member variance is undefined) Also fixes pre-existing vis.py breakage from the heatmap refactor: - Restores _TITLE_SIZE, _LABEL_SIZE, _TICK_SIZE, _tex_safe, plot_on_axis (used by plot_prediction and plot_spatial_error but accidentally removed) - Removes unused top-level cartopy.crs import (moved inside plot_on_axis) - Removes unused Iterator and patch imports from tests/test_plotting.py Adds tests/test_metrics.py with 9 tests covering mathematical correctness, Bessel's correction, S=1 guard, shape contract, mask filtering, and consistency with torch.var(unbiased=True).
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.
Describe your changes
Add
spread_squared(ensemble variance) metric to the metrics module.This metric computes the unbiased sample variance across ensemble members, following the same API pattern as all existing metrics:
(pred, target, pred_std, mask, average_grid, sum_vars). Entry-wise variance is computed first across the ensemble dimension (dim=-3), then passed throughmask_and_reduce_metricfor grid masking and optional reduction.Key design decisions:
mse,mae,nll, etc.targetandpred_stdare accepted but unused, maintaining the uniform interface expected byget_metric()callers inar_model.py.ens_dim = -3: Ensemble members are at the third-from-last dim, consistent with the(..., N, d_state)convention used throughout the metrics module. For(B, S, T, N, F)input per [RFC/Design] Standardize probabilistic vs deterministic return contract to unblock evaluation integrations #335, this correctly reduces over S.assert S > 1: Single-member variance is undefinedmask_and_reduce_metriccall: Follows the same pattern as every other metric in the file.This metric is a prerequisite for spread-skill analysis of ensemble and probabilistic models (Graph-EFM, Diffusion-LAM) tracked in #62.
Dependencies: None
Issue Link
Addresses parts of #62
Related discussion: #226, #335
Type of change
Checklist before requesting a review
pullwith--rebaseoption if possible).Checklist for reviewers
Each PR comes with its own improvements and flaws. The reviewer should check the following:
Author checklist after completed review
reflecting type of change (add section where missing):
Checklist for assignee