gluonts.mx.block.quantile_output module#
- class gluonts.mx.block.quantile_output.IncrementalDenseLayerProjection(num_outputs: int, **kwargs)[source]#
Bases:
HybridBlock
A dense layer that outputs non-decreasing values.
- Parameters:
num_outputs – number of outputs of the layer.
- class gluonts.mx.block.quantile_output.IncrementalQuantileOutput(quantiles: List[float], quantile_weights: Optional[List[float]] = None)[source]#
Bases:
QuantileOutput
Output layer using a quantile loss and projection layer to connect the quantile output to the network.
Differently from
QuantileOutput
, this class enforces the correct order relation between quantiles: this is done by parametrizing the increments between quantiles instead of the quantiles directly.- Parameters:
quantiles – list of quantiles to compute loss over.
quantile_weights – weights of the quantiles.
- class gluonts.mx.block.quantile_output.QuantileLoss(quantiles: List[float], quantile_weights: Optional[List[float]] = None, weight: Optional[float] = None, batch_axis: int = 0, **kwargs)[source]#
Bases:
Loss
- static compute_quantile_loss(F, y_true: Union[NDArray, Symbol], y_pred_p: Union[NDArray, Symbol], p: float) Union[NDArray, Symbol] [source]#
Compute the quantile loss of the given quantile.
- Parameters:
F – A module that can either refer to the Symbol API or the NDArray API in MXNet.
y_true – ground truth values to compute the loss against.
y_pred_p – predicted target quantile, same shape as
y_true
.p – quantile error to compute the loss.
- Returns:
quantile loss, shape: (N1 x N2 x … x Nk x 1)
- Return type:
Tensor
- hybrid_forward(F, y_true: Union[NDArray, Symbol], y_pred: Union[NDArray, Symbol], sample_weight=None)[source]#
Compute the weighted sum of quantile losses.
- Parameters:
F – A module that can either refer to the Symbol API or the NDArray API in MXNet.
y_true – ground truth values, shape (N1 x N2 x … x Nk)
y_pred – predicted target, shape (N1 x N2 x … x Nk x num_quantiles)
sample_weight – sample weights
- Returns:
weighted sum of the quantile losses, shape N1 x N1 x … Nk
- Return type:
Tensor
- class gluonts.mx.block.quantile_output.QuantileOutput(quantiles: List[float], quantile_weights: Optional[List[float]] = None)[source]#
Bases:
object
Output layer using a quantile loss and projection layer to connect the quantile output to the network.
- Parameters:
quantiles – list of quantiles to compute loss over.
quantile_weights – weights of the quantiles.
- get_loss() HybridBlock [source]#
- Returns:
constructs quantile loss object.
- Return type:
nn.HybridBlock
- property quantiles: List[float]#
- gluonts.mx.block.quantile_output.crps_weights_pwl(quantile_levels: List[float]) List[float] [source]#
Compute the quantile loss weights making mean quantile loss equal to CRPS under linear interpolation assumption.
Quantile levels are assumed to be sorted in increasing order.
Under the assumption of linear interpolation
\[CRPS = sum_{i=0}^{n-1} 0.5 * (q_{i+1}-q_{i}) * (z_{i+1}+z_{i})\]where \(z_i\) is the i-th quantile prediction \(q_i\). The inner terms cancel due to the telescoping sum property and we obtain
\[CRPS = sum_{i=1}^n w_i z_i\]with the weights \(w_i = (q_{i+1}-q_{i-1})/2\) for \(i = 1, ..., n-1\), \(w_0 = (q_1-q_0)/2\) and \(w_n = (w_n - w_{n-1})/2\).
- gluonts.mx.block.quantile_output.uniform_weights(objects: list) List[float] [source]#
Return uniform weights for a list of objects.
>>> uniform_weights(["a", "b", "c", "d"]) [0.25, 0.25, 0.25, 0.25]
- Parameters:
objects – Objects that need to be weighted.
- Returns:
List of weights.
- Return type:
List[float]