MeanGTRelativeSquaredError#
- class torch_uncertainty.metrics.regression.MeanGTRelativeSquaredError(squared=True, num_outputs=1, **kwargs)[source]#
Compute mean squared error relative to the Ground Truth (MSErel or SRE).
This metric is useful for evaluating the relative squared error between predictions and targets, particularly in regression tasks where relative accuracy is critical.
\[\text{MSErel} = \frac{1}{N}\sum_i^N \frac{(y_i - \hat{y_i})^2}{y_i}\]Where \(y\) is a tensor of target values, and \(\hat{y}\) is a tensor of predictions.
As input to
forward
andupdate
the metric accepts the following input:preds (
Tensor
): Predictions from modeltarget (
Tensor
): Ground truth values
As output of
forward
andcompute
the metric returns the following output:rel_mean_squared_error (
Tensor
): A tensor with the relative mean squared error
- Parameters:
squared – If True returns MSErel value, if False returns RMSErel value.
num_outputs – Number of outputs in multioutput setting
kwargs – Additional keyword arguments, see Advanced metric settings.
Example:
from torch_uncertainty.metrics.regression import MeanGTRelativeSquaredError import torch # Initialize the metric mse_rel_metric = MeanGTRelativeSquaredError(squared=True) # Example predictions and targets preds = torch.tensor([2.5, 1.0, 2.0, 8.0]) target = torch.tensor([3.0, 1.5, 2.0, 7.0]) # Update the metric state mse_rel_metric.update(preds, target) # Compute the Relative Mean Squared Error result = mse_rel_metric.compute() print(f"Relative Mean Squared Error: {result.item()}") # Output: 0.09821434319019318
See also