Skip to main content

Module kernel_pca

Module kernel_pca 

Source
Expand description

Kernel Principal Component Analysis (Scholkopf, Smola & Muller, 1998).

This module provides a fully self-contained implementation of Kernel PCA that operates through the crate’s Kernel trait. Any kernel in the crate (RBF, Linear, Polynomial, Symbolic, etc.) can be plugged in; the only additional requirement for fitting is Clone + 'static, which every shipped kernel satisfies.

§Module map

SubmodulePurpose
centeringDouble-centering of the Gram matrix + test-time centering
eigendecompWrapper around scirs2_linalg::eigh for top-k eigenpairs
errorKernelPcaError / KernelPcaResult types
modelKernelPCA, KernelPcaConfig, FittedKernelPCA

§Minimal example

use tensorlogic_sklears_kernels::kernel_pca::{KernelPCA, KernelPcaConfig};
use tensorlogic_sklears_kernels::RbfKernel;
use tensorlogic_sklears_kernels::RbfKernelConfig;

let kernel = RbfKernel::new(RbfKernelConfig::new(1.0)).expect("kernel");
let config = KernelPcaConfig::new(2);
let model = KernelPCA::build(kernel, config).expect("model");

let data = vec![
    vec![1.0, 2.0],
    vec![3.0, 4.0],
    vec![5.0, 6.0],
];
let fitted = model.fit(&data).expect("fit");
let embedding = fitted.transform(&data).expect("transform");
assert_eq!(embedding.nrows(), 3);
assert_eq!(embedding.ncols(), 2);

§References

  • Scholkopf, B., Smola, A. & Muller, K.-R. (1998). Nonlinear Component Analysis as a Kernel Eigenvalue Problem. Neural Computation 10(5), 1299–1319.

Re-exports§

pub use centering::center_test_kernel;
pub use centering::double_center;
pub use centering::KernelCenteringStats;
pub use eigendecomp::symmetric_eigendecomp;
pub use eigendecomp::TopKEigen;
pub use error::KernelPcaError;
pub use error::KernelPcaResult;
pub use model::FittedKernelPCA;
pub use model::KernelPCA;
pub use model::KernelPcaConfig;

Modules§

centering
Double-centering utilities for Kernel PCA.
eigendecomp
Wrappers around scirs2_linalg::eigh tailored to Kernel PCA.
error
Error type for the Kernel PCA research-preview module.
model
The KernelPCA estimator and its fitted counterpart FittedKernelPCA.