Table Of Contents
Table Of Contents

gluonts.gp.gaussian_process module

class gluonts.gp.gaussian_process.GaussianProcess(sigma: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], kernel: gluonts.kernels._kernel.Kernel, prediction_length: Optional[int] = None, context_length: Optional[int] = None, num_samples: Optional[int] = None, ctx: mxnet.context.Context = cpu(0), float_type: gluonts.core.component.DType = <class 'numpy.float64'>, jitter_method: str = 'iter', max_iter_jitter: int = 10, neg_tol: float = -1e-08, diag_weight: float = 1e-06, increase_jitter: int = 10, sample_noise: bool = True, F=None)[source]

Bases: object

exact_inference(x_train: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], y_train: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], x_test: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Tuple[Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]][source]
Parameters:
  • x_train – Training set of features of shape (batch_size, context_length, num_features).
  • y_train – Training labels of shape (batch_size, context_length).
  • x_test – Test set of features of shape (batch_size, prediction_length, num_features).
Returns:

Tensor

Predictive GP samples of shape (batch_size, prediction_length, num_samples).

Tensor

Predictive mean of the GP of shape (batch_size, prediction_length).

Tensor

Predictive standard deviation of the GP of shape (batch_size, prediction_length).

Return type:

Tuple

log_prob(x_train: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], y_train: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]

This method computes the negative marginal log likelihood

\begin{aligned} \frac{1}{2} [d \log(2\pi) + \log(|K|) + y^TK^{-1}y], \end{aligned}

where \(d\) is the number of data points. This can be written in terms of the Cholesky factor \(L\) as

\begin{aligned} \log(|K|) = \log(|LL^T|) &= \log(|L||L|^T) = \log(|L|^2) = 2\log(|L|) \\ &= 2\log\big(\prod_i^n L_{ii}\big) = 2 \sum_i^N \log(L_{ii}) \end{aligned} and
\begin{aligned} y^TK^{-1}y = (y^TL^{-T})(L^{-1}y) = (L^{-1}y)^T(L^{-1}y) = ||L^{-1}y||_2^2. \end{aligned}
Parameters:
  • x_train – Training set of features of shape (batch_size, context_length, num_features).
  • y_train – Training labels of shape (batch_size, context_length).
Returns:

The negative log marginal likelihood of shape (batch_size,)

Return type:

Tensor

static plot(ts_idx: int, x_train: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None, y_train: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None, x_test: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None, mean: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None, std: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None, samples: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol, None] = None, axis: Optional[List] = None) → None[source]

This method plots the sampled GP distribution at the test points in solid colors, as well as the predictive mean as the dashed red line. Plus and minus 2 predictive standard deviations are shown in the grey region. The training points are shown as the blue dots.

Parameters:
  • ts_idx – Time series index to plot
  • x_train – Training set of features of shape (batch_size, context_length, num_features).
  • y_train – Training labels of shape (batch_size, context_length).
  • x_test – Test set of features of shape (batch_size, prediction_length, num_features).
  • mean – Mean of the GP of shape (batch_size, prediction_length).
  • std – Standard deviation of the GP of shape (batch_size, prediction_length, 1).
  • samples – GP samples of shape (batch_size, prediction_length, num_samples).
  • axis – Plot axes limits
sample(mean: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], covariance: Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]) → Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol][source]
Parameters:
  • covariance – The covariance matrix of the GP of shape (batch_size, prediction_length, prediction_length).
  • mean – The mean vector of the GP of shape (batch_size, prediction_length).
Returns:

Samples from a Gaussian Process of shape (batch_size, prediction_length, num_samples), where \(L\) is the matrix square root, Cholesky Factor of the covariance matrix with the added noise tolerance on the diagonal, \(Lz\), where \(z \sim N(0,I)\) and assumes the mean is zero.

Return type:

Tensor