Skip to content

Kernels

FunctionalGPs.jl provides specialized kernel implementations optimized for linear functional operations (evaluation, differentiation, integration).

Overview

The kernels module offers:

  • Matérn kernels with half-integer smoothness and analytic derivatives

  • Wendland kernels with compact support for sparse computations

  • Kernel trait system for automatic algorithm selection

All kernels integrate with KernelFunctions.jl and can be used anywhere a Kernel is expected.

Matérn Kernels

The Matérn family provides tunable smoothness via the parameter ν. Half-integer values (ν = 1/2, 3/2, 5/2, ...) admit closed-form expressions.

FunctionalGPs.HalfIntegerMaternKernel Type
julia
HalfIntegerMaternKernel{P, ND, TL, TD, TP} <: Kernel

A Matérn kernel with half-integer smoothness parameter ν = P + 1/2.

The Matérn kernel is a popular choice for GP regression due to its tunable smoothness. Half-integer values of ν admit closed-form expressions as products of exponentials and polynomials, enabling efficient computation and analytic derivatives.

Type Parameters

  • P: Integer such that ν = P + 1/2 (e.g., P=0 gives ν=1/2, P=1 gives ν=3/2)

  • ND: Number of input dimensions

  • TL, TD, TP: Internal types for lengthscales, distance metric, and polynomial

Common Variants

PνSmoothnessEquivalent
01/2Not differentiableExponential kernel
13/2Once differentiable
25/2Twice differentiable

Constructor

HalfIntegerMaternKernel(p::Int, lengthscales)

Create a Matérn kernel with ν = p + 1/2 and the given lengthscales.

Arguments

  • p: Non-negative integer determining smoothness (ν = p + 1/2)

  • lengthscales: Scalar or vector of lengthscales (one per dimension)

Examples

julia
# Matérn-5/2 kernel (twice differentiable) in 1D with lengthscale 1.0
k = HalfIntegerMaternKernel(2, [1.0])
k([0.0], [0.5])  # Evaluate kernel

# Matérn-3/2 in 2D with different lengthscales per dimension
k2d = HalfIntegerMaternKernel(1, [0.5, 1.0])

# Compute derivatives (1D only)
dk = derivative(k, 1, 0)  # ∂k/∂x

See also: derivative, WendlandKernel

source

Derivative Kernels

Derivatives of Matérn kernels are computed analytically:

FunctionalGPs.derivative Function
julia
derivative(k::Kernel, n::Int, m::Int)

Compute the mixed partial derivative kernel ∂ⁿ⁺ᵐk/∂xⁿ∂yᵐ.

Returns a DerivativeKernel1D representing the n-th partial derivative with respect to the first argument and m-th partial derivative with respect to the second argument.

Arguments

  • k: The kernel to differentiate (must support derivatives)

  • n: Derivative order with respect to the first argument (≥ 0)

  • m: Derivative order with respect to the second argument (≥ 0)

Returns

A DerivativeKernel1D{n, m, ...} that can be evaluated like any kernel.

Examples

julia
k = HalfIntegerMaternKernel(2, [1.0])

# First derivative in both arguments: ∂²k/∂x∂y
k11 = derivative(k, 1, 1)

# Second derivative in x only: ∂²k/∂x²
k20 = derivative(k, 2, 0)

# Chained derivatives accumulate orders
k21 = derivative(k11, 1, 0)  # Equivalent to derivative(k, 2, 1)

Supported Kernels

See also: DerivativeKernel1D

source
julia
derivative(k::SqExponentialKernel, n::Int, m::Int)

Compute the mixed partial derivative kernel ∂^(n+m)k/∂x^n∂y^m for a 1D SE kernel.

The derivative has the form: ∂^(n+m)k/∂x^n∂y^m = (-1)^n * He_{n+m}(x-y) * exp(-(x-y)²/2)

where He_n is the n-th probabilist's Hermite polynomial.

Returns a DerivativeKernel1D wrapping either an even or odd derivative kernel.

source
julia
derivative(k::TransformedKernel{<:SqExponentialKernel, <:ScaleTransform}, n::Int, m::Int)

Compute the mixed partial derivative for a scaled SE kernel.

For k_t(x,y) = k(sx, sy) = exp(-s²(x-y)²/2), the derivative is: ∂^(n+m)k_t/∂x^n∂y^m = (-1)^n * s^(n+m) * He_{n+m}(s(x-y)) * exp(-s²(x-y)²/2)

source
julia
derivative(k::CompactPolynomialKernel, n::Int, m::Int)

