mixle.models._kernels module

Shared NumPy stationary-kernel primitives (RBF / Matern-3/2 / Matern-5/2).

The RBF and Matern covariance shapes were re-implemented independently in several places (mixle.models.sparse_gaussian_process, mixle.ppl.field, mixle.doe.calibrate), each with its own sqrt(3)/sqrt(5) constants. This module is the single source of those shapes for the NumPy back-end. (The Torch GP in mixle.models.gaussian_process keeps its own autograd kernel – a real back-end difference, not duplication that can be shared here.)

Two layers are provided:

  • shape functions that take an already-lengthscale-scaled distance and return amp**2 * shape – these let callers keep whatever distance/scaling arithmetic they already use (e.g. great-circle chord distance, or scaling the squared distance before vs after the sqrt), so existing numerical results are preserved bit-for-bit;

  • stationary_kernel(), a self-contained (x1, x2, lengthscale, amplitude, name) helper that computes Euclidean pairwise distances and applies the chosen shape (the sparse-GP convention: scale the squared distance by lengthscale**2 before the sqrt).

None of these add a jitter / nugget term – that is a caller concern (the existing call sites use different nugget values: 1e-8 on Kuu, 1e-6 on a field covariance, none on a cross-covariance), so it stays at the call site.

rbf_from_scaled_sqdist(d2_scaled, amplitude)[source]

RBF (squared-exponential) covariance amp**2 * exp(-0.5 * d2_scaled).

d2_scaled is the squared distance already divided by lengthscale**2.

Parameters:
Return type:

ndarray

matern32_from_scaled_dist(r, amplitude)[source]

Matern-3/2 covariance amp**2 * (1 + s) * exp(-s) with s = sqrt(3) * r.

r is the Euclidean distance already divided by the lengthscale.

Parameters:
Return type:

ndarray

matern52_from_scaled_dist(r, amplitude)[source]

Matern-5/2 covariance amp**2 * (1 + s + s**2/3) * exp(-s) with s = sqrt(5) * r.

r is the Euclidean distance already divided by the lengthscale.

Parameters:
Return type:

ndarray

exponential_from_scaled_dist(r, amplitude)[source]

Matern-1/2 / exponential covariance amp**2 * exp(-r) (r already lengthscale-scaled).

Parameters:
Return type:

ndarray

stationary_kernel(x1, x2, lengthscale, amplitude, name)[source]

Pairwise stationary covariance between point sets x1 and x2 (Euclidean inputs).

name is 'rbf', 'matern32' or 'matern52'. The squared distance is divided by lengthscale**2 before the (Matern) sqrt – the sparse-GP convention – with the Matern sqrt floored at 1e-12 so it stays defined at zero separation. No jitter is added.

Parameters:
Return type:

ndarray