Learn R Programming

⚠️There's a newer version (0.2.15) of this package.Take me there.

GauPro

Overview

This package allows you to fit a Gaussian process to a dataset. A Gaussian process is a commonly used model in computer simulation. It assumes that the distribution of any set of points is multivariate normal with a constant mean and a correlation function.

The newest release allows you to use different kernel and trend functions, instead of just a squared exponential covariance.

You should probably use a different package for your modeling, such as laGP, mlegp, or GPfit if you are using R, or GPy if you are using Python.

Installation

You can install like any other package

install.packages('GauPro')

The most up-to-date version can be downloaded from my Github account.

# install.packages("devtools")
devtools::install_github("CollinErickson/GauPro")

Examples in 1-Dimension

Fit a sine curve with noise.

n <- 12
x <- matrix(seq(0,1,length.out = n), ncol=1)
y <- sin(2*pi*x) + rnorm(n,0,1e-1)
gp <- GauPro::GauPro(X=x, Z=y)
curve(gp$pred(x));points(x,y)
curve(gp$pred(x)+2*gp$pred(x,T)$se,col=2,add=T);curve(gp$pred(x)-2*gp$pred(x,T)$se,col=2,add=T)

This is the likelihood as a function of the log of theta. It is not convex and is difficult to optimize in general.

curve(sapply(x, gp$deviance_theta_log),-10,10, n = 300) # deviance profile

Fit a sawtooth function with no noise.

n <- 12
x <- matrix(seq(0,1,length.out = n), ncol=1)
y <- (2*x) %%1
gp <- GauPro::GauPro(X=x, Z=y)
curve(gp$pred(x));points(x,y)
curve(gp$pred(x)+2*gp$pred(x,T)$se,col=2,add=T);curve(gp$pred(x)-2*gp$pred(x,T)$se,col=2,add=T)

curve(sapply(x, gp$deviance_theta_log),-10,10, n = 300) # deviance profile

Using kernels

library(GauPro)

The kernel, or covariance function, has a large effect on the Gaussian process being estimated. The function GauPro uses the squared exponential, or Gaussian, covariance function. The newer version of GauPro has a new function that will fit a model using whichever kernel is specified.

To do this a kernel must be specified, then passed to GauPro_kernel_model$new. The example below shows what the Matern 5/2 kernel gives.

kern <- Matern52$new(0)
gpk <- GauPro_kernel_model$new(matrix(x, ncol=1), y, kernel=kern, parallel=FALSE)
if (requireNamespace("MASS", quietly = TRUE)) {
  plot(gpk)
}

The exponential kernel is shown below. You can see that it has a huge effect on the model fit. The exponential kernel assumes the correlation between points dies off very quickly, so there is much more uncertainty and variation in the predictions and sample paths.

kern.exp <- Exponential$new(0)
gpk.exp <- GauPro_kernel_model$new(matrix(x, ncol=1), y, kernel=kern.exp, parallel=FALSE)
if (requireNamespace("MASS", quietly = TRUE)) {
  plot(gpk.exp)
}

Trends

Along with the kernel the trend can also be set. The trend determines what the mean of a point is without any information from the other points. I call it a trend instead of mean because I refer to the posterior mean as the mean, whereas the trend is the mean of the normal distribution. Currently the three options are to have a mean 0, a constant mean (default and recommended), or a linear model.

With the exponential kernel above we see some regression to the mean. Between points the prediction reverts towards the mean of 0.4006891. Also far away from any data the prediction will near this value.

Below when we use a mean of 0 we do not see this same reversion.

kern.exp <- Exponential$new(0)
trend.0 <- trend_0$new()
gpk.exp <- GauPro_kernel_model$new(matrix(x, ncol=1), y, kernel=kern.exp, trend=trend.0, parallel=FALSE)
if (requireNamespace("MASS", quietly = TRUE)) {
  plot(gpk.exp)
}

Copy Link

Version

Install

install.packages('GauPro')

Monthly Downloads

763

Version

0.2.4

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Collin Erickson

Last Published

April 11th, 2021

Functions in GauPro (0.2.4)

GauPro_Gauss

Corr Gauss GP using inherited optim
Exponential

Exponential Kernel R6 class
GauPro_kernel_beta

Beta Kernel R6 class
GauPro_kernel

Kernel R6 class
GauPro_base

Class providing object with methods for fitting a GP model
GauPro_Gauss_LOO

Corr Gauss GP using inherited optim
GauPro

GauPro_selector
GauPro_kernel_model

GauPro model that uses kernels
GauPro_kernel_model_LOO

Corr Gauss GP using inherited optim
GauPro_trend

Trend R6 class
Matern52

Matern 5/2 Kernel R6 class
Gaussian_hessianC

Calculate Hessian for a GP with Gaussian correlation
Gaussian_hessianCC

Gaussian hessian in C
PowerExp

Power Exponential Kernel R6 class
RatQuad

Rational Quadratic Kernel R6 class
Gaussian_hessianR

Calculate Hessian for a GP with Gaussian correlation
Matern32

Matern 3/2 Kernel R6 class
Periodic

Periodic Kernel R6 class
corr_gauss_matrix_sym_armaC

Correlation Gaussian matrix in C using Armadillo (symmetric)
corr_gauss_matrix_symC

Correlation Gaussian matrix in C (symmetric)
corr_gauss_matrixC

Correlation Gaussian matrix in C using Rcpp
corr_gauss_matrix_armaC

Correlation Gaussian matrix in C using Armadillo
corr_gauss_matrix

Gaussian correlation
corr_gauss_dCdX

Correlation Gaussian matrix gradient in C using Armadillo
White

White noise Kernel R6 class
Triangle

Triangle Kernel R6 class
Gaussian_devianceC

Calculate the Gaussian deviance in C
corr_exponential_matrix_symC

Correlation Gaussian matrix in C (symmetric)
predict.GauPro

Predict for class GauPro
Gaussian

Gaussian Kernel R6 class
arma_mult_cube_vec

Cube multiply over first dimension
plot.GauPro

Plot for class GauPro
+.GauPro_kernel

Kernel sum
sqrt_matrix

Find the square root of a matrix
corr_matern32_matrix_symC

Correlation Gaussian matrix in C (symmetric)
corr_matern52_matrix_symC

Correlation Gaussian matrix in C (symmetric)
gradfuncarray

Calculate gradfunc in optimization to speed up. NEEDS TO APERM dC_dparams Doesn't need to be exported, should only be useful in functions.
kernel_product

Gaussian Kernel R6 class
kernel_sum

Gaussian Kernel R6 class
trend_LM

Trend R6 class
*.GauPro_kernel

Kernel product
kernel_gauss_dC

Correlation Gaussian matrix in C (symmetric)
trend_c

Trend R6 class
trend_0

Trend R6 class