Kernel utilities

Helpers to build, check and precondition kernel matrices. KernelSpec describes how one view is turned into a kernel — linear, RBF, polynomial, or an already precomputed matrix — and is what KernelFusion consumes per view.

The three functions are standalone: center_kernel removes the mean in the reproducing-kernel Hilbert space, normalize_kernel rescales so that K[i, i] = 1, and is_valid_kernel checks symmetry and positive semi-definiteness, which is worth doing before trusting a precomputed matrix.

These names are also re-exported from polyview.fusion and from the package root.

Shared kernel utilities and configuration objects.

class polyview.utils.kernels.KernelSpec(kernel: Literal['linear', 'rbf', 'polynomial', 'precomputed'] | Callable[[numpy.ndarray], numpy.ndarray] = 'rbf', weight: float = 1.0, center: bool = True, normalize: bool = True, kernel_params: dict | None = None, **kwargs)

Bases: object

Configuration for one kernel view.

build(X: numpy.ndarray) → numpy.ndarray

Compute (and preprocess) the kernel matrix for X.

polyview.utils.kernels.center_kernel(K: numpy.ndarray) → numpy.ndarray

Center a kernel matrix in the RKHS.

polyview.utils.kernels.is_valid_kernel(K: numpy.ndarray, tol: float = 1e-06) → bool

Return True if K is a symmetric PSD kernel matrix.

polyview.utils.kernels.normalize_kernel(K: numpy.ndarray, eps: float = 1e-10) → numpy.ndarray

Normalize a kernel so that K[i, i] = 1 for all i.