pub struct LowRankApprox {
pub rank: usize,
pub u: Array2<f32>,
pub vt: Array2<f32>,
pub singular_values: Array1<f32>,
pub reconstruction_error: f32,
}Expand description
Low-rank approximation W ≈ U @ diag(S) @ V^T computed via pure-Rust power iteration (no LAPACK / C dependencies).
Fields§
§rank: usizeTarget rank
u: Array2<f32>Left singular vectors — shape (rows, rank)
vt: Array2<f32>Right singular vectors (transposed) — shape (rank, cols)
singular_values: Array1<f32>Singular values — shape (rank,)
reconstruction_error: f32Relative Frobenius reconstruction error ||W - approx||_F / ||W||_F
Implementations§
Source§impl LowRankApprox
impl LowRankApprox
Sourcepub fn compute(
w: &Array2<f32>,
rank: usize,
num_iter: usize,
) -> ModelResult<Self>
pub fn compute( w: &Array2<f32>, rank: usize, num_iter: usize, ) -> ModelResult<Self>
Compute a rank-rank approximation of w using power iteration.
num_iter controls the number of power-iteration steps per component.
Higher values give more accurate singular vectors.
Sourcepub fn reconstruct(&self) -> ModelResult<Array2<f32>>
pub fn reconstruct(&self) -> ModelResult<Array2<f32>>
Reconstruct the full matrix: U @ diag(S) @ V^T.
Sourcepub fn compression_ratio(&self) -> f32
pub fn compression_ratio(&self) -> f32
Compression ratio: (rows * cols) / (rows * rank + rank * cols).
Trait Implementations§
Source§impl Clone for LowRankApprox
impl Clone for LowRankApprox
Source§fn clone(&self) -> LowRankApprox
fn clone(&self) -> LowRankApprox
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for LowRankApprox
impl RefUnwindSafe for LowRankApprox
impl Send for LowRankApprox
impl Sync for LowRankApprox
impl Unpin for LowRankApprox
impl UnsafeUnpin for LowRankApprox
impl UnwindSafe for LowRankApprox
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more