Skip to main content

SvdRec

Struct SvdRec 

Source
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:

  • u is m × d — left singular vectors are columns
  • s is d, descending
  • vt is d × 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: usize

Number 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>

Source

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.

Source

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.

Source

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.

Source

pub fn scores(&self) -> Array2<T>

PCA scores, u · diag(s), shaped m × d — the embedding you’d cluster or plot.

Source

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.

Source

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.

Source

pub fn total_variance(&self) -> T

‖A‖²_F / (m − 1) — the same scale as explained_variance.

Source

pub fn nrows(&self) -> usize

Number of rows of the original matrix.

Source

pub fn ncols(&self) -> usize

Number of columns of the original matrix.

Source

pub fn truncate(&mut self, k: usize)

Truncate to the leading k triplets in place.

Trait Implementations§

Source§

impl<T: Clone> Clone for SvdRec<T>

Source§

fn clone(&self) -> SvdRec<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for SvdRec<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for SvdRec<T>

Source§

fn eq(&self, other: &SvdRec<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.