Skip to main content

Implementations of the CRPS using PyTorch

Project description

torch-crps

License: CC-BY-4.0 python Docs CD Coverage Tests mkdocs-material mypy pre-commit pytest Ruff uv

Implementations of the Continuously-Ranked Probability Score (CRPS) using PyTorch

Background

The Continuously-Ranked Probability Score (CRPS) is a strictly proper scoring rule. It assesses how well a distribution with the cumulative distribution function $F$ is explaining an observation $y$

$$ \text{CRPS}(F,y) = \int _{\mathbb {R} }(F(x)-\mathbb {1} (x\geq y))^{2}dx \qquad (\text{integral formulation}) $$

where $1$ denoted the indicator function.

In Section 2 of this paper Zamo & Naveau list 3 different formulations of the CRPS.

Incomplete list of sources that I came across while researching about the CRPS

  • Hersbach, "Decomposition of the Continuous Ranked Probability Score for Ensemble Prediction Systems"; 2000
  • Gneiting et al.; "Calibrated Probabilistic Forecasting Using Ensemble Model Output Statistis and Minimum CRPS Estimation"; 2004
  • Gneiting & Raftery; "Strictly Proper Scoring Rules, Prediction, and Estimation"; 2007
  • Zamo & Naveau; "Estimation of the Continuous Ranked Probability Score with Limited Information and Applications to Ensemble Weather Forecasts"; 2018
  • Jordan et al.; "Evaluating Probabilistic Forecasts with scoringRules"; 2019
  • Olivares & Négiar & Ma et al; "CLOVER: Probabilistic Forecasting with Coherent Learning Objective Reparameterization"; 2023
  • Vermorel & Tikhonov; "Continuously-Ranked Probability Score (CRPS)" blog post; 2024
  • Nvidia; "PhysicsNeMo Framework" source code; 2025
  • Zheng & Sun; "MVG-CRPS: A Robust Loss Function for Multivariate Probabilistic Forecasting"; 2025

Application to Machine Learning

The CRPS can be used as a loss function in machine learning, just like the well-known negative log-likelihood loss which is the log scoring rule.

The parametrized model outputs a distribution $q(x)$. The CRPS loss evaluates how good $q(x)$ is explaining the observation $y$. This is a distribution-to-point evaluation, which fits well for machine learning as the ground truth $y$ almost always comes as fixed values.

For processes over time and/or space, we need to estimate the CRPS for every point in time/space separately.

There is work on multi-variate CRPS estimation, but it is not part of this repo.

Implementation

The integral formulation is infeasible to naively evaluate on a computer due to the infinite integration over $x$.

I found Nvidia's implementation of the CRPS for ensemble preductions in $M log(M)$ time inspiring to read.

:point_right: Please have a look at the documentation to get started.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_crps-0.1.4.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_crps-0.1.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file torch_crps-0.1.4.tar.gz.

File metadata

  • Download URL: torch_crps-0.1.4.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torch_crps-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e19a4bb8f82297f0d3614df689cb6366569089dc75b86010458370ca1868b9e5
MD5 5122c602952538cd665e5f2dee13adf3
BLAKE2b-256 5f3d2739070d3cacdbaf129574e7ac1f8459b4a8fad6d801822eb104dcb23f02

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_crps-0.1.4.tar.gz:

Publisher: cd.yaml on famura/torch-crps

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torch_crps-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: torch_crps-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torch_crps-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b9361f07edd3f0fb729dcec7999274320330209e678721c9390ab6045fbc86f1
MD5 f203c2fc70f9854e9e6f3f977587d634
BLAKE2b-256 02f7a2854cf155180cf40dc20ffe8fa28b93d4d6613a5cfc044e05ba9d5d4ebd

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_crps-0.1.4-py3-none-any.whl:

Publisher: cd.yaml on famura/torch-crps

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page