gluonts.mx.distribution.piecewise_linear module

class gluonts.mx.distribution.piecewise_linear.FixedKnotsArgProj(knot_spacings: mxnet.ndarray.ndarray.NDArray, **kwargs)[source]

Bases: gluonts.mx.distribution.distribution_output.ArgProj

hybrid_forward(F, x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], **kwargs) → Tuple[Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]][source]

Overrides to construct symbolic graph for this Block.

Parameters
  • x (Symbol or NDArray) – The first input tensor.

  • *args (list of Symbol or list of NDArray) – Additional input tensors.

class gluonts.mx.distribution.piecewise_linear.FixedKnotsPiecewiseLinearOutput(quantile_levels: Union[List[float], numpy.ndarray])[source]

Bases: gluonts.mx.distribution.piecewise_linear.PiecewiseLinearOutput

A simple extension of PiecewiseLinearOutput that “fixes” the knot positions in the quantile function representation. That is, instead of initializing with the number of pieces, the quantiles are provided directly at initialization.

Parameters

quantile_levels

Points along the domain of the quantile function (i.e., in the interval [0,1]) where the knots of the piecewise linear approximation will be fixed, provided in sorted order (ascending).

For more information on the piecewise linear quantile function, refer to gluonts.distribution.PiecewiseLinear.

distr_cls

alias of PiecewiseLinear

classmethod domain_map(F, gamma, slopes, knot_spacings)[source]

Converts arguments to the right shape and domain. The domain depends on the type of distribution, while the correct shape is obtained by reshaping the trailing axis in such a way that the returned tensors define a distribution of the right event_shape.

get_args_proj(prefix: Optional[str] = None) → gluonts.mx.distribution.distribution_output.ArgProj[source]
class gluonts.mx.distribution.piecewise_linear.PiecewiseLinear(gamma: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], slopes: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], knot_spacings: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol])[source]

Bases: gluonts.mx.distribution.distribution.Distribution

Piecewise linear distribution.

This class represents the quantile function (i.e., the inverse CDF) associated with the a distribution, as a continuous, non-decreasing, piecewise linear function defined in the [0, 1] interval:

\[q(x; \gamma, b, d) = \gamma + \sum_{l=0}^L b_l (x_l - d_l)_+\]

where the input \(x \in [0,1]\) and the parameters are

  • \(\gamma\): intercept at 0

  • \(b\): differences of the slopes in consecutive pieces

  • \(d\): knot positions

Parameters
  • gamma – Tensor containing the intercepts at zero

  • slopes – Tensor containing the slopes of each linear piece. All coefficients must be positive. Shape: (*gamma.shape, num_pieces)

  • knot_spacings – Tensor containing the spacings between knots in the splines. All coefficients must be positive and sum to one on the last axis. Shape: (*gamma.shape, num_pieces)

  • F

property F
arg_names = None
property args
property batch_shape

Layout of the set of events contemplated by the distribution.

Invoking sample() from a distribution yields a tensor of shape batch_shape + event_shape, and computing log_prob (or loss more in general) on such sample will yield a tensor of shape batch_shape.

This property is available in general only in mx.ndarray mode, when the shape of the distribution arguments can be accessed.

cdf(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Computes the quantile level \(\alpha\) such that \(q(\alpha) = x\).

Parameters

x – Tensor of shape gamma.shape

Returns

Tensor of shape gamma.shape

Return type

Tensor

crps(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Compute CRPS in analytical form.

Parameters

x – Observation to evaluate. Shape equals to gamma.shape.

Returns

Tensor containing the CRPS.

Return type

Tensor

property event_dim

Number of event dimensions, i.e., length of the event_shape tuple.

This is 0 for distributions over scalars, 1 over vectors, 2 over matrices, and so on.

property event_shape

Shape of each individual event contemplated by the distribution.

For example, distributions over scalars have event_shape = (), over vectors have event_shape = (d, ) where d is the length of the vectors, over matrices have event_shape = (d1, d2), and so on.

Invoking sample() from a distribution yields a tensor of shape batch_shape + event_shape.

This property is available in general only in mx.ndarray mode, when the shape of the distribution arguments can be accessed.

is_reparameterizable = False
loss(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Compute the loss at x according to the distribution.

By default, this method returns the negative of log_prob. For some distributions, however, the log-density is not easily computable and therefore other loss functions are computed.

Parameters

x – Tensor of shape (*batch_shape, *event_shape).

Returns

Tensor of shape batch_shape containing the value of the loss for each event in x.

Return type

Tensor

quantile(level: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Calculates quantiles for the given levels.

Parameters

level – Level values to use for computing the quantiles. level should be a 1d tensor of level values between 0 and 1.

Returns

Quantile values corresponding to the levels passed. The return shape is

(num_levels, …DISTRIBUTION_SHAPE…),

where DISTRIBUTION_SHAPE is the shape of the underlying distribution.

Return type

quantiles

quantile_internal(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], axis: Optional[int] = None) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Evaluates the quantile function at the quantile levels contained in x.

Parameters
  • x – Tensor of shape *gamma.shape if axis=None, or containing an additional axis on the specified position, otherwise.

  • axis – Index of the axis containing the different quantile levels which are to be computed.

Returns

Quantiles tensor, of the same shape as x.

Return type

Tensor

sample(num_samples: Optional[int] = None, dtype=<class 'numpy.float32'>) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Draw samples from the distribution.

If num_samples is given the first dimension of the output will be num_samples.

Parameters
  • num_samples – Number of samples to to be drawn.

  • dtype – Data-type of the samples.

Returns

A tensor containing samples. This has shape (*batch_shape, *eval_shape) if num_samples = None and (num_samples, *batch_shape, *eval_shape) otherwise.

Return type

Tensor

class gluonts.mx.distribution.piecewise_linear.PiecewiseLinearOutput(num_pieces: int)[source]

Bases: gluonts.mx.distribution.distribution_output.DistributionOutput

distr_cls

alias of PiecewiseLinear

distribution(distr_args, loc: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None, scale: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None) → gluonts.mx.distribution.piecewise_linear.PiecewiseLinear[source]

Construct the associated distribution, given the collection of constructor arguments and, optionally, a scale tensor.

Parameters
  • distr_args – Constructor arguments for the underlying Distribution type.

  • loc – Optional tensor, of the same shape as the batch_shape+event_shape of the resulting distribution.

  • scale – Optional tensor, of the same shape as the batch_shape+event_shape of the resulting distribution.

classmethod domain_map(F, gamma, slopes, knot_spacings)[source]

Converts arguments to the right shape and domain. The domain depends on the type of distribution, while the correct shape is obtained by reshaping the trailing axis in such a way that the returned tensors define a distribution of the right event_shape.

property event_shape

Shape of each individual event contemplated by the distributions that this object constructs.

class gluonts.mx.distribution.piecewise_linear.TransformedPiecewiseLinear(base_distribution: gluonts.mx.distribution.piecewise_linear.PiecewiseLinear, transforms: List[gluonts.mx.distribution.bijection.Bijection])[source]

Bases: gluonts.mx.distribution.transformed_distribution.TransformedDistribution, gluonts.mx.distribution.piecewise_linear.PiecewiseLinear

arg_names = None
crps(y: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Compute the continuous rank probability score (CRPS) of x according to the distribution.

Parameters

x – Tensor of shape (*batch_shape, *event_shape).

Returns

Tensor of shape batch_shape containing the CRPS score, according to the distribution, for each event in x.

Return type

Tensor