NegativeBinomialDistributionLoss

class pytorch_forecasting.metrics.NegativeBinomialDistributionLoss(name: Optional[str] = None, quantiles: List[float] = [0.02, 0.1, 0.25, 0.5, 0.75, 0.9, 0.98], reduction='mean')[source]

Bases: pytorch_forecasting.metrics.DistributionLoss

Negative binomial loss, e.g. for count data.

Requirements for original target normalizer:
  • not centered normalization (only rescaled)

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

map_x_to_distribution(x)

Map the a tensor of parameters to a probability distribution.

rescale_parameters(parameters, target_scale, ...)

Rescale normalized parameters into the scale required for the output.

to_prediction(y_pred)

Convert network prediction into a point prediction.

distribution_class

alias of torch.distributions.negative_binomial.NegativeBinomial

map_x_to_distribution(x: torch.Tensor) torch.distributions.negative_binomial.NegativeBinomial[source]

Map the a tensor of parameters to a probability distribution.

Parameters

x (torch.Tensor) – parameters for probability distribution. Last dimension will index the parameters

Returns

torch probability distribution as defined in the

class attribute distribution_class

Return type

distributions.Distribution

rescale_parameters(parameters: torch.Tensor, target_scale: torch.Tensor, encoder: sklearn.base.BaseEstimator) torch.Tensor[source]

Rescale normalized parameters into the scale required for the output.

Parameters
  • parameters (torch.Tensor) – normalized parameters (indexed by last dimension)

  • target_scale (torch.Tensor) – scale of parameters (n_batch_samples x (center, scale))

  • encoder (BaseEstimator) – original encoder that normalized the target in the first place

Returns

parameters in real/not normalized space

Return type

torch.Tensor

to_prediction(y_pred: torch.Tensor) torch.Tensor[source]

Convert network prediction into a point prediction. In the case of this distribution prediction we need to derive the mean (as a point prediction) from the distribution parameters

Parameters
  • y_pred – prediction output of network

  • binomial (in this case the two parameters for the negative) –

Returns

mean prediction

Return type

torch.Tensor