splisosm.kernel#

Spatial kernel abstractions.

Classes#

SpatialCovKernel

Graph-based spatial covariance kernel built from spot coordinates.

Module Contents#

class splisosm.kernel.SpatialCovKernel(coords, k_neighbors=4, model='icar', rho=0.99, standardize_cov=True, centering=False, approx_rank=None)#

Bases: Kernel

Graph-based spatial covariance kernel built from spot coordinates.

Parameters:
  • coords (ndarray | Tensor) – Spot coordinates of shape (n_spots, 2).

  • k_neighbors (int) – Number of nearest neighbors used to build the graph.

  • model (Literal['icar', 'car', 'isar', 'sar']) – Spatial process model for inverse covariance construction. Supported values are 'icar', 'car', 'isar', and 'sar'.

  • rho (float) – Spatial autocorrelation coefficient.

  • standardize_cov (bool) – If True, scales covariance to unit marginal variance.

  • centering (bool) – If True, applies centering so row/column sums are approximately zero.

  • approx_rank (int | None) – If provided, computes and stores a rank-approx_rank factorization.

eigendecomposition()#

Compute and store eigendecomposition of the dense kernel.

Raises:

ValueError – If only low-rank kernel factors are stored.

Return type:

None

eigenvalues(k=None)#

Return leading eigenvalues of the kernel matrix.

Parameters:

k (int | None) – Number of leading eigenvalues to return. If None, all available eigenvalues are returned.

Returns:

Eigenvalues sorted in descending order.

Return type:

Tensor

rank()#

Return effective rank of the kernel representation.

Returns:

Kernel rank.

Return type:

int

realization()#

Return the realized dense kernel matrix.

Returns:

Dense matrix of shape (n_spots, n_spots).

Return type:

Tensor

shape()#

Return kernel shape.

Returns:

Pair (n_spots, n_spots).

Return type:

tuple of int

xtKx(x)#

Compute the kernel quadratic form for multivariate inputs.

Parameters:

x (Tensor) – Input matrix of shape (n_spots, d).

Returns:

Quadratic form of shape (d, d).

Return type:

Tensor

K_sp: Tensor | None#

Dense kernel matrix of shape (n_spots, n_spots) when full-rank storage is used. None when low-rank storage is used.

Q: Tensor | None#

Low-rank factor of shape (n_spots, rank) such that K_sp ~= Q @ Q.T. None when full-rank storage is used.

inv_cov: Tensor#

Sparse precision matrix (aka inverse spatial kernel) of shape (n_spots, n_spots).