IntervalCoverage#
- class torch_uncertainty.metrics.regression.IntervalCoverage(**kwargs)[source]#
Prediction Interval Coverage Probability (PICP).
Given predicted lower and upper bounds \(\hat{l}_i\) and \(\hat{u}_i\) of a central prediction interval, PICP is the empirical fraction of targets that fall inside the interval:
\[\text{PICP} = \frac{1}{N} \sum_{i=1}^{N} \mathbf{1}\!\left[ \hat{l}_i \le y_i \le \hat{u}_i \right].\]A well-calibrated interval built for a nominal coverage \(1 - \alpha\) should yield \(\text{PICP} \approx 1 - \alpha\). Coverage is gameable on its own — an arbitrarily wide interval reaches \(\text{PICP} = 1\) — so it should always be reported together with an interval-width metric such as
MeanIntervalWidthor a proper interval score such asIntervalScore.- Parameters:
kwargs (
Any) – Additional keyword arguments, see Advanced metric settings.
Note
Inputs of any shape are accepted and flattened, so the metric returns the coverage rate over all elements (e.g. batch and output dimensions pooled together).
Example:
import torch from torch_uncertainty.metrics.regression import IntervalCoverage lower = torch.tensor([0.0, 1.0, 2.0, 3.0]) upper = torch.tensor([2.0, 3.0, 4.0, 5.0]) target = torch.tensor([1.0, 5.0, 3.0, 4.0]) # 3 of 4 inside metric = IntervalCoverage() metric.update(lower, upper, target) print(metric.compute()) # tensor(0.7500)