Skip to content

Add structure-function (variogram) loss for sharper fine-scale fields - #2665

Open
wael-mika wants to merge 2 commits into
ecmwf:developfrom
wael-mika:wm/dev/structure_function_loss
Open

Add structure-function (variogram) loss for sharper fine-scale fields#2665
wael-mika wants to merge 2 commits into
ecmwf:developfrom
wael-mika:wm/dev/structure_function_loss

Conversation

@wael-mika

Copy link
Copy Markdown
Contributor

Description

Adds LossStructureFunction, a grid-free variogram loss that matches the variance of spatial increments per distance bin, so fine-scale fields stay sharp instead of blurring to the MSE conditional mean. Composes with MSE and doubles as a validation sharpness metric. New module + unit tests only; nothing existing changes.
Unit tests to be removed once the PR is reviewed and FT config to be introduced privately or in this repo if needed!

Issue Number

Closes #2663

Checklist before asking for review

  • I have performed a self-review of my code
  • My changes comply with basic sanity checks:
    • I have fixed formatting issues with ./scripts/actions.sh lint
    • I have run unit tests with ./scripts/actions.sh unit-test
    • I have documented my code and I have updated the docstrings.
    • I have added unit tests, if relevant
  • I have tried my changes with data and code:
    • I have run the integration tests with ./scripts/actions.sh integration-test
    • (bigger changes) I have run a full training and I have written in the comment the run_id(s): launch-slurm.py --time 60
    • (bigger changes and experiments) I have shared a hegdedoc in the github issue with all the configurations and runs for this experiments
  • I have informed and aligned with people impacted by my change:
    • for config changes: the MatterMost channels and/or a design doc
    • for changes of dependencies: the MatterMost software development channel

Grid-free structure-function loss (LossStructureFunction) matching S(r)
from point-pair increments, for sharpening smooth ensemble forecasts.
'reduce' supports 'mean', 'median' (per-point sorted middle), 'members'
(SF per sorted member, averaged), or an int member index. Exported in
loss_modules/__init__ so LossCalculator can instantiate it by name from
the config. CPU unit tests included.

Imported from wm/dev/latent_upsampling (eb1e1be, 58aa6fe, b1b5a6c)
without the experiment configs and latent-upsampling engine changes.
Replace the per-bin Python loop and its int(...sum()) guards with a single
bucketize + scatter_add reduction, cutting GPU->CPU host syncs from ~B+1 to 1
per call (x K in members mode) and removing the redundant per-bin boolean-mask
allocations. Also make the module/config docstrings general
@github-actions github-actions Bot added the model Related to model training or definition (not generic infra) label Jul 21, 2026
@s6sebusc

Copy link
Copy Markdown
Contributor

Very cool stuff! Just for future reference, variogram based scores are somewhat popular in ensemble forecasting, this is the key reference: https://doi.org/10.1175/MWR-D-14-00269.1 that probably tells us how this can be generalised to ensembles.
I believe they also typically down-weight the very large distances (or maybe cut them off entirely). Maybe that would be a good idea here too: gridpoints at large distances are typically uncorrelated so comparing the variograms there really only looks at the global variance and not the structure. Skipping them could save on computational effort and allow you to sample more relevant pairs that are closer to each other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Related to model training or definition (not generic infra)

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Task: Add a structure-function (variogram) loss for sharper fine-scale fields

2 participants