pub struct LowRankApproximation { /* private fields */ }Expand description
High-level API for low-rank matrix approximation.
Implementations§
Source§impl LowRankApproximation
impl LowRankApproximation
Sourcepub fn new(config: LowRankConfig) -> Self
pub fn new(config: LowRankConfig) -> Self
Create a new approximation engine with the given configuration.
Sourcepub fn approximate_matrix(
&self,
data: &[f64],
rows: usize,
cols: usize,
) -> Result<SvdResult, LowRankError>
pub fn approximate_matrix( &self, data: &[f64], rows: usize, cols: usize, ) -> Result<SvdResult, LowRankError>
Approximate a 2-D matrix stored in row-major order.
Sourcepub fn approximate_matmul(
&self,
a: &[f64],
a_rows: usize,
a_cols: usize,
b: &[f64],
b_rows: usize,
b_cols: usize,
) -> Result<Vec<f64>, LowRankError>
pub fn approximate_matmul( &self, a: &[f64], a_rows: usize, a_cols: usize, b: &[f64], b_rows: usize, b_cols: usize, ) -> Result<Vec<f64>, LowRankError>
Approximate the matrix product A @ B using low-rank factors of A.
Rather than computing the full product C = A B (which is O(a_rows · a_cols · b_cols)),
we approximate A ≈ U Σ Vᵀ (rank-k) and then compute C ≈ (U Σ) (Vᵀ B).
This can be cheaper when rank << min(a_rows, a_cols).
Sourcepub fn is_candidate(&self, rows: usize, cols: usize) -> bool
pub fn is_candidate(&self, rows: usize, cols: usize) -> bool
Return true if this matrix is large enough to be a candidate for
low-rank approximation (based on min_dimension in the config).
Sourcepub fn optimal_rank(singular_values: &[f64], energy_threshold: f64) -> usize
pub fn optimal_rank(singular_values: &[f64], energy_threshold: f64) -> usize
Compute the smallest rank k such that the top-k singular values
capture at least energy_threshold fraction of the total singular energy.
energy_threshold should be in [0, 1]. If the slice is empty the
function returns 0.
Auto Trait Implementations§
impl Freeze for LowRankApproximation
impl RefUnwindSafe for LowRankApproximation
impl Send for LowRankApproximation
impl Sync for LowRankApproximation
impl Unpin for LowRankApproximation
impl UnsafeUnpin for LowRankApproximation
impl UnwindSafe for LowRankApproximation
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 more