represented_interval_weights#
- openstef_beam.metrics.metrics_helpers.represented_interval_weights(quantiles: Sequence[Quantile]) ndarray[tuple[Any, ...], dtype[floating]][source]#
Calculate the probability interval each quantile represents on [0, 1].
Interval boundaries are placed at the midpoints between consecutive quantiles, with the outer edges fixed at 0 and 1. Each quantile is weighted by the width of its interval.
- Parameters:
quantiles (Sequence[Quantile]) – Quantile levels with shape (num_quantiles,). Must be sorted in ascending order and contain values in (0, 1).
- Returns:
The interval weights with shape (num_quantiles,). Weights are non-negative and sum to 1.
- Return type:
Example
Unevenly spaced quantiles get different weights
>>> import numpy as np >>> quantiles = np.array([0.05, 0.1, 0.5, 0.9, 0.95]) >>> represented_interval_weights(quantiles) array([0.075, 0.225, 0.4 , 0.225, 0.075])