pub struct KernelPCA { /* private fields */ }Expand description
Kernel PCA for nonlinear dimensionality reduction
§Example
use scirs2_transform::kernel::{KernelPCA, KernelType};
use scirs2_core::ndarray::Array2;
let data = Array2::<f64>::zeros((50, 10));
let mut kpca = KernelPCA::new(2, KernelType::RBF { gamma: 0.1 });
let embedding = kpca.fit_transform(&data).expect("should succeed");
assert_eq!(embedding.shape(), &[50, 2]);Implementations§
Source§impl KernelPCA
impl KernelPCA
Sourcepub fn new(n_components: usize, kernel: KernelType) -> Self
pub fn new(n_components: usize, kernel: KernelType) -> Self
Create a new KernelPCA instance
§Arguments
n_components- Number of principal components to retainkernel- The kernel function to use
Sourcepub fn with_centering(self, center: bool) -> Self
pub fn with_centering(self, center: bool) -> Self
Set whether to center the kernel matrix (default: true)
Sourcepub fn kernel(&self) -> &KernelType
pub fn kernel(&self) -> &KernelType
Get the kernel type
Sourcepub fn eigenvalues(&self) -> Option<&Array1<f64>>
pub fn eigenvalues(&self) -> Option<&Array1<f64>>
Get the eigenvalues
Sourcepub fn explained_variance_ratio(&self) -> Option<&Array1<f64>>
pub fn explained_variance_ratio(&self) -> Option<&Array1<f64>>
Get the explained variance ratio
Sourcepub fn alphas(&self) -> Option<&Array2<f64>>
pub fn alphas(&self) -> Option<&Array2<f64>>
Get the principal axes (eigenvectors scaled by 1/sqrt(eigenvalue))
Sourcepub fn fit_transform<S>(&mut self, x: &ArrayBase<S, Ix2>) -> Result<Array2<f64>>
pub fn fit_transform<S>(&mut self, x: &ArrayBase<S, Ix2>) -> Result<Array2<f64>>
Fit and transform in one step
Sourcepub fn inverse_transform(
&self,
projected: &Array2<f64>,
max_iter: usize,
tol: f64,
) -> Result<Array2<f64>>
pub fn inverse_transform( &self, projected: &Array2<f64>, max_iter: usize, tol: f64, ) -> Result<Array2<f64>>
Pre-image estimation: approximate reconstruction from kernel space to input space
Uses an iterative fixed-point method (Mika et al., 1998; Kwok & Tsang, 2004) to find an approximate pre-image for the kernel PCA projection.
§Arguments
projected- Projected data in kernel PCA space, shape (n_samples, n_components)max_iter- Maximum number of iterations for the fixed-point methodtol- Convergence tolerance
§Returns
- Approximate reconstruction in input space, shape (n_samples, n_features)
Sourcepub fn auto_select_gamma<S>(
x: &ArrayBase<S, Ix2>,
n_components: usize,
gamma_values: &[f64],
preimage_iter: usize,
) -> Result<(f64, f64)>
pub fn auto_select_gamma<S>( x: &ArrayBase<S, Ix2>, n_components: usize, gamma_values: &[f64], preimage_iter: usize, ) -> Result<(f64, f64)>
Automatic kernel parameter selection via grid search
Tries multiple gamma values and selects the one that minimizes the reconstruction error (for RBF/Laplacian kernels).
§Arguments
x- Input data, shape (n_samples, n_features)gamma_values- List of gamma values to trypreimage_iter- Number of pre-image iterations
§Returns
- The best gamma value and corresponding reconstruction error
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KernelPCA
impl RefUnwindSafe for KernelPCA
impl Send for KernelPCA
impl Sync for KernelPCA
impl Unpin for KernelPCA
impl UnsafeUnpin for KernelPCA
impl UnwindSafe for KernelPCA
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.