kernel_functions {shrinkGPR} | R Documentation |
Kernel Functions for Gaussian Processes
Description
A set of kernel functions for Gaussian processes, including the squared exponential (SE) kernel and Matérn kernels
with smoothness parameters 1/2, 3/2, and 5/2. These kernels compute the covariance structure for Gaussian process regression
models and are designed for compatibility with the shrinkGPR
function.
Usage
kernel_se(thetas, tau, x, x_star = NULL)
kernel_matern_12(thetas, tau, x, x_star = NULL)
kernel_matern_32(thetas, tau, x, x_star = NULL)
kernel_matern_52(thetas, tau, x, x_star = NULL)
Arguments
thetas |
A |
tau |
A |
x |
A |
x_star |
Either |
Details
These kernel functions are used to define the covariance structure in Gaussian process regression models. Each kernel implements a specific covariance function:
-
kernel_se
: Squared exponential (SE) kernel, also known as the radial basis function (RBF) kernel. It assumes smooth underlying functions. -
kernel_matern_12
: Matérn kernel with smoothness parameter\nu = 1/2
, equivalent to the absolute exponential kernel. -
kernel_matern_32
: Matérn kernel with smoothness parameter\nu = 3/2
. -
kernel_matern_52
: Matérn kernel with smoothness parameter\nu = 5/2
.
The sqdist
helper function is used internally by these kernels to compute squared distances between data points.
Note that these functions perform no input checks, as to ensure higher performance. Users should ensure that the input tensors are of the correct dimensions.
Value
A torch_tensor
containing the batched covariance matrices (one for each latent sample):
If
x_star = NULL
, the output is of dimensionsn_latent x N x N
, representing pairwise covariances between all points inx
.If
x_star
is provided, the output is of dimensionsn_latent x N_new x N
, representing pairwise covariances betweenx_star
andx
.
Examples
if (torch::torch_is_installed()) {
# Example inputs
torch::torch_manual_seed(123)
n_latent <- 3
d <- 2
N <- 5
thetas <- torch::torch_randn(n_latent, d)$abs()
tau <- torch::torch_randn(n_latent)$abs()
x <- torch::torch_randn(N, d)
# Compute the SE kernel
K_se <- kernel_se(thetas, tau, x)
print(K_se)
# Compute the Matérn 3/2 kernel
K_matern32 <- kernel_matern_32(thetas, tau, x)
print(K_matern32)
# Compute the Matérn 5/2 kernel with x_star
x_star <- torch::torch_randn(3, d)
K_matern52 <- kernel_matern_52(thetas, tau, x, x_star)
print(K_matern52)
}