Learn R Programming

bases (version 0.2.0)

kernels: Kernel functions

Description

These functions return vectorized kernel functions that can be used to calculate kernel matrices, or provided directly to other basis functions. These functions are designed to take a maximum value of one when identical inputs are provided. Kernels can be combined with arithmetic expressions; see ?kernel-arith.

Usage

k_rbf(scale = 1)

k_lapl(scale = 1)

k_rq(scale = 1, alpha = 2)

k_matern(scale = 1, nu = 1.5)

k_per(scale = 1, period = 1)

Value

A function which calculates a kernel matrix for vector arguments x

and y. The function has class c("kernel", "function").

Arguments

scale

The kernel length scale.

alpha

The shape/df parameter. \(\alpha=1\) is the Cauchy kernel.

nu

The smoothness parameter. \(\nu=0.5\) is the Ornstein–Uhlenbeck kernel.

period

The period, in the same units as scale.

Functions

  • k_rbf(): Radial basis function kernel

  • k_lapl(): Laplace kernel

  • k_rq(): Rational quadratic kernel.

  • k_matern(): Matérn kernel.

  • k_per(): Periodic (exp-sine-squared) kernel.

Examples

Run this code
k = k_rbf()
x = seq(-1, 1, 0.5)
k(0, 0)
k(0, x)
k(x, x)

k = k_per(scale=0.2, period=0.3)
round(k(x, x))

Run the code above in your browser using DataLab