Skip to main content

A package to compute the Continuous Ranked Probability Score (CRPS), the Fair-CRPS, and the Adjusted-CRPS. Read the documentation at https://github.com/garovent/CRPS

Project description

Documentation

A package to compute the continuous ranked probability score (crps) (Matheson and Winkler, 1976; Hersbach, 2000), the fair-crps (fcrps) (Ferro et al., 2008), and the adjusted-crps (acrps) (Ferro et al., 2008) given an ensemble prediction and an observation.

The CRPS is a negatively oriented score that is used to compare the empirical distribution of an ensemble prediction to a scalar observation.

Read documentation at https://github.com/garovent/CRPS

References:

[1] Matheson, J. E. & Winkler, R. L. Scoring Rules for Continuous Probability Distributions. Management Science 22, 1087–1096 (1976).

[2] Hersbach, H. Decomposition of the Continuous Ranked Probability Score for Ensemble Prediction Systems. Wea. Forecasting 15, 559–570 (2000).

[3] Ferro, C. A. T., Richardson, D. S. & Weigel, A. P. On the effect of ensemble size on the discrete and continuous ranked probability scores. Meteorological Applications 15, 19–24 (2008).

Installation:

pip install CRPS

Parameters:

ensemble_members: numpy.ndarray

The predicted ensemble members. They will be sorted in ascending order automatically.

Ex: np.array([2.1,3.5,4.7,1.2,1.3,5.2,5.3,4.2,3.1,1.7])

observation: float

The observed scalar.

Ex: 5.4

adjusted_ensemble_size: int, optional

The size the ensemble needs to be adjusted to before computing the Adjusted Continuous Ranked Probability Score. The default is 200.

Note: The crps becomes equal to acrps when adjusted_ensemble_size equals the length of the ensemble_members.

Methods:

compute():

Computes the continuous ranked probability score (crps), the fair-crps (fcrps), and the adjusted-crps (acrps).

Returns:

crps,fcrps,acrps

Attributes:

cdf_fc:

Empirical cumulative distribution function (CDF) of the forecasts (y). F(y) in the crps equation.

cdf_ob:

CDF (heaviside step function) for the observation (o). It takes 0 for values is less than the observation, and 1 otherwise. Fo(y) in the crps equation.

delta_fc:

dy term in the crps equation.

crps: Continuous Ranked Probability Score

It is the integral of the squared difference between the CDF of the forecast ensemble and the observation.

crps

fcrps: Fair-Continuous Ranked Probability Score

It is the crps computed assuming an infinite ensemble size.

fcrps

where m is the current ensemble size (i.e., len(ensemble_members))

acrps: Adjusted-Continuous Ranked Probability Score

It is the crps computed assuming an ensemble size of M.

acrps

where M is the adjusted_ensemble_size

Demonstration:

import numpy as np
import CRPS.CRPS as pscore

Example - 1

In [1]: pscore(np.random.uniform(2,5,50),3.5).compute()
Out[1]: (0.24374216742963792, 0.2332762342590258, 0.23589271755167882)

Example - 2

In [2]: crps,fcrps,acrps = pscore(np.random.uniform(1.2,7,100),8.3,50).compute()
In [3]: crps
Out[3]: 3.11890267263096
In [4]: fcrps
Out[4]: 3.109573704801023
In [5]: acrps
Out[5]: 3.129164537243891

Example - 3

In [1]: fc = np.random.uniform(4.6,5.3,100)
In [2]: ob = 4.9
In [3]: ps = pscore(fc,ob)
In [4]: ps.compute()
Out[4]: (0.05767439558002044, 0.05651649413199454, 0.05709544485600749)
In [5]: import matplotlib.pyplot as plt
In [6]: plt.plot(ps.fc,ps.cdf_fc,'-r',label='fc')
   ...: plt.plot(ps.fc,ps.cdf_ob,'-k',label='ob')
   ...: plt.plot(ps.fc,(ps.cdf_fc-ps.cdf_ob)**2,'-b')
   ...: plt.fill_between(ps.fc,(ps.cdf_fc-ps.cdf_ob)**2,label='crps')
   ...: plt.legend()
Out[6]:

illustration

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

CRPS-1.0.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

CRPS-1.0.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file CRPS-1.0.3.tar.gz.

File metadata

  • Download URL: CRPS-1.0.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for CRPS-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0776787557f56be3c77619e4cea65f9f22825d0cd508545cf4c6599c79a601d1
MD5 0149b52982ea40e590702edb2546b88b
BLAKE2b-256 0876046368ab12d58513dd608a0ca75d2be01c522cd543e326226a636b78043c

See more details on using hashes here.

File details

Details for the file CRPS-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: CRPS-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for CRPS-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 682d773efb4cf46dda966d904af7d08b293e0b720b80af924950e1fe3756071b
MD5 0b0e8236a9cfeaa7366ca36c59841e45
BLAKE2b-256 4f0f3b6d34d87004cc0b87c5557b87aa95fab6e7f3549bc3ced0ece71a297fd3

See more details on using hashes here.

Supported by

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