gluonts.mx.model.gp_forecaster.gaussian_process module#

class gluonts.mx.model.gp_forecaster.gaussian_process.GaussianProcess(sigma: typing.Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol], kernel: gluonts.mx.kernels._kernel.Kernel, prediction_length: typing.Optional[int] = None, context_length: typing.Optional[int] = None, num_samples: typing.Optional[int] = None, float_type: typing.Type = <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: Optional[Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]] = None, y_train: Optional[Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]] = None, x_test: Optional[Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]] = None, mean: Optional[Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]] = None, std: Optional[Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]] = None, samples: Optional[Union[mxnet.ndarray.ndarray.NDArray, mxnet.symbol.symbol.Symbol]] = None, axis: Optional[Tuple[float, float, float, float]] = 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