rcrps#

openstef_beam.metrics.rcrps(y_true: ndarray[tuple[Any, ...], dtype[floating]], y_pred: ndarray[tuple[Any, ...], dtype[floating]], quantiles: ndarray[tuple[Any, ...], dtype[floating]], lower_quantile: float = 0.05, upper_quantile: float = 0.95, sample_weights: ndarray[tuple[Any, ...], dtype[floating]] | None = None) float[source]#

Calculate the relative Continuous Ranked Probability Score (rCRPS).

The rCRPS normalizes the CRPS by the range of observed values, making it scale-invariant and suitable for comparing forecast quality across different datasets or time periods with varying magnitudes.

Parameters:
  • y_true (ndarray[tuple[Any, ...], dtype[floating]]) – Observed values with shape (num_samples,).

  • y_pred (ndarray[tuple[Any, ...], dtype[floating]]) – Predicted quantiles with shape (num_samples, num_quantiles).

  • quantiles (ndarray[tuple[Any, ...], dtype[floating]]) – Quantile levels with shape (num_quantiles,). Must be sorted in ascending order and contain values in [0, 1].

  • lower_quantile (float) – Lower quantile for range calculation. Must be in [0, 1].

  • upper_quantile (float) – Upper quantile for range calculation. Must be in [0, 1] and greater than lower_quantile.

  • sample_weights (ndarray[tuple[Any, ...], dtype[floating]] | None) – Optional weights for each sample with shape (num_samples,).

Returns:

The relative CRPS as a float. Returns NaN if the range between quantiles is zero.

Return type:

float

Example

Compare forecast quality across different scales:

>>> import numpy as np
>>> # High load period
>>> y_true_high = np.array([1000, 1200, 1100])
>>> quantiles = np.array([0.1, 0.5, 0.9])
>>> y_pred_high = np.array([[950, 1000, 1050],
...                         [1150, 1200, 1250],
...                         [1050, 1100, 1150]])
>>> rcrps_high = rcrps(y_true_high, y_pred_high, quantiles)
>>> isinstance(rcrps_high, float)
True

Note

rCRPS allows fair comparison of forecast quality between periods with different load levels, such as summer vs. winter energy demand.

Parameters:
  • y_true (ndarray[tuple[Any, ...], dtype[floating]])

  • y_pred (ndarray[tuple[Any, ...], dtype[floating]])

  • quantiles (ndarray[tuple[Any, ...], dtype[floating]])

  • lower_quantile (float)

  • upper_quantile (float)

  • sample_weights (ndarray[tuple[Any, ...], dtype[floating]] | None)

Return type:

float