Skip to contents

Computes diag(K(x, x)) without constructing the full covariance matrix. This is particularly useful in sparse Gaussian-process approximations.

Usage

kernel_diagonal(kernel, x)

Arguments

kernel

A Gaussian-process kernel specification.

x

Numeric vector or matrix of observations.

Value

A numeric vector with one prior variance per observation.

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