module neuralforecast.losses.pytorch
function level_to_outputs
function quantiles_to_outputs
function weighted_average
nan * 0 = nan you will get 0 * 0 = 0.
Args:
x(torch.Tensor): Input tensor, of which the average must be computed.weights(Optional[torch.Tensor], optional): Weights tensor, of the same shape asx. Defaults to None.dim(optional): The dim along which to averagex. Defaults to None.
torch.Tensor: The tensor with values averaged along the specifieddim.
function bernoulli_scale_decouple
loc, scale. Also adds Bernoulli domain protection to the distribution parameters.
Args:
output: Model output tensor.loc(optional): Location parameter. Defaults to None.scale(optional): Scale parameter. Defaults to None.
tuple: Processed probabilities.
function student_scale_decouple
loc, scale. Also adds StudentT domain protection to the distribution parameters.
Args:
output: Model output tensor.loc(optional): Location parameter. Defaults to None.scale(optional): Scale parameter. Defaults to None.eps(float, optional): Epsilon value for numerical stability. Defaults to 0.1.
tuple: Processed degrees of freedom, mean, and scale parameters.
function normal_scale_decouple
loc, scale. Also adds Normal domain protection to the distribution parameters.
Args:
output: Model output tensor.loc(optional): Location parameter. Defaults to None.scale(optional): Scale parameter. Defaults to None.eps(float, optional): Epsilon value for numerical stability. Defaults to 0.2.
tuple: Processed mean and standard deviation parameters.
function poisson_scale_decouple
loc, scale. Also adds Poisson domain protection to the distribution parameters.
function nbinomial_scale_decouple
loc, scale. Also adds Negative Binomial domain protection to the distribution parameters.
function est_lambda
function est_alpha
function est_beta
function tweedie_domain_map
function tweedie_scale_decouple
loc, scale. Also adds Tweedie domain protection to the distribution parameters.
function isqf_domain_map
distr_args length.
Args:
input(torch.Tensor): Tensor of dimensions [B, H, N * n_outputs].tol(float, optional): Tolerance. Defaults to 1e-4.quantiles(torch.Tensor, optional): Quantiles used for ISQF (i.e. x-positions for the knots). Defaults to torch.tensor([0.1, 0.5, 0.9], dtype=torch.float32).num_pieces(int, optional): Number of pieces used for each quantile spline. Defaults to 5.
tuple: Tuple with tensors of ISQF distribution arguments.
function isqf_scale_decouple
class BasePointLoss
Base class for point loss functions.
Args:
horizon_weight(Optional[torch.Tensor]): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.outputsize_multiplier(Optional[int]): Multiplier for the output size. Defaults to None.output_names(Optional[List[str]]): Names of the outputs. Defaults to None.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class MAE
Mean Absolute Error.
Calculates Mean Absolute Error between y and y_hat. MAE measures the relative prediction accuracy of a forecasting method by calculating the deviation of the prediction and the true value at a given time and averages these devations over the length of the series.
Args:
horizon_weight(Optional[torch.Tensor]): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class MSE
Mean Squared Error.
Calculates Mean Squared Error between y and y_hat. MSE measures the relative prediction accuracy of a forecasting method by calculating the squared deviation of the prediction and the true value at a given time, and averages these devations over the length of the series.
Args:
horizon_weight(Optional[torch.Tensor]): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class RMSE
Root Mean Squared Error.
Calculates Root Mean Squared Error between y and y_hat. RMSE measures the relative prediction accuracy of a forecasting method by calculating the squared deviation of the prediction and the observed value at a given time and averages these devations over the length of the series. Finally the RMSE will be in the same scale as the original time series so its comparison with other series is possible only if they share a common scale. RMSE has a direct connection to the L2 norm.
Args:
horizon_weight(Optional[torch.Tensor]): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class MAPE
Mean Absolute Percentage Error
Calculates Mean Absolute Percentage Error between y and y_hat. MAPE measures the relative prediction accuracy of a forecasting method by calculating the percentual deviation of the prediction and the observed value at a given time and averages these devations over the length of the series. The closer to zero an observed value is, the higher penalty MAPE loss assigns to the corresponding error.
Args:
horizon_weight: Tensor of size h, weight for each timestamp of the forecasting window.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class SMAPE
Symmetric Mean Absolute Percentage Error
Calculates Symmetric Mean Absolute Percentage Error between y and y_hat. SMAPE measures the relative prediction accuracy of a forecasting method by calculating the relative deviation of the prediction and the observed value scaled by the sum of the absolute values for the prediction and observed value at a given time, then averages these devations over the length of the series. This allows the SMAPE to have bounds between 0% and 200% which is desireble compared to normal MAPE that may be undetermined when the target is zero.
Args:
horizon_weight: Tensor of size h, weight for each timestamp of the forecasting window.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class MASE
Mean Absolute Scaled Error Calculates the Mean Absolute Scaled Error between y and y_hat. MASE measures the relative prediction accuracy of a forecasting method by comparinng the mean absolute errors of the prediction and the observed value against the mean absolute errors of the seasonal naive model. The MASE partially composed the Overall Weighted Average (OWA), used in the M4 Competition.
Args:
seasonality: Int. Main frequency of the time series; Hourly 24, Daily 7, Weekly 52, Monthly 12, Quarterly 4, Yearly 1.horizon_weight: Tensor of size h, weight for each timestamp of the forecasting window.
[Rob J. Hyndman, & Koehler, A. B. "Another look at measures of forecast accuracy".](https: //www.sciencedirect.com/science/article/pii/S0169207006000239)[Spyros Makridakis, Evangelos Spiliotis, Vassilios Assimakopoulos, "The M4 Competition: 100,000 time series and 61 forecasting methods”.](https://www.sciencedirect.com/science/article/pii/S0169207019301128)
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class relMSE
Relative Mean Squared Error Computes Relative Mean Squared Error (relMSE), as proposed by Hyndman & Koehler (2006) as an alternative to percentage errors, to avoid measure unstability.
Args:
y_train: Numpy array, deprecated.horizon_weight: Tensor of size h, weight for each timestamp of the forecasting window.
- Hyndman, R. J and Koehler, A. B. (2006). “Another look at measures of forecast accuracy”, International Journal of Forecasting, Volume 22, Issue 4.
- Kin G. Olivares, O. Nganba Meetei, Ruijun Ma, Rohan Reddy, Mengfei Cao, Lee Dicker. “Probabilistic Hierarchical Forecasting with Deep Poisson Mixtures. Submitted to the International Journal Forecasting, Working paper available at arxiv.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class QuantileLoss
Quantile Loss.
Computes the quantile loss between y and y_hat. QL measures the deviation of a quantile forecast. By weighting the absolute deviation in a non symmetric way, the loss pays more attention to under or over estimation. A common value for q is 0.5 for the deviation from the median (Pinball loss).
Args:
q(float): Between 0 and 1. The slope of the quantile loss, in the context of quantile regression, the q determines the conditional quantile level.horizon_weight(Optional[torch.Tensor]): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
[Roger Koenker and Gilbert Bassett, Jr., "Regression Quantiles".](https: //www.jstor.org/stable/1913643)
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class MQLoss
Multi-Quantile loss
Calculates the Multi-Quantile loss (MQL) between y and y_hat. MQL calculates the average multi-quantile Loss for a given set of quantiles, based on the absolute difference between predicted quantiles and observed values.
The limit behavior of MQL allows to measure the accuracy of a full predictive distribution with the continuous ranked probability score (CRPS). This can be achieved through a numerical integration technique, that discretizes the quantiles and treats the CRPS integral with a left Riemann approximation, averaging over uniformly distanced quantiles.
Args:
level(List[int], optional): Probability levels for prediction intervals. Defaults to [80, 90].quantiles(Optional[List[float]]): Alternative to level, quantiles to estimate from y distribution. Defaults to None.horizon_weight(Optional[torch.Tensor]): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
[Roger Koenker and Gilbert Bassett, Jr., "Regression Quantiles".](https: //www.jstor.org/stable/1913643)[James E. Matheson and Robert L. Winkler, "Scoring Rules for Continuous Probability Distributions".](https: //www.jstor.org/stable/2629907)
method __init__
method domain_map
y_hat(torch.Tensor): Input tensor.- Univariate: [B, H, 1 * Q]
- Multivariate: [B, H, N * Q]
torch.Tensor: Reshaped tensor with shape [B, H, N, Q].
class QuantileLayer
Implicit Quantile Layer from the paper IQN for Distributional Reinforcement Learning.
Code from GluonTS: https://github.com/awslabs/gluonts/blob/61133ef6e2d88177b32ace4afc6843ab9a7bc8cd/src/gluonts/torch/distributions/implicit_quantile_network.py
References: Dabney et al. 2018. https://arxiv.org/abs/1806.06923
method __init__
method forward
class IQLoss
Implicit Quantile Loss.
Computes the quantile loss between y and y_hat, with the quantile q provided as an input to the network. IQL measures the deviation of a quantile forecast. By weighting the absolute deviation in a non symmetric way, the loss pays more attention to under or over estimation.
Args:
cos_embedding_dim(int, optional): Cosine embedding dimension. Defaults to 64.concentration0(float, optional): Beta distribution concentration parameter. Defaults to 1.0.concentration1(float, optional): Beta distribution concentration parameter. Defaults to 1.0.horizon_weight(Optional[torch.Tensor]): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
Gouttes, Adèle, Kashif Rasul, Mateusz Koren, Johannes Stephan, and Tofigh Naghibi, "Probabilistic Time Series Forecasting with Implicit Quantile Networks". http: //arxiv.org/abs/2107.03743
method __init__
method domain_map
y_hat(torch.Tensor): Input tensor.- Univariate: [B, h, 1]
- Multivariate: [B, h, N]
torch.Tensor: Domain mapped tensor.
method update_quantile
class Tweedie
Tweedie Distribution.
The Tweedie distribution is a compound probability, special case of exponential dispersion models EDMs defined by its mean-variance relationship. The distribution particularly useful to model sparse series as the probability has possitive mass at zero but otherwise is continuous.
Cases of the variance relationship include Normal (rho = 0), Poisson (rho = 1), Gamma (rho = 2), inverse Gaussian (rho = 3).
Args:
log_mu(torch.Tensor): Tensor with log of means.rho(float): Tweedie variance power (1,2). Fixed across all observations.validate_args(optional): Validation arguments. Defaults to None.
sigma2: Tweedie variance. Currently fixed in 1. References: - Tweedie, M. C. K. (1984). An index which distinguishes between some important exponential families. Statistics: Applications and New Directions. Proceedings of the Indian Statistical Institute Golden Jubilee International Conference (Eds. J. K. Ghosh and J. Roy), pp. 579-604. Calcutta: Indian Statistical Institute. - Jorgensen, B. (1987). Exponential Dispersion Models. Journal of the Royal Statistical Society. Series B (Methodological), 49(2), 127–162. http://www.jstor.org/stable/2345415
method __init__
property batch_shape
Returns the shape over which parameters are batched.property event_shape
Returns the shape of a single sample (without batching).property mean
property mode
Returns the mode of the distribution.property stddev
Returns the standard deviation of the distribution.property variance
method log_prob
method sample
class ISQF
Distribution class for the Incremental (Spline) Quantile Function.
Args:
spline_knots(torch.Tensor): Tensor parametrizing the x-positions of the spline knots. Shape: (*batch_shape, (num_qk-1), num_pieces)spline_heights(torch.Tensor): Tensor parametrizing the y-positions of the spline knots. Shape: (*batch_shape, (num_qk-1), num_pieces)beta_l(torch.Tensor): Tensor containing the non-negative learnable parameter of the left tail. Shape: (*batch_shape,)beta_r(torch.Tensor): Tensor containing the non-negative learnable parameter of the right tail. Shape: (*batch_shape,)qk_y(torch.Tensor): Tensor containing the increasing y-positions of the quantile knots. Shape: (*batch_shape, num_qk)qk_x(torch.Tensor): Tensor containing the increasing x-positions of the quantile knots. Shape: (*batch_shape, num_qk)loc(torch.Tensor): Tensor containing the location in case of a transformed random variable. Shape: (*batch_shape,)scale(torch.Tensor): Tensor containing the scale in case of a transformed random variable. Shape: (*batch_shape,)
Park, Youngsuk, Danielle Maddix, François-Xavier Aubet, Kelvin Kan, Jan Gasthaus, and Yuyang Wang (2022). "Learning Quantile Functions without Quantile Crossing for Distribution-free Time Series Forecasting". https: //proceedings.mlr.press/v151/park22a.html
method __init__
property batch_shape
Returns the shape over which parameters are batched.property event_shape
Returns the shape of a single sample (without batching).property has_rsample
property mean
Function used to compute the empirical meanproperty mode
Returns the mode of the distribution.property stddev
Returns the standard deviation of the distribution.property variance
Returns the variance of the distribution.method crps
class BaseISQF
Base distribution class for the Incremental (Spline) Quantile Function.
Args:
spline_knots(torch.Tensor): Tensor parametrizing the x-positions of the spline knots. Shape: (*batch_shape, (num_qk-1), num_pieces)spline_heights(torch.Tensor): Tensor parametrizing the y-positions of the spline knots. Shape: (*batch_shape, (num_qk-1), num_pieces)beta_l(torch.Tensor): Tensor containing the non-negative learnable parameter of the left tail. (*batch_shape,)beta_r(torch.Tensor): Tensor containing the non-negative learnable parameter of the right tail. (*batch_shape,)qk_y(torch.Tensor): Tensor containing the increasing y-positions of the quantile knots. Shape: (*batch_shape, num_qk)qk_x(torch.Tensor): Tensor containing the increasing x-positions of the quantile knots. Shape: (*batch_shape, num_qk)tol(float, optional): Tolerance hyperparameter for numerical stability. Defaults to 1e-4.validate_args(bool, optional): Whether to validate arguments. Defaults to False.
Park, Youngsuk, Danielle Maddix, François-Xavier Aubet, Kelvin Kan, Jan Gasthaus, and Yuyang Wang (2022). "Learning Quantile Functions without Quantile Crossing for Distribution-free Time Series Forecasting". https: //proceedings.mlr.press/v151/park22a.html
method __init__
property arg_constraints
Returns a dictionary from argument names to :class:~torch.distributions.constraints.Constraint objects that should be satisfied by each argument of this distribution. Args that are not tensors need not appear in this dict.
property batch_shape
property event_shape
Returns the shape of a single sample (without batching).property mean
Returns the mean of the distribution.property mode
Returns the mode of the distribution.property stddev
Returns the standard deviation of the distribution.property support
Returns a :class:~torch.distributions.constraints.Constraint object representing this distribution’s support.
property variance
Returns the variance of the distribution.method cdf
z(torch.Tensor): Tensor of shape = (*batch_shape,)
torch.Tensor: Quantile level alpha_tilde.
method cdf_spline
- alpha_tilde = q^(z) if z is in-between qk_x[k] and qk_x[k+1]
- alpha_tilde = qk_x[k] if z< qk_x[k]
- alpha_tilde = qk_x[k+1] if z>qk_x[k+1]
z(torch.Tensor): Observation. Shape: (*batch_shape,)
torch.Tensor: Corresponding quantile level alpha_tilde. Shape: (*batch_shape, num_qk-1)
method cdf_tail
- alpha_tilde = q^(z) if z is in the tail region
- alpha_tilde = qk_x_l or qk_x_r if z is in the non-tail region
z(torch.Tensor): Observation. Shape: (*batch_shape,)left_tail(bool, optional): If True, compute alpha_tilde for the left tail. Otherwise, compute alpha_tilde for the right tail. Defaults to True.
torch.Tensor: Corresponding quantile level alpha_tilde. Shape: (*batch_shape,)
method crps
z(torch.Tensor): Observation to evaluate.
torch.Tensor: CRPS value.
method crps_spline
z(torch.Tensor): Observation to evaluate.
torch.Tensor: CRPS value for the spline.
method crps_tail
z(torch.Tensor): Observation to evaluate. Shape: (*batch_shape,)left_tail(bool, optional): If True, compute CRPS for the left tail. Otherwise, compute CRPS for the right tail. Defaults to True.
torch.Tensor: Tensor containing the CRPS, of the same shape as z.
method log_prob
method loss
method parameterize_qk
quantile_knots(torch.Tensor): x or y positions of the quantile knots. Shape: (*batch_shape, num_qk)
Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]: A tuple containing:- qk: x or y positions of the quantile knots (qk), with index=1, …, num_qk-1. Shape: (*batch_shape, num_qk-1)
- qk_plus: x or y positions of the quantile knots (qk), with index=2, …, num_qk. Shape: (*batch_shape, num_qk-1)
- qk_l: x or y positions of the left-most quantile knot (qk). Shape: (*batch_shape)
- qk_r: x or y positions of the right-most quantile knot (qk). Shape: (*batch_shape)
method parameterize_spline
spline_knots(torch.Tensor): Variable that parameterizes the spline knot positions.qk(torch.Tensor): x or y positions of the quantile knots (qk), with index=1, …, num_qk-1. Shape: (*batch_shape, num_qk-1)qk_plus(torch.Tensor): x or y positions of the quantile knots (qk), with index=2, …, num_qk. Shape: (*batch_shape, num_qk-1)tol(float, optional): Tolerance hyperparameter for numerical stability. Defaults to 1e-4.
Tuple[torch.Tensor, torch.Tensor]: A tuple containing:- sk: x or y positions of the spline knots (sk). Shape: (*batch_shape, num_qk-1, num_pieces)
- delta_sk: difference of x or y positions of the spline knots (sk). Shape: (*batch_shape, num_qk-1, num_pieces)
method parameterize_tail
beta(torch.Tensor): Parameterizes the left or right tail. Shape: (*batch_shape,)qk_x(torch.Tensor): Left- or right-most x-positions of the quantile knots. Shape: (*batch_shape,)qk_y(torch.Tensor): Left- or right-most y-positions of the quantile knots. Shape: (*batch_shape,)
Tuple[torch.Tensor, torch.Tensor]: A tuple containing:- tail_a: a_l or a_r as described above
- tail_b: b_l or b_r as described above
method quantile
method quantile_internal
alpha(torch.Tensor): Tensor of shape = (*batch_shape,) if axis=None, or containing an additional axis on the specified position, otherwise.dim(Optional[int], optional): Index of the axis containing the different quantile levels which are to be computed. Read the description below for detailed information. Defaults to None.
torch.Tensor: Quantiles tensor, of the same shape as alpha.
method quantile_spline
method quantile_tail
method rsample
sample_shape(torch.Size, optional): Shape of the sample. Defaults to torch.Size().
torch.Tensor: Random samples.
class DistributionLoss
DistributionLoss
This PyTorch module wraps the torch.distribution classes allowing it to interact with NeuralForecast models modularly. It shares the negative log-likelihood as the optimization objective and a sample method to generate empirically the quantiles defined by the level list.
Additionally, it implements a distribution transformation that factorizes the scale-dependent likelihood parameters into a base scale and a multiplier efficiently learnable within the network’s non-linearities operating ranges.
Available distributions:
- Poisson
- Normal
- StudentT
- NegativeBinomial
- Tweedie
- Bernoulli (Temporal Classifiers)
- ISQF (Incremental Spline Quantile Function)
distribution(str): Identifier of a torch.distributions.Distribution class.level(float list): Confidence levels for prediction intervals.quantiles(float list): Alternative to level list, target quantiles.num_samples(int): Number of samples for the empirical quantiles.return_params(bool): Whether or not return the Distribution parameters.horizon_weight(Tensor): Tensor of size h, weight for each timestamp of the forecasting window.
tuple: Tuple with tensors of ISQF distribution arguments.
- PyTorch Probability Distributions Package: StudentT.
- David Salinas, Valentin Flunkert, Jan Gasthaus, Tim Januschowski (2020). “DeepAR: Probabilistic forecasting with autoregressive recurrent networks”. International Journal of Forecasting.
- Park, Youngsuk, Danielle Maddix, François-Xavier Aubet, Kelvin Kan, Jan Gasthaus, and Yuyang Wang (2022). “Learning Quantile Functions without Quantile Crossing for Distribution-free Time Series Forecasting”.
method __init__
method get_distribution
distr_args(torch.Tensor): Constructor arguments for the underlying Distribution type.
Distribution: AffineTransformed distribution.
method sample
num_samples independently.
Args:
distr_args(torch.Tensor): Constructor arguments for the underlying Distribution type.num_samples(int, optional): Overwrite number of samples for the empirical quantiles. Defaults to None.
tuple: Tuple with samples, sample mean, and quantiles.
method update_quantile
class PMM
Poisson Mixture Mesh
This Poisson Mixture statistical model assumes independence across groups of data , and estimates relationships within the group.
Args:
n_components(int, optional): The number of mixture components. Defaults to 10.level(float list, optional): Confidence levels for prediction intervals. Defaults to [80, 90].quantiles(float list, optional): Alternative to level list, target quantiles. Defaults to None.return_params(bool, optional): Whether or not return the Distribution parameters. Defaults to False.batch_correlation(bool, optional): Whether or not model batch correlations. Defaults to False.horizon_correlation(bool, optional): Whether or not model horizon correlations. Defaults to False.
method __init__
method domain_map
method get_distribution
distr_args(torch.Tensor): Constructor arguments for the underlying Distribution type.
Distribution: AffineTransformed distribution.
method sample
num_samples independently.
Args:
distr_args(torch.Tensor): Constructor arguments for the underlying Distribution type.num_samples(int, optional): Overwrite number of samples for the empirical quantiles. Defaults to None.
tuple: Tuple with samples, sample mean, and quantiles.
method scale_decouple
loc, scale. Also adds domain protection to the distribution parameters.
method update_quantile
class GMM
Gaussian Mixture Mesh
This Gaussian Mixture statistical model assumes independence across groups of data , and estimates relationships within the group.
Args:
n_components(int, optional): The number of mixture components. Defaults to 10.level(float list, optional): Confidence levels for prediction intervals. Defaults to [80, 90].quantiles(float list, optional): Alternative to level list, target quantiles. Defaults to None.return_params(bool, optional): Whether or not return the Distribution parameters. Defaults to False.batch_correlation(bool, optional): Whether or not model batch correlations. Defaults to False.horizon_correlation(bool, optional): Whether or not model horizon correlations. Defaults to False.weighted(bool, optional): Whether or not model weighted components. Defaults to False.num_samples(int, optional): Number of samples for the empirical quantiles. Defaults to 1000.
- [Kin G. Olivares, O. Nganba Meetei, Ruijun Ma, Rohan Reddy, Mengfei Cao, Lee Dicker. Probabilistic Hierarchical Forecasting with Deep Poisson Mixtures. Submitted to the International
Journal Forecasting, Working paper available at arxiv.](https: //arxiv.org/pdf/2110.13179.pdf)
method __init__
method domain_map
method get_distribution
distr_args(torch.Tensor): Constructor arguments for the underlying Distribution type.
Distribution: AffineTransformed distribution.
method sample
num_samples independently.
Args:
distr_args(torch.Tensor): Constructor arguments for the underlying Distribution type.num_samples(int, optional): Overwrite number of samples for the empirical quantiles. Defaults to None.
tuple: Tuple with samples, sample mean, and quantiles.
method scale_decouple
loc, scale. Also adds domain protection to the distribution parameters.
method update_quantile
class NBMM
Negative Binomial Mixture Mesh
This N. Binomial Mixture statistical model assumes independence across groups of data , and estimates relationships within the group.
Args:
n_components(int, optional): The number of mixture components. Defaults to 10.level(float list, optional): Confidence levels for prediction intervals. Defaults to [80, 90].quantiles(float list, optional): Alternative to level list, target quantiles. Defaults to None.return_params(bool, optional): Whether or not return the Distribution parameters. Defaults to False.weighted(bool, optional): Whether or not model weighted components. Defaults to False.num_samples(int, optional): Number of samples for the empirical quantiles. Defaults to 1000.
- [Kin G. Olivares, O. Nganba Meetei, Ruijun Ma, Rohan Reddy, Mengfei Cao, Lee Dicker. Probabilistic Hierarchical Forecasting with Deep Poisson Mixtures. Submitted to the International
Journal Forecasting, Working paper available at arxiv.](https: //arxiv.org/pdf/2110.13179.pdf)
method __init__
method domain_map
method get_distribution
distr_args(torch.Tensor): Constructor arguments for the underlying Distribution type.
Distribution: AffineTransformed distribution.
method sample
num_samples independently.
Args:
distr_args(torch.Tensor): Constructor arguments for the underlying Distribution type.num_samples(int, optional): Overwrite number of samples for the empirical quantiles. Defaults to None.
tuple: Tuple with samples, sample mean, and quantiles.
method scale_decouple
loc, scale. Also adds domain protection to the distribution parameters.
method update_quantile
class HuberLoss
Huber Loss
The Huber loss, employed in robust regression, is a loss function that exhibits reduced sensitivity to outliers in data when compared to the squared error loss. This function is also refered as SmoothL1.
The Huber loss function is quadratic for small errors and linear for large errors, with equal values and slopes of the different sections at the two points where =.
where is a threshold parameter that determines the point at which the loss transitions from quadratic to linear, and can be tuned to control the trade-off between robustness and accuracy in the predictions.
Args:
delta(float, optional): Specifies the threshold at which to change between delta-scaled L1 and L2 loss. Defaults to 1.0.horizon_weight(Union[torch.Tensor, None], optional): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class TukeyLoss
Tukey Loss
The Tukey loss function, also known as Tukey’s biweight function, is a robust statistical loss function used in robust statistics. Tukey’s loss exhibits quadratic behavior near the origin, like the Huber loss; however, it is even more robust to outliers as the loss for large residuals remains constant instead of scaling linearly.
The parameter in Tukey’s loss determines the ”saturation” point of the function: Higher values of enhance sensitivity, while lower values increase resistance to outliers.
Please note that the Tukey loss function assumes the data to be stationary or normalized beforehand. If the error values are excessively large, the algorithm may need help to converge during optimization. It is advisable to employ small learning rates.
Args:
c(float, optional): Specifies the Tukey loss’ threshold on which residuals are no longer considered. Defaults to 4.685.normalize(bool, optional): Wether normalization is performed within Tukey loss’ computation. Defaults to True.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values- shape: [B, H, 1] for univariate
- shape: [B, H, N] for multivariate
torch.Tensor: Transformed values.- shape: [B, H, 1] for univariate
- shape: [B, H, N] for multivariate
method masked_mean
class HuberQLoss
Huberized Quantile Loss
The Huberized quantile loss is a modified version of the quantile loss function that combines the advantages of the quantile loss and the Huber loss. It is commonly used in regression tasks, especially when dealing with data that contains outliers or heavy tails.
The Huberized quantile loss between y and y_hat measure the Huber Loss in a non-symmetric way. The loss pays more attention to under/over-estimation depending on the quantile parameter ; and controls the trade-off between robustness and accuracy in the predictions with the parameter .
Args:
delta(float, optional): Specifies the threshold at which to change between delta-scaled L1 and L2 loss. Defaults to 1.0.q(float, optional): The slope of the quantile loss, in the context of quantile regression, the q determines the conditional quantile level. Defaults to 0.5.horizon_weight(Union[torch.Tensor, None], optional): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
- Huber Peter, J (1964). “Robust Estimation of a Location Parameter”. Annals of Statistics
- Roger Koenker and Gilbert Bassett, Jr., “Regression Quantiles”.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].
class HuberMQLoss
Huberized Multi-Quantile loss
The Huberized Multi-Quantile loss (HuberMQL) is a modified version of the multi-quantile loss function that combines the advantages of the quantile loss and the Huber loss. HuberMQL is commonly used in regression tasks, especially when dealing with data that contains outliers or heavy tails. The loss function pays more attention to under/over-estimation depending on the quantile list parameter. It controls the trade-off between robustness and prediction accuracy with the parameter .
Args:
level(int list, optional): Probability levels for prediction intervals (Defaults median). Defaults to [80, 90].quantiles(float list, optional): Alternative to level, quantiles to estimate from y distribution. Defaults to None.delta(float, optional): Specifies the threshold at which to change between delta-scaled L1 and L2 loss. Defaults to 1.0.horizon_weight(Union[torch.Tensor, None], optional): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.
- Huber Peter, J (1964). “Robust Estimation of a Location Parameter”. Annals of Statistics
- Roger Koenker and Gilbert Bassett, Jr., “Regression Quantiles”.
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values.
torch.Tensor: Transformed values.- shape: [B, H, 1 * Q] for univariate
- shape: [B, H, N * Q] for multivariate
class HuberIQLoss
Implicit Huber Quantile Loss
Computes the huberized quantile loss between y and y_hat, with the quantile q provided as an input to the network. HuberIQLoss measures the deviation of a huberized quantile forecast. By weighting the absolute deviation in a non symmetric way, the loss pays more attention to under or over estimation.
Args:
quantile_sampling(str, optional): Sampling distribution used to sample the quantiles during training. Choose from [‘uniform’, ‘beta’]. Defaults to ‘uniform’.horizon_weight(Union[torch.Tensor, None], optional): Tensor of size h, weight for each timestamp of the forecasting window. Defaults to None.delta(float, optional): Specifies the threshold at which to change between delta-scaled L1 and L2 loss. Defaults to 1.0.
- Gouttes, Adèle, Kashif Rasul, Mateusz Koren, Johannes Stephan, and Tofigh Naghibi, “Probabilistic Time Series Forecasting with Implicit Quantile Networks”.
- Huber Peter, J (1964). “Robust Estimation of a Location Parameter”. Annals of Statistics
- Roger Koenker and Gilbert Bassett, Jr., “Regression Quantiles”.
method __init__
method domain_map
-
y_hat(torch.Tensor): Predicted values.- shape: [B, h, 1] for univariate
- shape: [B, h, N] for multivariate
method update_quantile
class Accuracy
Accuracy
Computes the accuracy between categorical y and y_hat. This evaluation metric is only meant for evalution, as it is not differentiable.
method __init__
method domain_map
-
y_hat(torch.Tensor): Predicted values.- shape: [B, H, 1] for univariate
- shape: [B, H, N] for multivariate
torch.Tensor: Transformed values.- shape: [B, H, 1] for univariate
- shape: [B, H, N] for multivariate
class sCRPS
Scaled Continues Ranked Probability Score
Calculates a scaled variation of the CRPS, as proposed by Rangapuram (2021), to measure the accuracy of predicted quantiles y_hat compared to the observation y.
This metric averages percentual weighted absolute deviations as defined by the quantile losses.
where is the estimated quantile, and are the target variable realizations.
Args:
level(int list, optional): Probability levels for prediction intervals (Defaults median). Defaults to [80, 90].quantiles(float list, optional): Alternative to level, quantiles to estimate from y distribution. Defaults to None.
- Gneiting, Tilmann. (2011). “Quantiles as optimal point forecasts”. International Journal of Forecasting.
- Spyros Makridakis, Evangelos Spiliotis, Vassilios Assimakopoulos, Zhi Chen, Anil Gaba, Ilia Tsetlin, Robert L. Winkler. (2022). “The M5 uncertainty competition: Results, findings and conclusions”. International Journal of Forecasting.
- Syama Sundar Rangapuram, Lucien D Werner, Konstantinos Benidis, Pedro Mercado, Jan Gasthaus, Tim Januschowski. (2021). “End-to-End Learning of Coherent Probabilistic Forecasts for Hierarchical Time Series”. Proceedings of the 38th International Conference on Machine Learning (ICML).
method __init__
method domain_map
y_hat(torch.Tensor): Predicted values tensor.- Univariate: [B, H, 1]
- Multivariate: [B, H, N]
torch.Tensor: Mapped values tensor with shape [B, H, N].

