# gluonts.distribution.lowrank_multivariate_gaussian module¶

class gluonts.distribution.lowrank_multivariate_gaussian.LowrankMultivariateGaussian(dim: int, rank: int, mu: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], D: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], W: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol])[source]

Multivariate Gaussian distribution, with covariance matrix parametrized as the sum of a diagonal matrix and a low-rank matrix

$\Sigma = D + W W^T$

The implementation is strongly inspired from Pytorch: https://github.com/pytorch/pytorch/blob/master/torch/distributions/lowrank_multivariate_normal.py.

Complexity to compute log_prob is $$O(dim * rank + rank^3)$$ per element.

Parameters: dim – Dimension of the distribution’s support rank – Rank of W mu – Mean tensor, of shape (…, dim) D – Diagonal term in the covariance matrix, of shape (…, dim) W – Low-rank factor in the covariance matrix, of shape (…, dim, rank)
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.

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.

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 = True
log_prob(x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Compute the log-density of the distribution at x.

Parameters: x – Tensor of shape (*batch_shape, *event_shape). Tensor of shape batch_shape containing the log-density of the distribution for each event in x. Tensor
mean

Tensor containing the mean of the distribution.

sample_rep(num_samples: int = None) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Draw samples from the multivariate Gaussian distribution:

$s = \mu + D u + W v,$

where $$u$$ and $$v$$ are standard normal samples.

Parameters: num_samples – number of samples to be drawn. tensor with shape (num_samples, .., dim)
variance

Tensor containing the variance of the distribution.

class gluonts.distribution.lowrank_multivariate_gaussian.LowrankMultivariateGaussianOutput(dim: int, rank: int)[source]
distribution(distr_args, scale=None, **kwargs) → gluonts.distribution.distribution.Distribution[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. scale – Optional tensor, of the same shape as the batch_shape+event_shape of the resulting distribution.
domain_map(F, mu_vector, D_vector, W_vector)[source]
Parameters: F – mu_vector – Tensor of shape (…, dim) D_vector – Tensor of shape (…, dim) W_vector – Tensor of shape (…, dim * rank ) A tuple containing tensors mu, D, and W, with shapes (…, dim), (…, dim), and (…, dim, rank), respectively. Tuple
event_shape

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

get_args_proj(prefix: Optional[str] = None) → gluonts.distribution.distribution_output.ArgProj[source]
gluonts.distribution.lowrank_multivariate_gaussian.capacitance_tril(F, rank: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], W: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], D: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]
Parameters: F – rank – W ((.., dim, rank)) – D ((.., dim)) – the capacitance matrix $$I + W^T D^{-1} W$$
gluonts.distribution.lowrank_multivariate_gaussian.log_det(F, batch_D: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], batch_capacitance_tril: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Uses the matrix determinant lemma.

$\log|D + W W^T| = \log|C| + \log|D|,$

where $$C$$ is the capacitance matrix $$I + W^T D^{-1} W$$, to compute the log determinant.

Parameters: F – batch_D – batch_capacitance_tril –
gluonts.distribution.lowrank_multivariate_gaussian.lowrank_log_likelihood(F, dim: int, rank: int, mu: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], D: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], W: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]
gluonts.distribution.lowrank_multivariate_gaussian.mahalanobis_distance(F, W: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], D: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], capacitance_tril: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], x: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

Uses the Woodbury matrix identity

$(W W^T + D)^{-1} = D^{-1} - D^{-1} W C^{-1} W^T D^{-1},$

where $$C$$ is the capacitance matrix $$I + W^T D^{-1} W$$, to compute the squared Mahalanobis distance $$x^T (W W^T + D)^{-1} x$$.

Parameters: F – W – (…, dim, rank) D – (…, dim) capacitance_tril – (…, rank, rank) x – (…, dim)