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#
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.MatrixKernelBaseBuilt-in matrix kernel constructed from coordinates or a precomputed matrix.
Carries only the construction logic on converting coordinates
Sor a user-supplied matrix into_Kon top ofMatrixKernelBase.If you want a bespoke kernel builder (e.g. a custom distance decay, a cross-modality covariance, a learnt operator) subclass
MatrixKernelBasedirectly and implement_build_kernel().See also
MatrixKernel.from_coordinatesRecommended entry point when working from raw sample coordinates.
MatrixKernel.from_matrixRecommended entry point when a kernel or precision matrix is already available.
MatrixKernelBaseBase 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:
- Raises:
ValueError – If
methodis 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,
matrixis treated as the inverse (precision) matrixK^{-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:
Examples
>>> K = np.array([[2, -1], [-1, 2]]) # kernel matrix >>> kernel = MatrixKernel.from_matrix(K, is_precision=False)