GradientKernel<T>

Models & Types · AiDotNet.Kernels

Kernel that incorporates gradient observations for GPs with derivative information.

Implements: IKernelFunction<T>

For Beginners

Sometimes you have access not just to function values f(x), but also to gradient information ∇f(x) (the rate of change in each direction).

This is common in:

  • Bayesian optimization: When evaluating an expensive function, you might also

get gradient information “for free” (e.g., via automatic differentiation)

  • Physics-informed ML: Physical laws often constrain derivatives
  • Adjoint methods: Gradients are computed alongside function values

The GradientKernel extends a base kernel to model both values and gradients. If f(x) is a GP with kernel k(x, x’), then:

  • Cov(f(x), f(x’)) = k(x, x’)
  • Cov(∂f/∂xᵢ, f(x’)) = ∂k(x, x’)/∂xᵢ
  • Cov(∂f/∂xᵢ, ∂f/∂x’ⱼ) = ∂²k(x, x’)/∂xᵢ∂x’ⱼ

This lets you use gradient observations to improve predictions, especially when gradient observations are cheaper than function observations.

How It Works

Usage: Create with a base kernel (RBF, Matern, etc.) that supports gradients. The resulting kernel operates on extended vectors: [x; gradient_dim_flag; is_gradient_obs].

Constructors

Constructor Summary
GradientKernel(int inputDim, GradientKernelType<T> kernelType, double lengthScale, double outputScale) Initializes a new GradientKernel.

Properties

Property Summary
GradientKernelType<T> KernelType { get; } Gets the kernel type.
IKernelFunction<T> BaseKernel { get; } Gets the base kernel.
double LengthScale { get; } Gets the length scale.
int InputDim { get; } Gets the input dimensionality.

Methods

Method Summary
T Calculate(Vector<T> x1, Vector<T> x2) Calculates the kernel value between two points (value-value, value-gradient, or gradient-gradient).
Vector<T> CreateGradientObservation(Vector<T> input, int gradientDim) Creates an extended vector for a gradient observation.
Vector<T> CreateValueObservation(Vector<T> input) Creates an extended vector for a value observation.