Compute the derivative of a CompactPolynomialKernel.

Arguments

  • k::CompactPolynomialKernel: The CompactPolynomialKernel object.

  • n::Int: Order along the first argument.

  • m::Int: Order along the second argument.

Returns

  • CompactPolynomialKernel or CompactSignedPolynomialKernel: The derivative of the

CompactPolynomialKernel object.

source
julia
derivative(k::HalfIntegerMaternKernel, n::Int, m::Int)

Compute the mixed partial derivative kernel ∂ⁿ⁺ᵐk/∂xⁿ∂yᵐ for a 1D half-integer Matérn kernel. Returns a DerivativeKernel1D wrapping either an even or odd derivative kernel, depending on the parity of n + m.

Arguments

  • k: The base half-integer Matérn kernel

  • n: Derivative order with respect to the first argument

  • m: Derivative order with respect to the second argument

Examples

julia
k = HalfIntegerMaternKernel(2, [1.0])  # Matérn 5/2
dk = derivative(k, 1, 1)  # Second mixed derivative
source
FunctionalGPs.DerivativeKernel1D Type
julia
DerivativeKernel1D{N, M, K, KD} <: Kernel

A kernel representing the N-th and M-th mixed partial derivative of a 1D kernel.

Given an original kernel k(x, y), this type represents ∂ᴺ⁺ᴹk/∂xᴺ∂yᴹ. The struct wraps both the original kernel and the pre-computed derivative kernel for efficient evaluation.

Type Parameters

  • N: Derivative order with respect to the first argument

  • M: Derivative order with respect to the second argument

  • K: Type of the original kernel

  • KD: Type of the derivative kernel

Fields

  • original_kernel: The base kernel from which derivatives are taken

  • derivative_kernel: The computed derivative kernel used for evaluation

  • order1: Derivative order N (first argument)

  • order2: Derivative order M (second argument)

Examples

julia
k = HalfIntegerMaternKernel(2, [1.0])
dk = derivative(k, 1, 1)  # Returns DerivativeKernel1D{1,1,...}
dk([0.3], [0.7])  # Evaluate ∂²k/∂x∂y at (0.3, 0.7)

See also: derivative, HalfIntegerMaternKernel

source

Wendland Kernels

Wendland kernels are compactly supported (exactly zero beyond a radius), enabling sparse kernel matrices for large-scale problems.

FunctionalGPs.WendlandKernel Function
julia
WendlandKernel(d::Int, k::Int, [lengthscales])

Construct a Wendland compactly-supported kernel.

Wendland kernels are positive-definite, have compact support (exactly zero outside a radius), and tunable smoothness. They enable sparse kernel matrices for large-scale problems.

The kernel is defined as:

k(x, y) = p(‖x - y‖/ℓ)  if ‖x - y‖/ℓ ≤ 1
k(x, y) = 0              otherwise

where p is the Wendland polynomial and is the lengthscale.

Arguments

  • d: Spatial dimension (positive integer)

  • k: Smoothness parameter (non-negative integer). The kernel is C^(2k) smooth.

  • lengthscales: (Optional) Scalar or vector of lengthscales. Default is 1.0.

Common Choices

dkSmoothnessUse Case
111D regression
12C⁴1D with derivative data
313D spatial interpolation
32C⁴3D with smoothness needs

Examples

julia
# Basic Wendland kernel in 1D with C⁴ smoothness
k = WendlandKernel(1, 2)
k([0.0], [0.5])  # Evaluate kernel

# With custom lengthscale
k = WendlandKernel(1, 2, 0.3)

# In 2D with per-dimension lengthscales
k = WendlandKernel(2, 1, [0.5, 1.0])

See also: WendlandPolynomial, CompactPolynomialKernel, HalfIntegerMaternKernel

source
FunctionalGPs.WendlandPolynomial Function
julia
WendlandPolynomial(d::Int, k::Int) -> Polynomial

Construct the polynomial defining a Wendland compactly-supported kernel.

Wendland kernels are a family of positive-definite radial basis functions with minimal polynomial degree for a given smoothness. The resulting kernel is C^(2k) smooth and positive definite in ℝᵈ.

Arguments

  • d: Spatial dimension (determines polynomial degree)

  • k: Smoothness parameter (kernel is C^(2k) smooth)

Returns

A Polynomial with rational coefficients, normalized so p(0) = 1.

Examples

julia
# Polynomial for Wendland kernel in 1D with C² smoothness
p = WendlandPolynomial(1, 1)

