scoringrules.twcrps_ensemble

scoringrules.twcrps_ensemble#

scoringrules.twcrps_ensemble(obs: ArrayLike, fct: Array, a: float = -inf, b: float = inf, m_axis: int = -1, *, ens_w: Array = None, v_func: Callable[[ArrayLike], ArrayLike] = None, estimator: str = 'qd', sorted_ensemble: bool = False, backend: Backend = None) Array#

Estimate the threshold-weighted CRPS (twCRPS) for a finite ensemble.

Computation is performed using the ensemble representation of the twCRPS in [1].

\[\mathrm{twCRPS}(F_{ens}, y) = \frac{1}{M} \sum_{m = 1}^{M} |v(x_{m}) - v(y)| - \frac{1}{2 M^{2}} \sum_{m = 1}^{M} \sum_{j = 1}^{M} |v(x_{m}) - v(x_{j})|,\]

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:
obsarray_like

The observed values.

fctarray_like

The predicted forecast ensemble, where the ensemble dimension is by default represented by the last axis.

afloat

The lower bound to be used in the default weight function that restricts attention to values in the range [a, b].

bfloat

The upper bound to be used in the default weight function that restricts attention to values in the range [a, b].

m_axisint

The axis corresponding to the ensemble. Default is the last axis.

ens_warray, shape (…, m)

Weights assigned to the ensemble members. Array with the same shape as fct. Default is equal weighting. Weights are normalised so that they sum to one across the ensemble members.

v_funccallable, array_like -> array_like

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)\).

estimatorstr

Indicates the CRPS estimator to be used.

sorted_ensemblebool

Boolean indicating whether the ensemble members are already in ascending order. Default is False.

backendstr, optional

The name of the backend used for computations. Defaults to numba if available, else numpy.

Returns:
twcrpsarray_like

The twCRPS between the forecast ensemble and obs for the chosen chaining function.

See also

crps_ensemble

Compute the CRPS for a finite ensemble.

Notes

Weighted scoring rules

Some theoretical background on weighted versions of scoring rules.

References

[1]

Allen, S., Ginsbourger, D., & Ziegel, J. (2023). Evaluating forecasts for high-impact events using transformed kernel scores. SIAM/ASA Journal on Uncertainty Quantification, 11(3), 906-940. Available at https://arxiv.org/abs/2202.12732.

Examples

>>> import numpy as np
>>> import scoringrules as sr
>>> rng = np.random.default_rng(123)
...
>>> def v_func(x):
...    return np.maximum(x, -1.0)
...
>>> obs = rng.normal(size=3)
>>> fct = rng.normal(size=(3, 10))
>>> sr.twcrps_ensemble(obs, fct, v_func=v_func)
array([0.69605316, 0.32865417, 0.39048665])