geoml.kernels

Covariance functions. A kernel is handed to a GP node together with a transform, which is what carries the ranges and the anisotropy: the kernel says how correlation falls with distance, and the transform says what distance means.

class geoml.kernels.Gaussian[source]

Bases: _Kernel

Gaussian kernel.

exp(-3 d**2) of the distance measured in ranges, so the correlation falls to 5% at one range. Infinitely differentiable: the smoothest field of the kernels here, and the one for gently varying quantities and structural surfaces.

kernelize(x)[source]
class geoml.kernels.Spherical(epsilon=1e-12)[source]

Bases: _Kernel

Spherical kernel.

The geostatistical classic, 1 - 1.5 d + 0.5 d**3 of the distance in ranges and zero past one range. Continuous but not differentiable at the origin, so the field is rough at short scale, as a grade usually is.

kernelize(x)[source]
class geoml.kernels.Exponential(epsilon=1e-12)[source]

Bases: _Kernel

Exponential kernel.

exp(-3 d) of the distance in ranges, falling to 5% at one range. The roughest of the kernels here: continuous, never differentiable.

kernelize(x)[source]
class geoml.kernels.Cubic[source]

Bases: _Kernel

Cubic kernel.

A polynomial in the distance in ranges that reaches zero at one range and stays there, as the spherical does, while staying smooth at the origin: a compactly supported stand-in for the Gaussian.

kernelize(x)[source]
class geoml.kernels.Constant[source]

Bases: _Kernel

Constant kernel.

One at every distance: a field that takes one value everywhere. Its matrix has rank one, so it is no kernel for a GP node, whose bias does the same; it is kept for covariances built by hand.

kernelize(x)[source]
implicit_matmul(coordinates)[source]

Implicit matrix-vector multiplication.

Returns a function that multiplies the kernel’s covariance matrix (defined at the given coordinates) with a vector efficiently.

class geoml.kernels.Linear(transform=None)[source]

Bases: _AbstractCovariance

The linear covariance, the dot product of transformed coordinates.

A field that is a linear function of the coordinates, as seen through the transform: a trend, with the transform’s parameters as its slopes. Meant as a term in a Sum of covariances.

__init__(transform=None)[source]
Parameters:

transform (_Transform | None) – An object from the transform module; the identity if left out.

covariance_matrix(x, y)[source]

Computes point-point covariance matrix between x and y tensors.

point_variance(x)[source]

Computes the data points’ self variance (covariance between the point and itself).

implicit_matmul(coordinates)[source]

Implicit matrix-vector multiplication.

Returns a function that multiplies the kernel’s covariance matrix (defined at the given coordinates) with a vector efficiently.

feature_matrix(x)[source]
class geoml.kernels.Cosine[source]

Bases: _Kernel

Cosine kernel.

cos(2 pi d) of the distance in ranges: a field repeating with a period of one range. A valid covariance along one axis only – in two or three dimensions a cosine of the distance is not, and the inducing points’ Cholesky can fail on it – so it is no kernel for a GP node.

kernelize(x)[source]
class geoml.kernels.Sum(*args)[source]

Bases: _NodeCovariance

A weighted sum of covariances, the weights trained and summing to one.

Nested structures, as a variogram model has them: a short range and a long one, or a trend and a residual. The weights share the one unit of variance between the terms.

__init__(*args)[source]
Parameters:

args – The covariances to add up.

class geoml.kernels.Product(*args)[source]

Bases: _NodeCovariance

The product of covariances.

Correlated only where every factor is: a periodic covariance times a decaying one gives a pattern that repeats and fades, and covariances of different coordinates multiply into one over all of them.

__init__(*args)[source]
Parameters:

args – The covariances to multiply.

covariance_matrix_d1(x, y, dir_y)[source]

Computes point-direction covariance matrix between x and y tensors.

covariance_matrix_d2(x, y, dir_x, dir_y)[source]

Computes direction-direction covariance matrix between x and y tensors.

self_covariance_matrix_d2(x, dir_x)[source]
class geoml.kernels.Matern32[source]

Bases: _Kernel

Once differentiable Matérn kernel.

(1 + 5 d) exp(-5 d) of the distance in ranges: rougher than the Gaussian and smoother than the exponential, the usual middle ground for a physical quantity.

kernelize(x)[source]
class geoml.kernels.Matern52[source]

Bases: _Kernel

Twice differentiable Matérn kernel.

(1 + 6 d + 12 d**2) exp(-6 d) of the distance in ranges: one step smoother than Matern32, still short of the Gaussian’s perfect smoothness.

kernelize(x)[source]
class geoml.kernels.RationalQuadratic(scale=1)[source]

Bases: _Kernel

Rational quadratic (a.k.a. Cauchy) kernel.

(1 + 3 d**2 / scale) ** -scale of the distance in ranges: a mixture of Gaussian kernels over many ranges, which gives a long tail of weak correlation. scale is trained; the larger it grows, the closer the kernel comes to the Gaussian.

kernelize(x)[source]
class geoml.kernels.Covariance(kernel, transform=None)[source]

Bases: _AbstractCovariance

Covariance function.

__init__(kernel, transform=None)[source]

Initializer for Covariance.

Parameters:
  • kernel (_Kernel) – A kernel object.

  • transform (_Transform | None) – An object from the transform module; the identity if left out.

covariance_matrix(x, y)[source]

Computes point-point covariance matrix between x and y tensors.

point_variance(x)[source]

Computes the data points’ self variance (covariance between the point and itself).

covariance_matrix_d1(x, y, dir_y)[source]

Computes point-direction covariance matrix between x and y tensors.

covariance_matrix_d2(x, y, dir_x, dir_y)[source]

Computes direction-direction covariance matrix between x and y tensors.

point_variance_d2(x, dir_x)[source]
set_limits(data)[source]
implicit_matmul(coordinates)[source]

Implicit matrix-vector multiplication.

Returns a function that multiplies the kernel’s covariance matrix (defined at the given coordinates) with a vector efficiently.

feature_matrix(x)[source]
class geoml.kernels.Scale(base_covariance)[source]

Bases: _WrapperCovariance

Kernel scaling.

Add a parameter allowing for non-unit variance.

covariance_matrix(x, y)[source]

Computes point-point covariance matrix between x and y tensors.

point_variance(x)[source]

Computes the data points’ self variance (covariance between the point and itself).

covariance_matrix_d1(x, y, dir_y)[source]

Computes point-direction covariance matrix between x and y tensors.

covariance_matrix_d2(x, y, dir_x, dir_y)[source]

Computes direction-direction covariance matrix between x and y tensors.

point_variance_d2(x, dir_x)[source]