The package offers two ways to compute a covariance matrix. Kernel
specifications, such as rbf_kernel(), are objects: they can be combined
with sum_kernel(), product_kernel(), and scale_kernel(), their
parameters can be read, updated, and optimized, and models store them.
evaluate_kernel() computes their covariance. The covariance functions,
such as kernel_rbf(), take the parameter values as arguments and return
one matrix directly. Both use the same formulas.
Stability
Stable: from version 1.0.0 this interface changes incompatibly only in a major release, after a deprecation period. Results and options that concern an experimental model class, kernel, or argument follow that interface's tier. See gaussianprocesses-package for the policy.
Examples
kernel <- sum_kernel(rbf_kernel(length_scale = 0.5), white_noise_kernel(0.1))
x <- c(0, 0.5, 1)
evaluate_kernel(kernel, x)
#> [,1] [,2] [,3]
#> [1,] 1.1000000 0.6065307 0.1353353
#> [2,] 0.6065307 1.1000000 0.6065307
#> [3,] 0.1353353 0.6065307 1.1000000
# Cross-covariance between training and new inputs.
evaluate_kernel(kernel, x, c(0.25, 2))
#> [,1] [,2]
#> [1,] 0.8824969 0.0003354626
#> [2,] 0.8824969 0.0111089965
#> [3,] 0.3246525 0.1353352832