Learn R Programming

CVEK (version 0.1-2)

generate_kernel: Generating A Single Kernel

Description

Generate kernels for the kernel library.

Usage

generate_kernel(method = "rbf", l = 1, p = 2, sigma = 1)

Arguments

method

(character) A character string indicating which kernel is to be computed.

l

(numeric) A numeric number indicating the hyperparameter (flexibility) of a specific kernel.

p

(integer) For polynomial, p is the power; for matern, v = p + 1 / 2; for rational, alpha = p.

sigma

(numeric) The covariance coefficient for neural network kernel.

Value

kern

(function) A function indicating the generated kernel.

Details

There are seven kinds of kernel available here. For convenience, we define \(r=\mid x-x'\mid\).

Gaussian RBF Kernels $$k_{SE}(r)=exp\Big(-\frac{r^2}{2l^2}\Big)$$

Matern Kernels $$k_{Matern}(r)=\frac{2^{1-\nu}}{\Gamma(\nu)}\Big(\frac{\sqrt{2\nu r}}{l}\Big)^\nu K_\nu \Big(\frac{\sqrt{2\nu r}}{l}\Big)$$

Rational Quadratic Kernels $$k_{RQ}(r)=\Big(1+\frac{r^2}{2\alpha l^2}\Big)^{-\alpha}$$

Polynomial Kernels $$k(x, x')=(x \cdot x')^p$$ We have intercept kernel when \(p=0\), and linear kernel when \(p=1\).

Neural Network Kernels $$k_{NN}(x, x')=\frac{2}{\pi}sin^{-1}\Big(\frac{2\sigma \tilde{x}^T \tilde{x}'}{\sqrt{(1+2\sigma \tilde{x}^T \tilde{x})(1+2\sigma \tilde{x}'^T \tilde{x}')}}\Big)$$ where \(\tilde{x}\) is the vector \(x\) prepending with \(1\).

References

The MIT Press. Gaussian Processes for Machine Learning, 2006.

Examples

Run this code
# NOT RUN {
kern_par <- data.frame(method = c("rbf", "polynomial", "matern"),
l = c(.5, 1, 1.5), p = 1:3, sigma = rep(1, 3), stringsAsFactors = FALSE)

kern_func_list <- list()
for (j in 1:nrow(kern_par)) {
  kern_func_list[[j]] <- generate_kernel(kern_par[j, ]$method,
                                         kern_par[j, ]$l,
                                         kern_par[j, ]$p, 
                                         kern_par[j, ]$sigma)
}


# }

Run the code above in your browser using DataLab