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
HalfIntegerMaternKernel{P, ND, TL, TD, TP} <: KernelA 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=0gives ν=1/2,P=1gives ν=3/2)ND: Number of input dimensionsTL,TD,TP: Internal types for lengthscales, distance metric, and polynomial
Common Variants
| P | ν | Smoothness | Equivalent |
|---|---|---|---|
| 0 | 1/2 | Not differentiable | Exponential kernel |
| 1 | 3/2 | Once differentiable | — |
| 2 | 5/2 | Twice 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
# 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/∂xSee also: derivative, WendlandKernel
Derivative Kernels
Derivatives of Matérn kernels are computed analytically:
FunctionalGPs.derivative Function
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
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
HalfIntegerMaternKernel: Analytic derivatives via polynomial recurrenceCompactPolynomialKernel: Derivatives of Wendland and compact kernels
See also: DerivativeKernel1D
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.
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)
sourcederivative(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
CompactPolynomialKernelorCompactSignedPolynomialKernel: The derivative of the
CompactPolynomialKernel object.
sourcederivative(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 kerneln: Derivative order with respect to the first argumentm: Derivative order with respect to the second argument
Examples
k = HalfIntegerMaternKernel(2, [1.0]) # Matérn 5/2
dk = derivative(k, 1, 1) # Second mixed derivativeFunctionalGPs.DerivativeKernel1D Type
DerivativeKernel1D{N, M, K, KD} <: KernelA 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 argumentM: Derivative order with respect to the second argumentK: Type of the original kernelKD: Type of the derivative kernel
Fields
original_kernel: The base kernel from which derivatives are takenderivative_kernel: The computed derivative kernel used for evaluationorder1: Derivative orderN(first argument)order2: Derivative orderM(second argument)
Examples
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
Wendland Kernels
Wendland kernels are compactly supported (exactly zero beyond a radius), enabling sparse kernel matrices for large-scale problems.
FunctionalGPs.WendlandKernel Function
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 otherwisewhere p is the Wendland polynomial and ℓ is the lengthscale.
Arguments
d: Spatial dimension (positive integer)k: Smoothness parameter (non-negative integer). The kernel isC^(2k)smooth.lengthscales: (Optional) Scalar or vector of lengthscales. Default is1.0.
Common Choices
| d | k | Smoothness | Use Case |
|---|---|---|---|
| 1 | 1 | C² | 1D regression |
| 1 | 2 | C⁴ | 1D with derivative data |
| 3 | 1 | C² | 3D spatial interpolation |
| 3 | 2 | C⁴ | 3D with smoothness needs |
Examples
# 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
FunctionalGPs.WendlandPolynomial Function
WendlandPolynomial(d::Int, k::Int) -> PolynomialConstruct 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 isC^(2k)smooth)
Returns
A Polynomial with rational coefficients, normalized so p(0) = 1.
Examples
# 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
Compact Kernels
The compact kernel hierarchy provides the foundation for Wendland and other compactly-supported kernels.
Abstract Types
FunctionalGPs.AbstractCompactKernel Type
AbstractCompactKernel{X} <: KernelAbstract 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 radiusk_support(k, x, y): Evaluate the kernel within its support region
Type Parameter
X: Element type of the lengthscale parameter
See also: AbstractCompactRadialKernel, CompactPolynomialKernel
FunctionalGPs.AbstractCompactRadialKernel Type
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 distancer ∈ [0,1]
The k_support method is automatically defined via k_r.
See also: AbstractCompactKernel, CompactPolynomialKernel
FunctionalGPs.AbstractCompactSignedRadialKernel Type
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 lengthscalek_r(k, r): Evaluate the unsigned radial factor forr ∈ [0,1]
The k_support method is automatically defined with the sign factor.
See also: AbstractCompactKernel, CompactSignedPolynomialKernel
Concrete Types
FunctionalGPs.CompactPolynomialKernel Type
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 otherwisewhere poly is the defining polynomial and ℓ is the lengthscale.
Type Parameters
T: Coefficient type of the polynomialX: Element type of the lengthscale
Fields
poly: Polynomial evaluated at normalized distancer ∈ [0,1]lengthscales: Scalar or vector defining the support radius
Constructor
CompactPolynomialKernel(poly::Polynomial, [lengthscales=1.0])Examples
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 CompactPolynomialKernelSee also: WendlandKernel, CompactSignedPolynomialKernel
FunctionalGPs.CompactSignedPolynomialKernel Type
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 otherwiseThis 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 polynomialX: Element type of the lengthscale
Fields
poly: Polynomial evaluated at normalized distancelengthscales: 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