Skip to contents

Fit a Gaussian process in R

Usage

gaussian_process(
  form,
  data,
  sparse = F,
  n_points = 5,
  training_method = "bfgs",
  noise = T
)

Arguments

form

the regression formula for the gaussian process. The left-hand-side gives determines outcome you are fitting the GP to, and the right-hand side gives the kernel specification.

data

the dataframe from which to source regression data.

sparse

a boolean indicating whether to use the projected process approximation to speed up training. Recommended for N>500.

n_points

The number of inducing points used for the projected process approximation. Defaults to 5. If set too large, may cause numerical stability issues when calculating the gradient of the marginal likelihood.

training_method

one of 'bfgs', 'cg' (conjugate gradient), 'rgenoud' (genetic optimization using derivatives), or "coin" (coin betting). The method used to optimize the marginal likelihood (default BFGS).

noise

whether to fit a GP assuming function values are observed with noise (default TRUE). Setting FALSE is only available when sparse = F.

Examples

# \donttest{
library(tibble)
library(ggplot2)
n <- 400
data <- tibble(
 x = runif(n), 
 y = runif(n), 
 z = x^2 + rnorm(n, 0,.1)
)
gp_model <- gaussian_process(z ~ rbf(x,y), data = data)
data$predictions <- predict(gp_model)[,1]
ggplot(data, aes(x=x)) + 
  geom_point(aes(y= z)) + 
  geom_line(aes(y=predictions))

 # }