GridKernel<T>

Models & Types · AiDotNet.Kernels

Grid Kernel for exploiting Kronecker structure in regularly-spaced data.

Implements: IKernelFunction<T>

For Beginners

When your input data lies on a regular grid (like pixels in an image, or time series sampled at regular intervals), the kernel matrix has special structure that can be exploited for massive computational savings.

For data on a D-dimensional grid with n_1 × n_2 × … × n_D points: K = K_1 ⊗ K_2 ⊗ … ⊗ K_D (Kronecker product)

This means:

  • Storage: O(sum of n_i) instead of O((product of n_i)²)
  • Matrix-vector multiply: O(product of n_i × sum of n_i) instead of O((product of n_i)²)

Example: 100×100 image grid

  • Full kernel: 10,000 × 10,000 = 100M entries
  • Grid kernel: 100 + 100 = 200 entries (500,000× less memory!)

Limitations:

  • Only works for data on regular grids
  • All dimensions must use the same base kernel (but can have different lengthscales)

Constructors

Constructor Summary
GridKernel(IKernelFunction<T>[] dimensionKernels, Vector<T>[] gridCoordinates) Initializes a Grid Kernel with specified kernels per dimension.

Properties

Property Summary
int NumDimensions { get; } Gets the number of dimensions.
int TotalGridPoints { get; } Gets the total number of grid points.
int[] GridSizes { get; } Gets the grid sizes along each dimension.

Methods

Method Summary
GridKernel<T> WithRBF(Vector<T>[] gridCoordinates, double[] lengthscales) Creates a Grid Kernel with RBF kernels for all dimensions.
T Calculate(Vector<T> x1, Vector<T> x2) Calculates the kernel value between two grid points.
T LogDeterminant() Computes log-determinant using Kronecker structure.
Vector<T> GetEigenvalues() Gets the eigenvalues of the full Kronecker kernel matrix.
Vector<T> KroneckerMultiply(Vector<T> v) Performs efficient matrix-vector product K * v using Kronecker structure.
void Precompute() Precomputes the 1D kernel matrices and their eigendecompositions.