Computes common kernel functions elementwise for two equal-length numeric
vectors. Each function is vectorized: the result at position i depends only
on y1[i]
and y2[i]
.
Usage
linear_kernel(y1, y2)
polynomial_kernel(y1, y2, intercept, degree)
gaussian_kernel(y1, y2, bandwidth)
matern_kernel(y1, y2, lengthscale)
Value
A numeric vector of length length(y1)
giving the kernel values for
each pair of corresponding elements in y1
and y2
.
Details
The following kernels are provided:
Linear: $$K(y_1, y_2) = y_1 y_2$$
Polynomial: $$K(y_1, y_2) = (y_1 y_2 + c)^{d},$$ with intercept \(c \in \mathbb{R}\) and degree \(d \in \mathbb{N}_0\).
Gaussian (RBF): $$K(y_1, y_2) = \exp\left(-\frac{(y_1 - y_2)^2}{2 \sigma^2}\right),$$ where \(\sigma\) is the bandwidth.
Matern (\(\nu = 3/2\)): $$K(y_1, y_2) = \left(1 + \frac{\sqrt{3} |y_1 - y_2|}{\ell}\right) \exp\left(-\frac{\sqrt{3} |y_1 - y_2|}{\ell}\right),$$ with lengthscale \(\ell > 0\).
Inputs must have the same length; kernel-specific parameters must be valid
(e.g., positive bandwidth/lengthscale, non-negative integer degree). Inputs
containing NA
will yield NA
in the corresponding positions.