# Polynomial for Wendland kernel in 3D with C⁴ smoothness
p = WendlandPolynomial(3, 2)

See also: WendlandKernel

source

Compact Kernels

The compact kernel hierarchy provides the foundation for Wendland and other compactly-supported kernels.

Abstract Types

FunctionalGPs.AbstractCompactKernel Type
julia
AbstractCompactKernel{X} <: Kernel

Abstract base type for compactly-supported kernels.

Compact kernels are exactly zero when inputs are farther apart than a threshold (determined by lengthscales). This enables sparse kernel matrices and efficient computation for large datasets.

Interface

Subtypes must implement:

  • lengthscales(k): Return the lengthscale(s) defining the support radius

  • k_support(k, x, y): Evaluate the kernel within its support region

Type Parameter

  • X: Element type of the lengthscale parameter

See also: AbstractCompactRadialKernel, CompactPolynomialKernel

source
FunctionalGPs.AbstractCompactRadialKernel Type
julia
AbstractCompactRadialKernel{X} <: AbstractCompactKernel{X}

Abstract type for compact radial (isotropic) kernels.

Radial kernels depend only on the distance r = ‖x - y‖/ℓ between inputs. Combined with compact support, these kernels enable both sparsity and efficient stationary-structure optimizations.

Interface

Subtypes must implement:

  • lengthscales(k): Return the lengthscale(s)

  • k_r(k, r): Evaluate the kernel as a function of normalized distance r ∈ [0,1]

The k_support method is automatically defined via k_r.

See also: AbstractCompactKernel, CompactPolynomialKernel

source
FunctionalGPs.AbstractCompactSignedRadialKernel Type
julia
AbstractCompactSignedRadialKernel{X} <: AbstractCompactKernel{X}

Abstract type for compact signed radial kernels.

Signed radial kernels have the form k(x,y) = sign(x-y) · f(|x-y|/ℓ). This structure arises from odd-order derivatives of radial kernels. Primarily used in 1D for derivative kernel representations.

Interface

Subtypes must implement:

  • lengthscales(k): Return the lengthscale

  • k_r(k, r): Evaluate the unsigned radial factor for r ∈ [0,1]

The k_support method is automatically defined with the sign factor.

See also: AbstractCompactKernel, CompactSignedPolynomialKernel

source

Concrete Types

FunctionalGPs.CompactPolynomialKernel Type
julia
CompactPolynomialKernel{T, X} <: AbstractCompactRadialKernel{X}

A compactly-supported kernel defined by evaluating a polynomial on normalized distance.

The kernel is:

k(x, y) = poly(r)  if r = ‖x - y‖/ℓ ≤ 1
k(x, y) = 0        otherwise

where poly is the defining polynomial and is the lengthscale.

Type Parameters

  • T: Coefficient type of the polynomial

  • X: Element type of the lengthscale

Fields

  • poly: Polynomial evaluated at normalized distance r ∈ [0,1]

  • lengthscales: Scalar or vector defining the support radius

Constructor

CompactPolynomialKernel(poly::Polynomial, [lengthscales=1.0])

Examples

julia
using Polynomials

# Custom polynomial kernel: k(r) = 1 - r² for r ≤ 1
p = Polynomial([1, 0, -1])
k = CompactPolynomialKernel(p)

# With lengthscale 0.5 (support radius = 0.5)
k = CompactPolynomialKernel(p, 0.5)

# Wendland kernels are CompactPolynomialKernels
k = WendlandKernel(1, 2)  # Returns a CompactPolynomialKernel

See also: WendlandKernel, CompactSignedPolynomialKernel

source
FunctionalGPs.CompactSignedPolynomialKernel Type
julia
CompactSignedPolynomialKernel{T, X} <: AbstractCompactSignedRadialKernel{X}

A compactly-supported signed kernel defined by a polynomial times sign(x-y).

The kernel is:

k(x, y) = sign(x - y) · poly(|x - y|/ℓ)  if |x - y|/ℓ ≤ 1
k(x, y) = 0                               otherwise

This structure arises from odd-order derivatives of compact polynomial kernels. It is antisymmetric: k(x, y) = -k(y, x).

Type Parameters

  • T: Coefficient type of the polynomial

  • X: Element type of the lengthscale

Fields

  • poly: Polynomial evaluated at normalized distance

  • lengthscales: Scalar or vector defining the support radius

Constructor

CompactSignedPolynomialKernel(poly::Polynomial, [lengthscales=1.0])

Typically constructed via derivative on a CompactPolynomialKernel rather than directly.

See also: CompactPolynomialKernel, derivative

source