Learn R Programming

GPpenalty (version 1.0.1)

kernel: kernel

Description

Compute the squared exponential kernel defined as \(k = \exp(-\theta (x - x')^2) + g\) , where \(\theta\) is the lengthscale parameter and \(g\) is a jitter term. Both isotropic and separable kernels are supported.

Usage

kernel(x1, theta, x2 = NULL, g = NULL)

Value

a matrix representing the evaluated kernel function

Arguments

x1

matrix of input locations

theta

a scalar or vector specifying the lengthscale parameter. If a vector is provided, a separable kernel function is used. If a scalar is provided and x1 has more than one column, an isotropic kernel is assumed.

x2

matrix of second input locations. If NULL, distance is computed between x1 and itself.

g

a jitter term. It is added when x2=NULL for computational stability.

Details

Matrix computations are implemented in C++ for improved performance and computational efficiency.

Examples

Run this code
### isotropic ###
x <- matrix(seq(0, 10, length=10), ncol=1)
theta <- 5
k <- kernel(x1=x, theta=theta)

### separable ###
x <- matrix(seq(0, 20, length=20), ncol=2)
theta <- c(2, 4)
k <- kernel(x1=x, theta=theta)

Run the code above in your browser using DataLab