Expand description
Matrix-level gradient computation for kernel hyperparameter optimization.
This module provides utilities for computing gradients of kernel matrices with respect to hyperparameters, essential for Gaussian Process optimization.
§Overview
When optimizing kernel hyperparameters (e.g., via gradient descent or L-BFGS), we need to compute the gradient of the kernel matrix K with respect to each hyperparameter θ: dK/dθ (an N×N matrix of partial derivatives).
§Supported Kernels
- RBF/Gaussian: dK/dγ (gamma) and dK/dl (length scale)
- Polynomial: dK/dc (constant) and dK/dd (degree, continuous)
- Matérn: dK/dl (length scale) for nu = 0.5, 1.5, 2.5
- Laplacian: dK/dγ (gamma) and dK/dσ (sigma)
- Rational Quadratic: dK/dl (length scale) and dK/dα (alpha)
§Example
use tensorlogic_sklears_kernels::{RbfKernel, RbfKernelConfig};
use tensorlogic_sklears_kernels::gradient::{KernelGradientMatrix, compute_rbf_gradient_matrix};
let kernel = RbfKernel::new(RbfKernelConfig::new(0.5)).unwrap();
let data = vec![
vec![1.0, 2.0],
vec![3.0, 4.0],
vec![5.0, 6.0],
];
let grad_result = compute_rbf_gradient_matrix(&kernel, &data).unwrap();
// grad_result.kernel_matrix is the N×N kernel matrix K
// grad_result.gradient_gamma is dK/dγ (N×N matrix)
// grad_result.gradient_length_scale is dK/dl (N×N matrix)Structs§
- Gradient
Component - A single gradient component with its name and matrix.
- Kernel
Gradient Matrix - Result of computing kernel matrix with gradients.
- Laplacian
Gradient Result - Result of Laplacian gradient computation.
- Matern
Gradient Result - Result of Matérn gradient computation.
- Polynomial
Gradient Result - Result of Polynomial gradient computation.
- Rational
Quadratic Gradient Result - Result of Rational Quadratic gradient computation.
- RbfGradient
Result - Result of RBF gradient computation with specific gradient accessors.
Functions§
- compute_
generic_ gradient_ matrix - Generic function to compute gradient matrix for any kernel with gradient support.
- compute_
laplacian_ gradient_ matrix - Compute the kernel matrix and gradients for a Laplacian kernel.
- compute_
matern_ gradient_ matrix - Compute the kernel matrix and gradients for a Matérn kernel.
- compute_
polynomial_ gradient_ matrix - Compute the kernel matrix and gradients for a Polynomial kernel.
- compute_
rational_ quadratic_ gradient_ matrix - Compute the kernel matrix and gradients for a Rational Quadratic kernel.
- compute_
rbf_ gradient_ matrix - Compute the kernel matrix and gradients for an RBF kernel.
- frobenius_
norm - Compute the Frobenius norm of a matrix: ||A||F = sqrt(sum{i,j} A_{ij}^2).
- is_
symmetric - Check if a gradient matrix is symmetric (as it should be for symmetric kernels).
- trace_
product - Compute the trace of the product of two matrices: tr(A * B).