MultivariateDistributionLoss#
- class pytorch_forecasting.metrics.base_metrics.MultivariateDistributionLoss(name: str | None = None, quantiles: List[float] = [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98], reduction='mean')[source]#
Bases:
DistributionLoss
Base class for multivariate distribution losses.
Class should be inherited for all multivariate distribution losses, i.e. if a batch of values is predicted in one go and the batch dimension is not independent, but the time dimension still remains independent.
Initialize metric
- Parameters:
name (str) – metric name. Defaults to class name.
quantiles (List[float], optional) – quantiles for probability range. Defaults to [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98].
reduction (str, optional) – Reduction, “none”, “mean” or “sqrt-mean”. Defaults to “mean”.
Methods
loss
(y_pred, y_actual)Calculate negative likelihood
sample
(y_pred, n_samples)Sample from distribution.
- loss(y_pred: Tensor, y_actual: Tensor) Tensor [source]#
Calculate negative likelihood
- Parameters:
y_pred – network output
y_actual – actual values
- Returns:
metric value on which backpropagation can be applied
- Return type:
torch.Tensor
- sample(y_pred, n_samples: int) Tensor [source]#
Sample from distribution.
- Parameters:
y_pred – prediction output of network (shape batch_size x n_timesteps x n_paramters)
n_samples (int) – number of samples to draw
- Returns:
tensor with samples (shape batch_size x n_timesteps x n_samples)
- Return type:
torch.Tensor