Skip to contents

Computes the posterior of the latent function and of new observations under a FITC or VFE model (fit_sparse_gp()).

Usage

predict_sparse_gp(
  model,
  x,
  interval_level = 0.95,
  include_covariance = FALSE,
  variance_tolerance = sqrt(.Machine$double.eps),
  observation_noise_variance = NULL,
  block_size = NULL
)

Arguments

model

A fitted sparse GP model.

x

Numeric vector or matrix of prediction inputs.

interval_level

Probability level for intervals.

include_covariance

If TRUE, construct the full latent covariance matrix. Otherwise only marginal variances are computed.

variance_tolerance

Relative tolerance for posterior variances.

observation_noise_variance

Optional prediction-time observation-noise variance. Required when the sparse model was fitted with observation- specific training noise.

block_size

Number of prediction inputs processed together when include_covariance = FALSE. NULL chooses the largest block whose inducing-by-block cross-covariance holds at most \(2^{20}\) values, as in predict_gp(); memory then grows linearly with the number of prediction inputs. Results do not depend on it.

Value

An object of class gaussianprocesses_sparse_prediction, with the shared prediction fields of predict_gp() and approximation.

Details

With \(A = K_{uu} + K_{uf} \Lambda^{-1} K_{fu}\), where \(\Lambda\) is the FITC diagonal or, for VFE, the noise, the latent posterior at new inputs is $$\mu_* = m(x_*) + K_{*u} A^{-1} K_{uf} \Lambda^{-1} (y - m(X)), \qquad \Sigma_{**} = K_{**} - Q_{**} + K_{*u} A^{-1} K_{u*},$$ computed through the Cholesky factors of \(K_{uu}\) and \(B = I + V \Lambda^{-1} V^\top\). For VFE these are the predictive equations of the deterministic training conditional.

Stability

Experimental: this interface may change in a minor release, and every change is listed in NEWS. See gaussianprocesses-package for the policy.

Examples

x <- seq(-3, 3, length.out = 200)
y <- sin(x) + 0.1 * cos(7 * x)
kernel <- rbf_kernel(length_scale = 0.8)

sparse <- fit_sparse_gp(x, y, kernel, noise_variance = 0.01, n_inducing = 15)
exact <- fit_gp(x, y, kernel, noise_variance = 0.01)

x_new <- c(-1, 0, 1)
cbind(
  exact = predict_gp(exact, x_new)$mean,
  sparse = predict_sparse_gp(sparse, x_new)$mean
)
#>             exact       sparse
#> [1,] -0.846050529 -0.845670318
#> [2,] -0.001243997 -0.000849367
#> [3,]  0.837511648  0.837674891