Computes the squared-exponential (radial basis function) kernel between rows
of x and y. A scalar length scale gives an isotropic kernel; one
length scale per input dimension gives automatic relevance determination
(ARD).
Arguments
- x
Numeric vector or matrix. Matrix rows are observations and columns are input dimensions.
- y
Optional numeric vector or matrix with the same number of input dimensions as
x. IfNULL, computes the covariance ofxwith itself.- variance
Positive marginal variance.
- length_scale
Positive scalar or numeric vector with one value per input dimension. A vector enables ARD.
Value
A numeric covariance matrix with nrow(x) rows and nrow(y)
columns. Numeric vectors are treated as one-dimensional observations.
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.
See also
rbf_kernel() creates the same kernel as a reusable
specification, which can be combined, optimized, and used in models.
Examples
x <- seq(0, 2, by = 0.5)
kernel_rbf(x, variance = 2, length_scale = 0.7)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 2.00000000 1.5496749 0.7208956 0.2013378 0.03375977
#> [2,] 1.54967486 2.0000000 1.5496749 0.7208956 0.20133780
#> [3,] 0.72089558 1.5496749 2.0000000 1.5496749 0.72089558
#> [4,] 0.20133780 0.7208956 1.5496749 2.0000000 1.54967486
#> [5,] 0.03375977 0.2013378 0.7208956 1.5496749 2.00000000
# ARD: one length scale per input dimension.
x2 <- cbind(c(0, 1, 2), c(0, 0, 1))
kernel_rbf(x2, length_scale = c(0.5, 3))
#> [,1] [,2] [,3]
#> [1,] 1.000000000 0.1353353 0.000317334
#> [2,] 0.135335283 1.0000000 0.128021693
#> [3,] 0.000317334 0.1280217 1.000000000
# Cross-covariance between two sets of inputs.
kernel_rbf(x, c(0.25, 1.75))
#> [,1] [,2]
#> [1,] 0.9692332 0.2162652
#> [2,] 0.9692332 0.4578334
#> [3,] 0.7548396 0.7548396
#> [4,] 0.4578334 0.9692332
#> [5,] 0.2162652 0.9692332