pub struct GpuPCA {
pub n_components: usize,
pub center: bool,
pub components: Option<Array2<f64>>,
pub explained_variance: Option<Array1<f64>>,
pub mean: Option<Array1<f64>>,
/* private fields */
}Expand description
GPU-accelerated Principal Component Analysis
Fields§
§n_components: usizeNumber of components to compute
center: boolWhether to center the data
components: Option<Array2<f64>>Principal components (loading vectors)
explained_variance: Option<Array1<f64>>Explained variance for each component
mean: Option<Array1<f64>>Mean values for centering
Implementations§
Source§impl GpuPCA
impl GpuPCA
Sourcepub fn fit(&mut self, x: &ArrayView2<'_, f64>) -> Result<()>
pub fn fit(&mut self, x: &ArrayView2<'_, f64>) -> Result<()>
Fit the PCA model using a CPU SVD-based backend.
Currently delegates to the CPU SVD-based PCA implementation. A wgpu-backed Jacobi SVD path is planned for v0.5.
§Arguments
x- Input data matrix with shape (n_samples, n_features)
§Errors
Returns an error if the input is invalid or if n_components exceeds
min(n_samples, n_features).
§Examples
let mut pca = GpuPCA::new(2)?;
let data = Array2::from_shape_vec((5, 4), vec![
1.0, 2.0, 3.0, 4.0,
2.0, 3.0, 4.0, 5.0,
3.0, 4.0, 5.0, 6.0,
4.0, 5.0, 6.0, 7.0,
5.0, 6.0, 7.0, 8.0,
])?;
pca.fit(&data.view())?;
assert!(pca.components.is_some());Sourcepub fn transform(&self, x: &ArrayView2<'_, f64>) -> Result<Array2<f64>>
pub fn transform(&self, x: &ArrayView2<'_, f64>) -> Result<Array2<f64>>
Transform data using the fitted PCA model.
Projects the input data onto the principal components computed during
GpuPCA::fit. Currently runs on the CPU; a wgpu-backed path is
planned for v0.5.
§Arguments
x- Input data matrix with shape (n_samples, n_features)
§Returns
Transformed data matrix with shape (n_samples, n_components)
§Errors
Returns NotFitted if GpuPCA::fit has not been called yet, or
InvalidInput if the number of features does not match.
Sourcepub fn fit_transform(&mut self, x: &ArrayView2<'_, f64>) -> Result<Array2<f64>>
pub fn fit_transform(&mut self, x: &ArrayView2<'_, f64>) -> Result<Array2<f64>>
Fit the PCA model and project data in one step.
Equivalent to calling GpuPCA::fit followed by GpuPCA::transform
on the same data.
§Arguments
x- Input data matrix with shape (n_samples, n_features)
§Returns
Transformed data matrix with shape (n_samples, n_components)
§Errors
Returns any error produced by GpuPCA::fit or GpuPCA::transform.
Sourcepub fn explained_variance_ratio(&self) -> Result<Array1<f64>>
pub fn explained_variance_ratio(&self) -> Result<Array1<f64>>
Get the explained variance ratio for each principal component.
The returned array sums to approximately 1.0 after fitting.
§Returns
Array of explained variance ratios with length n_components
§Errors
Returns NotFitted if GpuPCA::fit has not been called yet.
Auto Trait Implementations§
impl Freeze for GpuPCA
impl !RefUnwindSafe for GpuPCA
impl Send for GpuPCA
impl Sync for GpuPCA
impl Unpin for GpuPCA
impl UnsafeUnpin for GpuPCA
impl !UnwindSafe for GpuPCA
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> 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 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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.