Computes diag(K(x, x)) without constructing the full covariance matrix.
This is particularly useful in sparse Gaussian-process approximations.
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(variance = 2), linear_kernel())
x <- cbind(1:3, 0:2)
kernel_diagonal(kernel, x)
#> [1] 3 7 15
all.equal(kernel_diagonal(kernel, x), diag(evaluate_kernel(kernel, x)))
#> [1] TRUE