SetSize#

class torch_uncertainty.metrics.classification.SetSize(reduction='mean', **kwargs)[source]#

Average prediction-set size — the standard efficiency metric for conformal prediction methods.

For a set-valued predictor \(\mathcal{C}(X) \subseteq \{1, \dots, C\}\),

\[\text{SetSize} = \frac{1}{N} \sum_{i=1}^{N} |\mathcal{C}(x_i)|.\]

Smaller sets are more informative, hence higher_is_better = False. Set size is typically reported jointly with the empirical CoverageRate: a useful conformal predictor achieves the target coverage with as small a set as possible.

Parameters:
  • reduction (Optional[Literal['mean', 'sum', 'none']]) –

    Determines how to reduce over the \(B\)/batch dimension:

    • 'mean' [default]: Averages score across samples

    • 'sum': Sum score across samples

    • 'none' or None: Returns score per sample

  • kwargs – Additional keyword arguments, see Advanced metric settings.

compute()[source]#

Compute the set size.

Returns:

The set size according to the selected reduction.

Return type:

Tensor

update(preds, targets=None)[source]#

Update the metric state with predictions and targets.

Parameters:
  • preds (Tensor) – Predicted sets tensor of shape (B, C), where B is the batch size and C is the number of classes.

  • targets (Tensor | None) – Unused. Kept for API consistency. Defaults to None.

Return type:

None