MeanIntervalWidth#

class torch_uncertainty.metrics.regression.MeanIntervalWidth(**kwargs)[source]#

Mean Prediction Interval Width (MPIW), a.k.a. sharpness.

The mean width of the predicted central prediction intervals:

\[\text{MPIW} = \frac{1}{N} \sum_{i=1}^{N} \left( \hat{u}_i - \hat{l}_i \right).\]

MPIW measures the sharpness of the intervals. It is only meaningful jointly with a coverage metric such as IntervalCoverage: narrower is better at equal coverage, since width can be reduced trivially by sacrificing coverage.

Parameters:

kwargs (Any) – Additional keyword arguments, see Advanced metric settings.

Note

Inputs of any shape are accepted and flattened, so the metric returns the mean width over all elements.

Example:

import torch
from torch_uncertainty.metrics.regression import MeanIntervalWidth

lower = torch.tensor([0.0, 1.0, 2.0])
upper = torch.tensor([2.0, 3.0, 5.0])  # widths 2, 2, 3

metric = MeanIntervalWidth()
metric.update(lower, upper)
print(metric.compute())
# tensor(2.3333)
compute()[source]#

Compute the mean interval width.

Return type:

Tensor

update(lower, upper)[source]#

Update state with a batch of interval bounds.

Parameters:
  • lower (Tensor) – The predicted lower bounds of the interval.

  • upper (Tensor) – The predicted upper bounds of the interval.

Return type:

None