pytorch_forecasting.metrics.
DistributionLoss
Bases: pytorch_forecasting.metrics.MultiHorizonMetric
pytorch_forecasting.metrics.MultiHorizonMetric
DistributionLoss base class.
Class should be inherited for all distribution losses, i.e. if a network predicts the parameters of a probability distribution, DistributionLoss can be used to score those parameters and calculate loss for given true values.
Define two class attributes in a child class:
distribution_class
torch probability distribution
distributions.Distribution
distribution_arguments
list of parameter names for the distribution
List[str]
Further, implement the methods map_x_to_distribution() and rescale_parameters().
map_x_to_distribution()
rescale_parameters()
Initialize metric
name (str) – metric name. Defaults to class name.
quantiles (List[float], optional) – quantiles for probability range. Defaults to None.
reduction (str, optional) – Reduction, “none”, “mean” or “sqrt-mean”. Defaults to “mean”.
Methods
loss(y_pred, y_actual)
loss
Calculate negative likelihood
map_x_to_distribution(x)
map_x_to_distribution
Map the a tensor of parameters to a probability distribution.
rescale_parameters(parameters, target_scale, …)
rescale_parameters
Rescale normalized parameters into the scale required for the distribution.
sample_n(y_pred, n_samples)
sample_n
Sample from distribution.
to_prediction(y_pred)
to_prediction
Convert network prediction into a point prediction.
to_quantiles(y_pred)
to_quantiles
Convert network prediction into a quantile prediction.
y_pred – network output
y_actual – actual values
metric value on which backpropagation can be applied
torch.Tensor
x (torch.Tensor) – parameters for probability distribution. Last dimension will index the parameters
class attribute distribution_class
[extended_summary]
parameters (torch.Tensor) – normalized parameters (indexed by last dimension)
target_scale (torch.Tensor) – scale of parameters (n_batch_samples x (center, scale))
transformer (BaseEstimator) – original transformer that normalized the target in the first place
parameters in real/not normalized space
y_pred – prediction output of network
n_samples (int) – number of samples to draw
tensor where first dimensionare samples
y_pred – prediction output of network (with output_type = samples)
output_type = samples
mean prediction
prediction quantiles (last dimension)