gpmp.kernel covariance functions¶
Covariance functions accept gpmp.num arrays and covariance-parameter
vectors. They can be passed directly to gpmp.core.Model.
gpmp.parameter objects are optional display objects and are not part of the
covariance-function call signature.
The covariance functions documented here define stationary anisotropic covariances of the form
where \(\sigma^2\) is the process variance, \(\rho_j\) are coordinate lengthscales, \(h_\rho\) is the scaled Euclidean distance, and \(r_\eta\) is a correlation kernel. This is the covariance function used in kriging / Gaussian-process interpolation; see Chilès and Delfiner [1], Stein [13] for covariance choice, regularity, and lengthscales in spatial interpolation.
Correlation kernels and covariance functions¶
Correlation kernels take a scaled distance h and return a correlation
value. They do not include the variance parameter. The public correlation
kernels are exponential_kernel, squared_exponential_kernel,
matern12_kernel, matern32_kernel, matern52_kernel,
maternp_kernel, and matern_kernel.
Covariance functions take point arrays and a covariance-parameter vector. They
include the process variance and the coordinate scaling. The covariance
functions documented here are squared_exponential_covariance,
maternp_covariance, and matern_covariance.
Scaled-distance convention¶
For anisotropic covariance functions, covparam stores
loginvrho_j = -log(rho_j). For points
\(x, y \in \mathbb{R}^d\), GPmp uses
The scaled squared distance is
Thus a larger stored value loginvrho_j means a shorter lengthscale in
coordinate j. The same convention is used by the fixed-regularity Matérn,
continuous-regularity Matérn, and squared-exponential covariance functions.
Self-covariance matrix functions add a small numerical nugget \(10 \sigma^2 \epsilon_{\mathrm{mach}}\) on the diagonal. This is a linear-algebra safeguard, not an observation-noise model.
Squared-exponential scaling¶
The squared-exponential kernel follows the same scaling convention as the
Matérn kernels. If h is the scaled distance, GPmp uses
Equivalently,
GPmp does not use the alternative exp(-0.5 * h**2) convention. This choice
makes the squared-exponential kernel consistent with the
continuous-regularity Matérn implementation, whose large-nu limit is
exp(-h**2) under the GPmp scaling.
Fixed-regularity Matérn covariance¶
maternp_covariance uses the sigma2_rho convention
[log(sigma2), -log(rho_0), ..., -log(rho_{d-1})].
The regularity is fixed by the integer p with
\(\nu = p + 1/2\). GPmp evaluates the half-integer Matérn correlation as
The closed forms matern12_kernel, matern32_kernel, and
matern52_kernel are provided for the common cases p = 0, p = 1,
and p = 2:
The covariance is then
Continuous-regularity Matérn covariance¶
matern_covariance uses the sigma2_nu_rho convention
[log(sigma2), log(nu), -log(rho_0), ..., -log(rho_{d-1})].
Here nu is optimized or supplied as part of the covariance-parameter vector.
This convention requires an initializer and selection method that know about the
extra log(nu) component.
For \(\nu > 0\), the continuous-regularity Matérn correlation is
where \(K_\nu\) is the modified Bessel function of the second kind. The covariance is
Under this scaling, \(r_\nu(h)\) tends to \(\exp(-h^2)\) as \(\nu \to \infty\), which explains the squared-exponential convention used in GPmp. The regularity parameter controls mean-square smoothness of the GP and is a central parameter in Matérn modeling [13].
The backend-dependent evaluation policy, the Torch derivatives, and the
nodes, t_max, and large_nu_method arguments are documented in
Numerical evaluation of the Matérn covariance. Normal model construction and parameter
selection use the default large_nu_method="auto" policy.
Squared-exponential covariance summary¶
squared_exponential_covariance uses the sigma2_rho convention
[log(sigma2), -log(rho_0), ..., -log(rho_{d-1})].
Under the GPmp distance scaling, the correlation is exp(-q), where q is
the scaled squared distance.
Function reference¶
exponential_kernel¶
- gpmp.kernel.exponential_kernel(h)[source]
Exponential kernel.
\[k(h) = \exp(-h)\]- Parameters:
h (array_like) – Scaled distances.
- Returns:
Correlation values with the same backend as
h.- Return type:
array_like
squared_exponential_kernel¶
- gpmp.kernel.squared_exponential_kernel(h)[source]¶
Squared-exponential kernel.
\[k(h) = \exp(-h^2)\]The argument
his the scaled distance used by the GPmp Matérn kernels. With this convention the squared-exponential kernel is the limiting case of the continuous-regularity Matérn kernel. GPmp therefore usesexp(-h**2), not the alternativeexp(-0.5 * h**2)convention.- Parameters:
h (array_like) – Scaled distances between points.
- Returns:
Correlation values with the same backend as
h.- Return type:
array_like
squared_exponential_covariance¶
- gpmp.kernel.squared_exponential_covariance(x, y, param, pairwise=False)[source]¶
Squared-exponential covariance.
paramfollows the convention[log(sigma2), -log(rho_0), ..., -log(rho_{d-1})]. The correlation term isexp(-q), whereqis the scaled squared distance associated with this covariance-parameter convention.- Parameters:
x (array_like, shape (nx, d)) – First set of points.
y (array_like or None) – Second set of points. If
yisNoneory is x, the self-covariance ofxis returned.param (array_like, shape (d + 1,)) – Covariance parameters
[log(sigma2), -log(rho_0), ..., -log(rho_{d-1})].pairwise (bool, optional) – If True, return elementwise covariances. If False, return a full covariance matrix.
- Returns:
Covariance matrix or vector, depending on
pairwise.- Return type:
array_like
matern12_kernel¶
matern32_kernel¶
matern52_kernel¶
maternp_kernel¶
- gpmp.kernel.maternp_kernel(p: int, h)[source]¶
Matérn kernel with half-integer regularity \(\nu = p + 1/2\).
Using the half-integer simplification from Watson (1922) and Abramowitz and Stegun:
\[K(h) = \exp(-2\sqrt{\nu}\,h)\, \frac{\Gamma(p+1)}{\Gamma(2p+1)} \sum_{i=0}^{p} \frac{(p+i)!}{i!(p-i)!}\,(4\sqrt{\nu}h)^{\,p-i}\]- Parameters:
p (int) – Nonnegative integer with \(\nu = p+1/2\).
h (array_like) – Scaled distances.
- Returns:
Correlation values with the same backend as
h.- Return type:
array_like
maternp_covariance¶
matern_kernel¶
- gpmp.kernel.matern_kernel(nu, h, *, nodes: int = 160, t_max: float = 20.0, large_nu_method: str = 'auto')[source]¶
Matérn kernel with continuous regularity
nu.hfollows the same scaled-distance convention asmaternp_kernel. Internally, the continuous Matérn primitive uses the standardsqrt(2 * nu) * rparameterization, so the squared distance is multiplied by two for compatibility with the existing GPmp half-integer kernels.- Parameters:
nu (scalar or array_like) – Positive Matérn regularity parameter.
h (scalar or array_like) – Scaled distance.
nodes (int, optional) – Base number of quadrature nodes used by the Torch backend. NumPy accepts this argument for API consistency, but it has no effect.
t_max (float, optional) – Base upper integration limit for adaptive Torch quadrature.
large_nu_method (str, optional) – Numerical evaluation policy. In both backends, the default
"auto"uses a uniform expansion for scalarnu >= 70. Below this threshold, NumPy uses SciPy, while Torch selects among exact formulas, calibrated recurrences, and quadrature."quadrature"forces the SciPy path in NumPy and quadrature in Torch. Explicit"uniform_asymptotic"requires scalarnu >= 70.
- Returns:
Matérn correlation values.
- Return type:
scalar or array_like
matern_covariance¶
- gpmp.kernel.matern_covariance(x, y, param, pairwise=False, *, nodes: int = 160, t_max: float = 20.0, large_nu_method: str = 'auto')[source]¶
Matérn covariance with continuous regularity.
paramfollows the convention[log(sigma2), log(nu), -log(rho_0), ..., -log(rho_{d-1})].- Parameters:
x (array_like, shape (nx, d)) – First set of points.
y (array_like or None) – Second set of points. If
yisNoneory is x, the self-covariance ofxis returned.param (array_like, shape (d + 2,)) – Covariance parameters
[log(sigma2), log(nu), -log(rho_0), ..., -log(rho_{d-1})].pairwise (bool, optional) – If True, return elementwise covariances. If False, return a full covariance matrix.
nodes (int, optional) – Base number of quadrature nodes used by the Torch backend. NumPy accepts this argument for API consistency, but it has no effect.
t_max (float, optional) – Base upper integration limit for adaptive Torch quadrature.
large_nu_method (str, optional) – Numerical evaluation policy. In both backends, the default
"auto"uses a uniform expansion for scalarnu >= 70. Below this threshold, NumPy uses SciPy, while Torch selects among exact formulas, calibrated recurrences, and quadrature."quadrature"forces the SciPy path in NumPy and quadrature in Torch. Explicit"uniform_asymptotic"requires scalarnu >= 70.
- Returns:
Covariance matrix or vector, depending on
pairwise.- Return type:
array_like
Notes
"quadrature"selects the backend reference path used to validate the automatic large-order branch near its switching threshold.