quadsv.kernels.matrix#

Built-in concrete matrix kernel.

MatrixKernel is the standard subclass of MatrixKernelBase. It carries the construction logic for turning a coordinate cloud or a precomputed matrix into the underlying _K storage; the algorithm itself (Kx / xtKx / trace / etc.) is inherited unchanged from MatrixKernelBase.

Classes#

MatrixKernel

Built-in matrix kernel constructed from coordinates or a precomputed matrix.

Module Contents#

class quadsv.kernels.matrix.MatrixKernel(data, mode='coords', method='matern', **kwargs)[source]#

Bases: quadsv.kernels.base.MatrixKernelBase

Built-in matrix kernel constructed from coordinates or a precomputed matrix.

Carries only the construction logic on converting coordinates S or a user-supplied matrix into _K on top of MatrixKernelBase.

If you want a bespoke kernel builder (e.g. a custom distance decay, a cross-modality covariance, a learnt operator) subclass MatrixKernelBase directly and implement _build_kernel().

See also

MatrixKernel.from_coordinates

Recommended entry point when working from raw sample coordinates.

MatrixKernel.from_matrix

Recommended entry point when a kernel or precision matrix is already available.

MatrixKernelBase

Base class to inherit from for custom kernel constructions.

Parameters:
  • data (ndarray)

  • mode (str)

  • method (str)

classmethod from_coordinates(coords, method='matern', **kwargs)[source]#

Build kernel from spatial coordinates.

Parameters:
  • coords (np.ndarray) – Array of spatial coordinates, shape (n, D).

  • method (str, default 'matern') – Kernel method. Must be one of ‘gaussian’, ‘matern’, ‘moran’, ‘graph_laplacian’, ‘car’.

  • **kwargs (dict) – Additional kernel parameters (bandwidth, nu, rho, k_neighbors, etc.).

Returns:

Initialized kernel object.

Return type:

MatrixKernel

Raises:

ValueError – If method is not one of _available_kernels.

Examples

>>> coords = np.random.randn(100, 2)
>>> kernel = MatrixKernel.from_coordinates(coords, method='gaussian', bandwidth=1.0)
classmethod from_matrix(matrix, is_precision=False, method='precomputed', **kwargs)[source]#

Build kernel from a precomputed kernel matrix or its inverse.

Parameters:
  • matrix (np.ndarray or scipy.sparse matrix) – Kernel matrix (n, n) or its inverse (precision matrix).

  • is_precision (bool, default False) – If True, matrix is treated as the inverse (precision) matrix K^{-1}.

  • method (str, default 'precomputed') – The logical kernel method (e.g., ‘car’ for precision matrices).

  • **kwargs (dict) – Additional parameters.

Returns:

Initialized kernel object.

Return type:

MatrixKernel

Examples

>>> K = np.array([[2, -1], [-1, 2]])  # kernel matrix
>>> kernel = MatrixKernel.from_matrix(K, is_precision=False)