pub struct KernelMatrix { /* private fields */ }Expand description
A square kernel matrix (n×n, symmetric positive semi-definite).
All matrix operations are implemented from scratch over Vec<Vec<f64>>.
Implementations§
Source§impl KernelMatrix
impl KernelMatrix
Sourcepub fn new(data: Vec<Vec<f64>>) -> Result<KernelMatrix, AlignmentError>
pub fn new(data: Vec<Vec<f64>>) -> Result<KernelMatrix, AlignmentError>
Construct from a row-major Vec<Vec<f64>>.
Returns Err(AlignmentError::NonSquareMatrix) if any row has a length
different from the number of rows.
Sourcepub fn from_flat(flat: &[f64], n: usize) -> Result<KernelMatrix, AlignmentError>
pub fn from_flat(flat: &[f64], n: usize) -> Result<KernelMatrix, AlignmentError>
Construct from a flat slice of length n*n in row-major order.
Sourcepub fn identity(n: usize) -> KernelMatrix
pub fn identity(n: usize) -> KernelMatrix
Construct the n×n identity kernel matrix.
Sourcepub fn from_labels(labels: &[f64]) -> KernelMatrix
pub fn from_labels(labels: &[f64]) -> KernelMatrix
Construct the “ideal” label kernel:
K[i,j] = 1.0 if labels[i] == labels[j], else -1.0.
This is equivalent to the outer product of the label sign vector and is the target used in KTA for binary or multi-class classification.
Sourcepub fn frobenius_norm_sq(&self) -> f64
pub fn frobenius_norm_sq(&self) -> f64
Compute ||K||_F^2 = sum_{i,j} K[i,j]^2.
Sourcepub fn frobenius_inner(
&self,
other: &KernelMatrix,
) -> Result<f64, AlignmentError>
pub fn frobenius_inner( &self, other: &KernelMatrix, ) -> Result<f64, AlignmentError>
Compute <K1, K2>_F = sum_{i,j} K1[i,j] * K2[i,j].
Returns Err(AlignmentError::DimensionMismatch) if the matrices have
different sizes.
Sourcepub fn center(&self) -> KernelMatrix
pub fn center(&self) -> KernelMatrix
Double-center the kernel matrix: K_c = H * K * H
where H = I - (1/n) * 1*1^T is the centering matrix.
Equivalent to:
K_c[i,j] = K[i,j] - row_mean[i] - col_mean[j] + grand_meanTrait Implementations§
Source§impl Clone for KernelMatrix
impl Clone for KernelMatrix
Source§fn clone(&self) -> KernelMatrix
fn clone(&self) -> KernelMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for KernelMatrix
impl RefUnwindSafe for KernelMatrix
impl Send for KernelMatrix
impl Sync for KernelMatrix
impl Unpin for KernelMatrix
impl UnsafeUnpin for KernelMatrix
impl UnwindSafe for KernelMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more