Continuous Ranked Probability Score
Formally, the CRPS is expressed as
where \(F(x) = P(X<x)\) is the forecast CDF and \(\mathbb{1}\{x \le y\}\) the empirical CDF of the scalar observation \(y\). \(\mathbb{1}\) is the indicator function. The CRPS can also be viewed as the Brier score integrated over all real-valued thresholds.
Analytical formulations
scoringrules.crps_beta
crps_beta(
observation: ArrayLike,
a: ArrayLike,
b: ArrayLike,
/,
lower: ArrayLike = 0.0,
upper: ArrayLike = 1.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the beta distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(F_{\alpha, \beta}\) is the beta distribution function with shape parameters \(\alpha, \beta > 0\), and lower and upper bounds \(l, u \in \R\), \(l < u\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
a
|
ArrayLike
|
First shape parameter of the forecast beta distribution. |
required |
b
|
ArrayLike
|
Second shape parameter of the forecast beta distribution. |
required |
lower
|
ArrayLike
|
Lower bound of the forecast beta distribution. |
0.0
|
upper
|
ArrayLike
|
Upper bound of the forecast beta distribution. |
1.0
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between Beta(a, b) and obs. |
Examples:
scoringrules.crps_binomial
crps_binomial(
observation: ArrayLike,
n: ArrayLike,
prob: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the binomial distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(f_{n, p}\) and \(F_{n, p}\) are the PDF and CDF of the binomial distribution with size parameter \(n = 0, 1, 2, ...\) and probability parameter \(p \in [0, 1]\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values as an integer or array of integers. |
required |
n
|
ArrayLike
|
Size parameter of the forecast binomial distribution as an integer or array of integers. |
required |
prob
|
ArrayLike
|
Probability parameter of the forecast binomial distribution as a float or array of floats. |
required |
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between Binomial(n, prob) and obs. |
Examples:
scoringrules.crps_exponential
crps_exponential(
observation: ArrayLike,
rate: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the exponential distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(F_{\lambda}\) is exponential distribution function with rate parameter \(\lambda > 0\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
rate
|
ArrayLike
|
Rate parameter of the forecast exponential distribution. |
required |
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between Exp(rate) and obs. |
Examples:
scoringrules.crps_exponentialM
crps_exponentialM(
observation: ArrayLike,
/,
mass: ArrayLike = 0.0,
location: ArrayLike = 0.0,
scale: ArrayLike = 1.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the standard exponential distribution with a point mass at the boundary.
It is based on the following formulation from Jordan et al. (2019):
where \(F_{M, \mu, \sigma}\) is standard exponential distribution function generalised using a location parameter \(\mu\) and scale parameter \(\sigma < 0\) and a point mass \(M \in [0, 1]\) at \(\mu\), \(F_{M} = F_{M, 0, 1}\), and
for \(y \geq 0\), and 0 otherwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
mass
|
ArrayLike
|
Mass parameter of the forecast exponential distribution. |
0.0
|
location
|
ArrayLike
|
Location parameter of the forecast exponential distribution. |
0.0
|
scale
|
ArrayLike
|
Scale parameter of the forecast exponential distribution. |
1.0
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between obs and ExpM(mass, location, scale). |
Examples:
scoringrules.crps_2pexponential
crps_2pexponential(
observation: ArrayLike,
scale1: ArrayLike,
scale2: ArrayLike,
location: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the two-piece exponential distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(F_{\sigma_{1}, \sigma_{2}, \mu}\) is the two-piece exponential distribution function with scale parameters \(\sigma_{1}, \sigma_{2} > 0\) and location parameter \(\mu\). The parameter \(\sigma_{\pm}\) is equal to \(\sigma_{1}\) if \(y < 0\) and \(\sigma_{2}\) if \(y \geq 0\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
scale1
|
ArrayLike
|
First scale parameter of the forecast two-piece exponential distribution. |
required |
scale2
|
ArrayLike
|
Second scale parameter of the forecast two-piece exponential distribution. |
required |
location
|
ArrayLike
|
Location parameter of the forecast two-piece exponential distribution. |
required |
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between 2pExp(sigma1, sigma2, location) and obs. |
Examples:
scoringrules.crps_gamma
crps_gamma(
observation: ArrayLike,
shape: ArrayLike,
/,
rate: ArrayLike | None = None,
*,
scale: ArrayLike | None = None,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the gamma distribution.
It is based on the following formulation from Scheuerer and Möller (2015):
where \(F_{\alpha, \beta}\) is gamma distribution function with shape parameter \(\alpha > 0\) and rate parameter \(\beta > 0\) (equivalently, with scale parameter \(1/\beta\)).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
shape
|
ArrayLike
|
Shape parameter of the forecast gamma distribution. |
required |
rate
|
ArrayLike | None
|
Rate parameter of the forecast rate distribution. |
None
|
scale
|
ArrayLike | None
|
Scale parameter of the forecast scale distribution, where |
None
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between obs and Gamma(shape, rate). |
Examples:
Raises:
Type | Description |
---|---|
ValueError
|
If both |
scoringrules.crps_gev
crps_gev(
observation: ArrayLike,
shape: ArrayLike,
/,
location: ArrayLike = 0.0,
scale: ArrayLike = 1.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the generalised extreme value (GEV) distribution.
It is based on the following formulation from Friederichs and Thorarinsdottir (2012):
Special cases are handled as follows:
- For \(\xi = 0\):
- For \(\xi \neq 0\):
where \(C\) is the Euler-Mascheroni constant, \(\text{Ei}\) is the exponential integral, and \(\Gamma\) is the gamma function. The GEV cumulative distribution function \(F_{\xi}\) and the auxiliary function \(G_{\xi}\) are defined as:
- For \(\xi = 0\):
- For \(\xi \neq 0\):
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
shape
|
ArrayLike
|
Shape parameter of the forecast GEV distribution. |
required |
location
|
ArrayLike
|
Location parameter of the forecast GEV distribution. |
0.0
|
scale
|
ArrayLike
|
Scale parameter of the forecast GEV distribution. |
1.0
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between obs and GEV(shape, location, scale). |
Examples:
scoringrules.crps_gpd
crps_gpd(
observation: ArrayLike,
shape: ArrayLike,
/,
location: ArrayLike = 0.0,
scale: ArrayLike = 1.0,
mass: ArrayLike = 0.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the generalised pareto distribution (GPD).
It is based on the following formulation from Jordan et al. (2019):
where \(F_{M, \xi, \mu, \sigma}\) is the GPD distribution function with shape parameter \(\xi < 1\), location parameter \(\mu\), scale parameter \(\sigma > 0\), and point mass \(M \in [0, 1]\) at the lower boundary. \(F_{M, \xi} = F_{M, \xi, 0, 1}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
shape
|
ArrayLike
|
Shape parameter of the forecast GPD distribution. |
required |
location
|
ArrayLike
|
Location parameter of the forecast GPD distribution. |
0.0
|
scale
|
ArrayLike
|
Scale parameter of the forecast GPD distribution. |
1.0
|
mass
|
ArrayLike
|
Mass parameter at the lower boundary of the forecast GPD distribution. |
0.0
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between obs and GPD(shape, location, scale, mass). |
Examples:
scoringrules.crps_gtclogistic
crps_gtclogistic(
observation: ArrayLike,
location: ArrayLike,
scale: ArrayLike,
/,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
lmass: ArrayLike = 0.0,
umass: ArrayLike = 0.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the generalised truncated and censored logistic distribution.
where \(F\) is the CDF of the standard logistic distribution, \(F_{l, L, \mu, \sigma}^{u, U}\) is the CDF of the logistic distribution truncated below at \(l\) and above at \(u\), with point masses \(L, U > 0\) at the lower and upper boundaries, respectively, and location and scale parameters \(\mu\) and \(\sigma > 0\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
location
|
ArrayLike
|
Location parameter of the forecast distribution. |
required |
scale
|
ArrayLike
|
Scale parameter of the forecast distribution. |
required |
lower
|
ArrayLike
|
Lower boundary of the truncated forecast distribution. |
float('-inf')
|
upper
|
ArrayLike
|
Upper boundary of the truncated forecast distribution. |
float('inf')
|
lmass
|
ArrayLike
|
Point mass assigned to the lower boundary of the forecast distribution. |
0.0
|
umass
|
ArrayLike
|
Point mass assigned to the upper boundary of the forecast distribution. |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between gtcLogistic(location, scale, lower, upper, lmass, umass) and obs. |
Examples:
scoringrules.crps_tlogistic
crps_tlogistic(
observation: ArrayLike,
location: ArrayLike,
scale: ArrayLike,
/,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the truncated logistic distribution.
It is based on the formulation for the generalised truncated and censored logistic distribution with lmass and umass set to zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
location
|
ArrayLike
|
Location parameter of the forecast distribution. |
required |
scale
|
ArrayLike
|
Scale parameter of the forecast distribution. |
required |
lower
|
ArrayLike
|
Lower boundary of the truncated forecast distribution. |
float('-inf')
|
upper
|
ArrayLike
|
Upper boundary of the truncated forecast distribution. |
float('inf')
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between tLogistic(location, scale, lower, upper) and obs. |
Examples:
scoringrules.crps_clogistic
crps_clogistic(
observation: ArrayLike,
location: ArrayLike,
scale: ArrayLike,
/,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the censored logistic distribution.
It is based on the formulation for the generalised truncated and censored logistic distribution with lmass and umass set to the tail probabilities of the predictive distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
location
|
ArrayLike
|
Location parameter of the forecast distribution. |
required |
scale
|
ArrayLike
|
Scale parameter of the forecast distribution. |
required |
lower
|
ArrayLike
|
Lower boundary of the truncated forecast distribution. |
float('-inf')
|
upper
|
ArrayLike
|
Upper boundary of the truncated forecast distribution. |
float('inf')
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between cLogistic(location, scale, lower, upper) and obs. |
Examples:
scoringrules.crps_gtcnormal
crps_gtcnormal(
observation: ArrayLike,
location: ArrayLike,
scale: ArrayLike,
/,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
lmass: ArrayLike = 0.0,
umass: ArrayLike = 0.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the generalised truncated and censored normal distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(\Phi\) and \(\phi\) are respectively the CDF and PDF of the standard normal distribution, \(F_{l, L, \mu, \sigma}^{u, U}\) is the CDF of the normal distribution truncated below at \(l\) and above at \(u\), with point masses \(L, U > 0\) at the lower and upper boundaries, respectively, and location and scale parameters \(\mu\) and \(\sigma > 0\). \(F_{l, L}^{u, U} = F_{l, L, 0, 1}^{u, U}\).
Examples:
scoringrules.crps_tnormal
crps_tnormal(
observation: ArrayLike,
location: ArrayLike,
scale: ArrayLike,
/,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the truncated normal distribution.
It is based on the formulation for the generalised truncated and censored normal distribution with distribution with lmass and umass set to zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
location
|
ArrayLike
|
Location parameter of the forecast distribution. |
required |
scale
|
ArrayLike
|
Scale parameter of the forecast distribution. |
required |
lower
|
ArrayLike
|
Lower boundary of the truncated forecast distribution. |
float('-inf')
|
upper
|
ArrayLike
|
Upper boundary of the truncated forecast distribution. |
float('inf')
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between tNormal(location, scale, lower, upper) and obs. |
Examples:
scoringrules.crps_cnormal
crps_cnormal(
observation: ArrayLike,
location: ArrayLike,
scale: ArrayLike,
/,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the censored normal distribution.
It is based on the formulation for the generalised truncated and censored normal distribution with lmass and umass set to the tail probabilities of the predictive distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
location
|
ArrayLike
|
Location parameter of the forecast distribution. |
required |
scale
|
ArrayLike
|
Scale parameter of the forecast distribution. |
required |
lower
|
ArrayLike
|
Lower boundary of the truncated forecast distribution. |
float('-inf')
|
upper
|
ArrayLike
|
Upper boundary of the truncated forecast distribution. |
float('inf')
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between cNormal(location, scale, lower, upper) and obs. |
Examples:
scoringrules.crps_gtct
crps_gtct(
observation: ArrayLike,
df: ArrayLike,
/,
location: ArrayLike = 0.0,
scale: ArrayLike = 1.0,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
lmass: ArrayLike = 0.0,
umass: ArrayLike = 0.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the generalised truncated and censored t distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(F_{\nu}\) is the CDF of the standard t distribution with \(\nu > 1\) degrees of freedom, distribution, \(F_{l, L, \nu, \mu, \sigma}^{u, U}\) is the CDF of the t distribution truncated below at \(l\) and above at \(u\), with point masses \(L, U > 0\) at the lower and upper boundaries, respectively, and degrees of freedom, location and scale parameters \(\nu > 1\), \(\mu\) and \(\sigma > 0\). \(F_{l, L, \nu}^{u, U} = F_{l, L, \nu, 0, 1}^{u, U}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
df
|
ArrayLike
|
Degrees of freedom parameter of the forecast distribution. |
required |
location
|
ArrayLike
|
Location parameter of the forecast distribution. |
0.0
|
scale
|
ArrayLike
|
Scale parameter of the forecast distribution. |
1.0
|
lower
|
ArrayLike
|
Lower boundary of the truncated forecast distribution. |
float('-inf')
|
upper
|
ArrayLike
|
Upper boundary of the truncated forecast distribution. |
float('inf')
|
lmass
|
ArrayLike
|
Point mass assigned to the lower boundary of the forecast distribution. |
0.0
|
umass
|
ArrayLike
|
Point mass assigned to the upper boundary of the forecast distribution. |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between gtct(df, location, scale, lower, upper, lmass, umass) and obs. |
Examples:
scoringrules.crps_tt
crps_tt(
observation: ArrayLike,
df: ArrayLike,
/,
location: ArrayLike = 0.0,
scale: ArrayLike = 1.0,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the truncated t distribution.
It is based on the formulation for the generalised truncated and censored t distribution with lmass and umass set to zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
df
|
ArrayLike
|
Degrees of freedom parameter of the forecast distribution. |
required |
location
|
ArrayLike
|
Location parameter of the forecast distribution. |
0.0
|
scale
|
ArrayLike
|
Scale parameter of the forecast distribution. |
1.0
|
lower
|
ArrayLike
|
Lower boundary of the truncated forecast distribution. |
float('-inf')
|
upper
|
ArrayLike
|
Upper boundary of the truncated forecast distribution. |
float('inf')
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between tt(df, location, scale, lower, upper) and obs. |
Examples:
scoringrules.crps_ct
crps_ct(
observation: ArrayLike,
df: ArrayLike,
/,
location: ArrayLike = 0.0,
scale: ArrayLike = 1.0,
lower: ArrayLike = float("-inf"),
upper: ArrayLike = float("inf"),
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the censored t distribution.
It is based on the formulation for the generalised truncated and censored t distribution with lmass and umass set to the tail probabilities of the predictive distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
df
|
ArrayLike
|
Degrees of freedom parameter of the forecast distribution. |
required |
location
|
ArrayLike
|
Location parameter of the forecast distribution. |
0.0
|
scale
|
ArrayLike
|
Scale parameter of the forecast distribution. |
1.0
|
lower
|
ArrayLike
|
Lower boundary of the truncated forecast distribution. |
float('-inf')
|
upper
|
ArrayLike
|
Upper boundary of the truncated forecast distribution. |
float('inf')
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between ct(df, location, scale, lower, upper) and obs. |
Examples:
scoringrules.crps_hypergeometric
crps_hypergeometric(
observation: ArrayLike,
m: ArrayLike,
n: ArrayLike,
k: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the hypergeometric distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(f_{m, n, k}\) and \(F_{m, n, k}\) are the PDF and CDF of the hypergeometric distribution with population parameters \(m,n = 0, 1, 2, ...\) and size parameter \(k = 0, ..., m + n\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
m
|
ArrayLike
|
Number of success states in the population. |
required |
n
|
ArrayLike
|
Number of failure states in the population. |
required |
k
|
ArrayLike
|
Number of draws, without replacement. Must be in 0, 1, ..., m + n. |
required |
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between obs and Hypergeometric(m, n, k). |
Examples:
scoringrules.crps_laplace
crps_laplace(
observation: ArrayLike,
/,
location: ArrayLike = 0.0,
scale: ArrayLike = 1.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the laplace distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(\mu\) and \(\sigma > 0\) are the location and scale parameters of the Laplace distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
Observed values. |
required |
location
|
ArrayLike
|
Location parameter of the forecast laplace distribution. |
0.0
|
scale
|
ArrayLike
|
Scale parameter of the forecast laplace distribution. |
1.0
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between obs and Laplace(location, scale). |
>>> sr.crps_laplace(0.3, 0.1, 0.2)
|
|
|
0.12357588823428847
|
|
scoringrules.crps_logistic
crps_logistic(
observation: ArrayLike,
mu: ArrayLike,
sigma: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the logistic distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(F(\omega)\) is the CDF of the standard logistic distribution at the normalized prediction error \(\omega = \frac{y - \mu}{\sigma}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
Observed values. |
required | |
mu
|
ArrayLike
|
Location parameter of the forecast logistic distribution. |
required |
sigma
|
ArrayLike
|
Scale parameter of the forecast logistic distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS for the Logistic(mu, sigma) forecasts given the observations. |
Examples:
scoringrules.crps_loglaplace
crps_loglaplace(
observation: ArrayLike,
locationlog: ArrayLike,
scalelog: ArrayLike,
*,
backend: Backend = None
) -> ArrayLike
Compute the closed form of the CRPS for the log-Laplace distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(F_{\mu, \sigma}\) is the CDF of the log-laplace distribution with location parameter \(\mu\) and scale parameter \(\sigma \in (0, 1)\), and
if \(y < \exp{\mu}\), and
if \(y \ge \exp{\mu}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
Observed values. |
required |
locationlog
|
ArrayLike
|
Location parameter of the forecast log-laplace distribution. |
required |
scalelog
|
ArrayLike
|
Scale parameter of the forecast log-laplace distribution. |
required |
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between obs and Loglaplace(locationlog, scalelog). |
Examples:
scoringrules.crps_loglogistic
crps_loglogistic(
observation: ArrayLike,
mulog: ArrayLike,
sigmalog: ArrayLike,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the log-logistic distribution.
It is based on the following formulation from Jordan et al. (2019):
where \( F_{\mu,\sigma}(x) \) is the cumulative distribution function (CDF) of the log-logistic distribution, defined as:
\(B\) is the beta function, and \(I\) is the regularised incomplete beta function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
mulog
|
ArrayLike
|
Location parameter of the log-logistic distribution. |
required |
sigmalog
|
ArrayLike
|
Scale parameter of the log-logistic distribution. |
required |
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between obs and Loglogis(mulog, sigmalog). |
Examples:
scoringrules.crps_lognormal
crps_lognormal(
observation: ArrayLike,
mulog: ArrayLike,
sigmalog: ArrayLike,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the lognormal distribution.
It is based on the formulation introduced by Baran and Lerch (2015)
where \(\Phi\) is the CDF of the standard normal distribution and \(\omega = \frac{\mathrm{log}y - \mu}{\sigma}\).
Note that mean and standard deviation are not the values for the distribution itself, but of the underlying normal distribution it is derived from.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
mulog
|
ArrayLike
|
Mean of the normal underlying distribution. |
required |
sigmalog
|
ArrayLike
|
Standard deviation of the underlying normal distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
crps |
ArrayLike
|
The CRPS between Lognormal(mu, sigma) and obs. |
Examples:
scoringrules.crps_mixnorm
crps_mixnorm(
observation: ArrayLike,
m: ArrayLike,
s: ArrayLike,
/,
w: ArrayLike = None,
axis: ArrayLike = -1,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for a mixture of normal distributions.
It is based on the following formulation from Grimit et al. (2006):
where \(F(x) = \sum_{i=1}^{M} w_{i} \Phi \left( \frac{x - \mu_{i}}{\sigma_{i}} \right)\), and \(A(\mu, \sigma^{2}) = \mu (2 \Phi(\frac{\mu}{\sigma}) - 1) + 2\sigma \phi(\frac{\mu}{\sigma}).\)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
m
|
ArrayLike
|
Means of the component normal distributions. |
required |
s
|
ArrayLike
|
Standard deviations of the component normal distributions. |
required |
w
|
ArrayLike
|
Non-negative weights assigned to each component. |
None
|
axis
|
ArrayLike
|
The axis corresponding to the mixture components. Default is the last axis. |
-1
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
score |
ArrayLike
|
The CRPS between MixNormal(m, s) and obs. |
Examples:
scoringrules.crps_negbinom
crps_negbinom(
observation: ArrayLike,
n: ArrayLike,
/,
prob: ArrayLike | None = None,
*,
mu: ArrayLike | None = None,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the negative binomial distribution.
It is based on the following formulation from Wei and Held (2014):
where \(F_{n, p}\) is the CDF of the negative binomial distribution with size parameter \(n > 0\) and probability parameter \(p \in (0, 1]\). The mean of the negative binomial distribution is \(\mu = n (1 - p)/p\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
n
|
ArrayLike
|
Size parameter of the forecast negative binomial distribution. |
required |
prob
|
ArrayLike | None
|
Probability parameter of the forecast negative binomial distribution. |
None
|
mu
|
ArrayLike | None
|
Mean of the forecast negative binomial distribution. |
None
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between NegBinomial(n, prob) and obs. |
Examples:
Raises:
Type | Description |
---|---|
ValueError
|
If both |
scoringrules.crps_normal
crps_normal(
observation: ArrayLike,
mu: ArrayLike,
sigma: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the normal distribution.
It is based on the following formulation from Geiting et al. (2005):
where \(\Phi(ω)\) and \(\phi(ω)\) are respectively the CDF and PDF of the standard normal distribution at the normalized prediction error \(\omega = \frac{y - \mu}{\sigma}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
The observed values. |
required | |
mu
|
ArrayLike
|
Mean of the forecast normal distribution. |
required |
sigma
|
ArrayLike
|
Standard deviation of the forecast normal distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between Normal(mu, sigma) and obs. |
Examples:
scoringrules.crps_2pnormal
crps_2pnormal(
observation: ArrayLike,
scale1: ArrayLike,
scale2: ArrayLike,
location: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the two-piece normal distribution.
It is based on the following relationship given in Jordan et al. (2019):
where \(F_{\sigma_{1}, \sigma_{2}, \mu}\) is the two-piece normal distribution with scale1 and scale2 parameters \(\sigma_{1}, \sigma_{2} > 0\) and location parameter \(\mu\), and \(F_{l, L}^{u, U}\) is the CDF of the generalised truncated and censored normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
The observed values. |
required | |
scale1
|
ArrayLike
|
Scale parameter of the lower half of the forecast two-piece normal distribution. |
required |
scale2
|
ArrayLike
|
Scale parameter of the upper half of the forecast two-piece normal distribution. |
required |
mu
|
Location parameter of the forecast two-piece normal distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between 2pNormal(scale1, scale2, mu) and obs. |
Examples:
scoringrules.crps_poisson
crps_poisson(
observation: ArrayLike,
mean: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the Poisson distribution.
It is based on the following formulation from Wei and Held (2014):
where \(F_{\lambda}\) is Poisson distribution function with mean parameter \(\lambda > 0\), and \(I_{0}\) and \(I_{1}\) are modified Bessel functions of the first kind.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
mean
|
ArrayLike
|
Mean parameter of the forecast poisson distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between Pois(mean) and obs. |
Examples:
scoringrules.crps_t
crps_t(
observation: ArrayLike,
df: ArrayLike,
/,
location: ArrayLike = 0.0,
scale: ArrayLike = 1.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the student's t distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(\omega = (y - \mu)/\sigma\), where \(\nu > 1, \mu\), and \(\sigma > 0\) are the degrees of freedom, location, and scale parameters respectively of the Student's t distribution, and \(f_{\nu}\) and \(F_{\nu}\) are the PDF and CDF of the standard Student's t distribution with \(\nu\) degrees of freedom.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
df
|
ArrayLike
|
Degrees of freedom parameter of the forecast t distribution. |
required |
location
|
ArrayLike
|
Location parameter of the forecast t distribution. |
0.0
|
sigma
|
Scale parameter of the forecast t distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between t(df, location, scale) and obs. |
Examples:
scoringrules.crps_uniform
crps_uniform(
observation: ArrayLike,
min: ArrayLike,
max: ArrayLike,
/,
lmass: ArrayLike = 0.0,
umass: ArrayLike = 0.0,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the uniform distribution.
It is based on the following formulation from Jordan et al. (2019):
where \(\mathcal{U}_{L}^{U}(l, u)\) is the uniform distribution with lower bound \(l\), upper bound \(u > l\), point mass \(L\) on the lower bound, and point mass \(U\) on the upper bound. We must have that \(L, U \ge 0, L + U < 1\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observation
|
ArrayLike
|
The observed values. |
required |
min
|
ArrayLike
|
Lower bound of the forecast uniform distribution. |
required |
max
|
ArrayLike
|
Upper bound of the forecast uniform distribution. |
required |
lmass
|
ArrayLike
|
Point mass on the lower bound of the forecast uniform distribution. |
0.0
|
umass
|
ArrayLike
|
Point mass on the upper bound of the forecast uniform distribution. |
0.0
|
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between U(min, max, lmass, umass) and obs. |
Examples:
scoringrules.crps_normal
crps_normal(
observation: ArrayLike,
mu: ArrayLike,
sigma: ArrayLike,
/,
*,
backend: Backend = None,
) -> ArrayLike
Compute the closed form of the CRPS for the normal distribution.
It is based on the following formulation from Geiting et al. (2005):
where \(\Phi(ω)\) and \(\phi(ω)\) are respectively the CDF and PDF of the standard normal distribution at the normalized prediction error \(\omega = \frac{y - \mu}{\sigma}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
The observed values. |
required | |
mu
|
ArrayLike
|
Mean of the forecast normal distribution. |
required |
sigma
|
ArrayLike
|
Standard deviation of the forecast normal distribution. |
required |
Returns:
Name | Type | Description |
---|---|---|
crps |
array_like
|
The CRPS between Normal(mu, sigma) and obs. |
Examples:
Ensemble-based estimators
scoringrules.crps_ensemble
crps_ensemble(
observations: ArrayLike,
forecasts: Array,
/,
axis: int = -1,
*,
sorted_ensemble: bool = False,
estimator: str = "pwm",
backend: Backend = None,
) -> Array
Estimate the Continuous Ranked Probability Score (CRPS) for a finite ensemble.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
ArrayLike
|
The observed values. |
required |
forecasts
|
Array
|
The predicted forecast ensemble, where the ensemble dimension is by default represented by the last axis. |
required |
axis
|
int
|
The axis corresponding to the ensemble. Default is the last axis. |
-1
|
sorted_ensemble
|
bool
|
Boolean indicating whether the ensemble members are already in ascending order. Default is False. |
False
|
estimator
|
str
|
Indicates the CRPS estimator to be used. |
'pwm'
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
crps |
ArrayLike
|
The CRPS between the forecast ensemble and obs. |
Examples:
scoringrules.twcrps_ensemble
twcrps_ensemble(
observations: ArrayLike,
forecasts: Array,
v_func: tp.Callable[[ArrayLike], ArrayLike],
/,
axis: int = -1,
*,
estimator: str = "pwm",
sorted_ensemble: bool = False,
backend: Backend = None,
) -> Array
Estimate the Threshold-Weighted Continuous Ranked Probability Score (twCRPS) for a finite ensemble.
Computation is performed using the ensemble representation of the twCRPS in Allen et al. (2022):
where \(F_{ens}(x) = \sum_{m=1}^{M} 1 \{ x_{m} \leq x \}/M\) is the empirical distribution function associated with an ensemble forecast \(x_{1}, \dots, x_{M}\) with \(M\) members, and \(v\) is the chaining function used to target particular outcomes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
ArrayLike
|
The observed values. |
required |
forecasts
|
Array
|
The predicted forecast ensemble, where the ensemble dimension is by default represented by the last axis. |
required |
v_func
|
Callable[[ArrayLike], ArrayLike]
|
Chaining function used to emphasise particular outcomes. For example, a function that only considers values above a certain threshold \(t\) by projecting forecasts and observations to \([t, \inf)\). |
required |
axis
|
int
|
The axis corresponding to the ensemble. Default is the last axis. |
-1
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
twcrps |
ArrayLike
|
The twCRPS between the forecast ensemble and obs for the chosen chaining function. |
Examples:
scoringrules.owcrps_ensemble
owcrps_ensemble(
observations: ArrayLike,
forecasts: Array,
w_func: tp.Callable[[ArrayLike], ArrayLike],
/,
axis: int = -1,
*,
estimator: tp.Literal["nrg"] = "nrg",
backend: Backend = None,
) -> Array
Estimate the Outcome-Weighted Continuous Ranked Probability Score (owCRPS) for a finite ensemble.
Computation is performed using the ensemble representation of the owCRPS in Allen et al. (2022):
where \(F_{ens}(x) = \sum_{m=1}^{M} 1\{ x_{m} \leq x \}/M\) is the empirical distribution function associated with an ensemble forecast \(x_{1}, \dots, x_{M}\) with \(M\) members, \(w\) is the chosen weight function, and \(\bar{w} = \sum_{m=1}^{M}w(x_{m})/M\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
ArrayLike
|
The observed values. |
required |
forecasts
|
Array
|
The predicted forecast ensemble, where the ensemble dimension is by default represented by the last axis. |
required |
w_func
|
Callable[[ArrayLike], ArrayLike]
|
Weight function used to emphasise particular outcomes. |
required |
axis
|
int
|
The axis corresponding to the ensemble. Default is the last axis. |
-1
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
owcrps |
ArrayLike
|
The owCRPS between the forecast ensemble and obs for the chosen weight function. |
Examples:
scoringrules.vrcrps_ensemble
vrcrps_ensemble(
observations: ArrayLike,
forecasts: Array,
w_func: tp.Callable[[ArrayLike], ArrayLike],
/,
axis: int = -1,
*,
estimator: tp.Literal["nrg"] = "nrg",
backend: Backend = None,
) -> Array
Estimate the Vertically Re-scaled Continuous Ranked Probability Score (vrCRPS) for a finite ensemble.
Computation is performed using the ensemble representation of the vrCRPS in Allen et al. (2022):
where \(F_{ens}(x) = \sum_{m=1}^{M} 1 \{ x_{m} \leq x \}/M\) is the empirical distribution function associated with an ensemble forecast \(x_{1}, \dots, x_{M}\) with \(M\) members, \(w\) is the chosen weight function, and \(\bar{w} = \sum_{m=1}^{M}w(x_{m})/M\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
ArrayLike
|
The observed values. |
required |
forecasts
|
Array
|
The predicted forecast ensemble, where the ensemble dimension is by default represented by the last axis. |
required |
w_func
|
Callable[[ArrayLike], ArrayLike]
|
Weight function used to emphasise particular outcomes. |
required |
axis
|
int
|
The axis corresponding to the ensemble. Default is the last axis. |
-1
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
vrcrps |
ArrayLike
|
The vrCRPS between the forecast ensemble and obs for the chosen weight function. |
Examples:
Quantile-based estimators
scoringrules.crps_quantile
crps_quantile(
observations: ArrayLike,
forecasts: Array,
alpha: Array,
/,
axis: int = -1,
*,
backend: Backend = None,
) -> Array
Approximate the CRPS from quantile predictions via the Pinball Loss.
It is based on the notation in Berrisch & Ziel, 2022
The CRPS can be approximated as the mean pinball loss for all quantile forecasts \(F_q\) with level \(q \in Q\):
where the pinball loss is defined as:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observations
|
ArrayLike
|
The observed values. |
required |
forecasts
|
Array
|
The predicted forecast ensemble, where the ensemble dimension is by default represented by the last axis. |
required |
alpha
|
Array
|
The percentile levels. We expect the quantile array to match the axis (see below) of the forecast array. |
required |
axis
|
int
|
The axis corresponding to the ensemble. Default is the last axis. |
-1
|
backend
|
Backend
|
The name of the backend used for computations. Defaults to 'numba' if available, else 'numpy'. |
None
|
Returns:
Name | Type | Description |
---|---|---|
qcrps |
Array
|
An array of CRPS scores for each forecast, which should be averaged to get meaningful values. |
Examples:
-
Michaël Zamo and Philippe Naveau. Estimation of the Continuous Ranked Probability Score with Limited Information and Applications to Ensemble Weather Forecasts. Mathematical Geosciences, 2018. URL: https://doi.org/10.1007/s11004-017-9709-7, doi:10.1007/s11004-017-9709-7. ↩
-
Alexander Jordan. Facets of forecast evaluation. PhD thesis, Karlsruher Institut für Technologie (KIT), 2016. doi:10.5445/IR/1000063629. ↩