Kernels

All kernels inherit from lightgp.Kernel and support composition via the +, *, and Scale operators.

kernel = gp.Scale(gp.RBF()) + gp.Scale(gp.Periodic())

Base class

class lightgp.Kernel

Abstract base for all kernels. Subclasses implement compute(), compute_diag(), parameter access, and a printable name().

name() str

Human-readable kernel name (used in repr and composite-kernel display).

num_params() int

Number of learnable log-hyperparameters.

get_params() list[float]

Flat list of log-hyperparameters. Order is fixed per-kernel and matches set_params().

set_params(params: list[float]) None

Overwrite log-hyperparameters from a flat list.

__add__(other: Kernel) Kernel

Return SumKernel(self, other). The result’s parameter list is the concatenation of both.

__mul__(other: Kernel) Kernel

Return ProductKernel(self, other) (elementwise multiply of kernel matrices).

Concrete kernels

class lightgp.RBF(length_scale: float = 1.0, signal_var: float = 1.0)

Radial Basis Function (squared exponential) kernel.

\[k(x, x') = \sigma^2 \exp\!\left(-\tfrac{\|x - x'\|^2}{2\ell^2}\right)\]
Parameters:
  • length_scale – Length scale \(\ell\). Larger values produce smoother fits.

  • signal_var – Signal variance \(\sigma^2\). Controls the prior output amplitude.

class lightgp.Matern(nu: float = 2.5, length_scale: float = 1.0, signal_var: float = 1.0)

Matérn kernel with smoothness parameter \(\nu\).

\[k_{5/2}(r) = \sigma^2 \left(1 + \tfrac{\sqrt{5}\,r}{\ell} + \tfrac{5 r^2}{3 \ell^2}\right)\, \exp\!\left(-\tfrac{\sqrt{5}\,r}{\ell}\right)\]
Parameters:
  • nu – Smoothness; one of 0.5 (rough), 1.5 (once-differentiable), or 2.5 (twice-differentiable).

  • length_scale – As for RBF.

  • signal_var – As for RBF.

class lightgp.Periodic(length_scale: float = 1.0, period: float = 1.0, signal_var: float = 1.0)

Periodic kernel for cyclical signals.

\[k(x, x') = \sigma^2 \exp\!\left( -\tfrac{2 \sin^2(\pi |x-x'| / p)}{\ell^2}\right)\]
Parameters:
  • period – Period p of the pattern.

  • length_scale – Smoothness within one period.

class lightgp.Linear(signal_var: float = 1.0, input_dim: int = 1, offset: float = 0.0)

Linear (dot-product) kernel. Equivalent to Bayesian linear regression when used alone.

\[k(x, x') = \sigma^2 (x - c)^\top (x' - c)\]
Parameters:

offset – Vector offset c (broadcast across dimensions).

Composition

class lightgp.Scale(base: Kernel, scale: float = 1.0)

Wraps a kernel with a learnable scalar output scale exp(log_scale). Adds one log-hyperparameter to the parameter list (prepended in front of the base kernel’s parameters).

\[k_{\text{scaled}}(x, x') = \exp(\text{log\_scale}) \cdot k_{\text{base}}(x, x')\]
class lightgp.SumKernel(a: Kernel, b: Kernel)

\(k(x, x') = k_a(x, x') + k_b(x, x')\). Created by a + b.

class lightgp.ProductKernel(a: Kernel, b: Kernel)

\(k(x, x') = k_a(x, x') \cdot k_b(x, x')\) (elementwise on the kernel matrix). Created by a * b.

Example

A composed kernel for the Mauna Loa CO₂ benchmark (multi-decade rising trend + annual seasonal cycle + medium-term irregularities):

trend = gp.Scale(gp.RBF(length_scale=10.0))
seasonal = gp.Scale(gp.Periodic(period=1.0))
medium = gp.Scale(gp.RBF(length_scale=0.5))
kernel = trend + seasonal + medium
print(kernel.name())
# ((Scale(RBF) + Scale(Periodic)) + Scale(RBF))
print(kernel.num_params())   # 9