ThresholdAccuracy#

class torch_uncertainty.metrics.regression.ThresholdAccuracy(power, lmbda=1.25, **kwargs)[source]#

Compute the Threshold Accuracy metric, also referred to as \(\delta_1\), \(\delta_2\), or \(\delta_3\).

This metric is standard in monocular depth estimation. It reports the fraction of pixels (or samples) whose prediction \(\hat{y}_i\) and target \(y_i\) agree up to a multiplicative factor \(\lambda^k\):

\[\delta_k = \frac{1}{N} \sum_{i=1}^{N} \mathbf{1}\!\left[ \max\!\left(\frac{\hat{y}_i}{y_i}, \frac{y_i}{\hat{y}_i}\right) < \lambda^k \right],\]

where \(\lambda = 1.25\) by default and \(k\) is the power argument. Higher values are better.

Parameters:
  • power (int) – The power to raise the threshold to. Often in [1, 2, 3].

  • lmbda (float) – The threshold to compare the max of ratio of predictions to targets and its inverse to. Defaults to 1.25.

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

Example:

from torch_uncertainty.metrics.regression import ThresholdAccuracy
import torch

# Initialize the metric with power=2 and lambda=1.25
threshold_accuracy = ThresholdAccuracy(power=2, lmbda=1.25)

# Example predictions and targets
preds = torch.tensor([2.0, 3.0, 5.0, 8.0, 20.0])
target = torch.tensor([2.1, 2.5, 4.5, 10.0, 10.0])

# Update the metric state
threshold_accuracy.update(preds, target)

# Compute the Threshold Accuracy
result = threshold_accuracy.compute()
print(f"Threshold Accuracy: {result.item():.2f}")
# Output: Threshold Accuracy: 0.80
compute()[source]#

Compute the Threshold Accuracy.

Return type:

Tensor

update(preds, target)[source]#

Update state with predictions and targets.

Return type:

None