pub struct SvdRec<T> {
pub d: usize,
pub u: Array2<T>,
pub s: Array1<T>,
pub vt: Array2<T>,
pub total_squared_norm: T,
pub diagnostics: Diagnostics<T>,
}Expand description
A singular value decomposition.
§Orientation
A ≈ u · diag(s) · vt, matching the numpy.linalg.svd / scipy convention:
uism × d— left singular vectors are columnssisd, descendingvtisd × n— right singular vectors are rows
In 1.x this was inconsistent: the Lanczos path returned u transposed (d × m)
while the randomized path returned it as m × d, so SvdRec::recompose only
worked for square inputs. Both paths now follow the convention above.
Fields§
§d: usizeNumber of singular triplets returned.
u: Array2<T>Left singular vectors, m × d.
s: Array1<T>Singular values, length d, descending.
vt: Array2<T>Transposed right singular vectors, d × n.
total_squared_norm: T‖A‖²_F of what was decomposed — the centered matrix if the solver was centering.
Recorded because a truncated result can’t recover it: Σᵢ sᵢ² over the returned
d values is only the part that was kept, not the tail it’s measured against.
diagnostics: Diagnostics<T>Implementations§
Source§impl<T: SvdFloat> SvdRec<T>
impl<T: SvdFloat> SvdRec<T>
Sourcepub fn recompose(&self) -> Array2<T>
pub fn recompose(&self) -> Array2<T>
Rebuild the dense approximation u · diag(s) · vt.
Allocates an m × n dense matrix — only reasonable for small inputs or for
checking reconstruction error in tests.
Sourcepub fn converged(&self) -> bool
pub fn converged(&self) -> bool
Whether an iterative method reached its tolerance.
Always true for the randomized methods — they do a fixed amount of work and have
no convergence test. For IRLBA it’s real: false means the restart budget ran out.
IRLBA refuses to return such a result by default, so this only matters if you
called allow_unconverged.
Sourcepub fn max_residual(&self) -> Option<T>
pub fn max_residual(&self) -> Option<T>
Largest ‖A·vᵢ − σᵢ·uᵢ‖ over the returned triplets, for algorithms that track it.
Judge it against s[0]: 1e-9 · σ_max is excellent, 0.1 · σ_max is unusable.
Sourcepub fn scores(&self) -> Array2<T>
pub fn scores(&self) -> Array2<T>
PCA scores, u · diag(s), shaped m × d — the embedding you’d cluster or plot.
Sourcepub fn explained_variance(&self) -> Array1<T>
pub fn explained_variance(&self) -> Array1<T>
sᵢ² / (m − 1), matching sklearn’s explained_variance_. Only a variance in the
statistical sense if the decomposition was centered.
Sourcepub fn explained_variance_ratio(&self) -> Array1<T>
pub fn explained_variance_ratio(&self) -> Array1<T>
Fraction of the total squared norm each component captures. Sums to at most 1,
and to zero (not NaN) for an all-zero input.
Sourcepub fn total_variance(&self) -> T
pub fn total_variance(&self) -> T
‖A‖²_F / (m − 1) — the same scale as
explained_variance.
Trait Implementations§
impl<T: PartialEq> StructuralPartialEq for SvdRec<T>
Auto Trait Implementations§
impl<T> Freeze for SvdRec<T>where
T: Freeze,
impl<T> RefUnwindSafe for SvdRec<T>where
T: RefUnwindSafe,
impl<T> Send for SvdRec<T>where
T: Send,
impl<T> Sync for SvdRec<T>where
T: Sync,
impl<T> Unpin for SvdRec<T>where
T: Unpin,
impl<T> UnsafeUnpin for SvdRec<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for SvdRec<T>where
T: UnwindSafe + RefUnwindSafe,
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