Skip to main content

FactorSet

Struct FactorSet 

Source
pub struct FactorSet {
    pub m: usize,
    pub n: usize,
    pub k: usize,
    pub u_data: Vec<f32>,
    pub s_data: Vec<f32>,
    pub v_data: Vec<f32>,
}
Expand description

Low-rank factor representation for reconstruction.

Stores U (m x k), S (k), V (k x n) such that data ~ U * diag(S) * V. All matrices are row-major.

Fields§

§m: usize§n: usize§k: usize§u_data: Vec<f32>§s_data: Vec<f32>§v_data: Vec<f32>

Implementations§

Source§

impl FactorSet

Source

pub fn reconstruct(&self) -> Vec<f32>

Reconstruct the full data from factors: U * diag(S) * V.

Source

pub fn storage_bytes(&self) -> usize

Compute storage size in bytes: (mk + k + kn) * 4.

Source

pub fn from_data(data: &[f32], rows: usize, cols: usize, rank: usize) -> Self

Create from a flat data vector using truncated SVD via power iteration.

Simplified implementation suitable for moderate-sized matrices. Extracts top-rank singular triplets with successive deflation.

§Panics

Panics if data.len() != rows * cols.

Source

pub fn reconstruction_error(&self, original: &[f32]) -> f32

Compute the relative reconstruction error (Frobenius norm).

Returns ||original - reconstructed|| / ||original||. Returns 0.0 if the original has zero norm.

Source

pub fn energy_captured(&self, original: &[f32]) -> f32

Estimate the fraction of total energy (Frobenius norm) captured by factors.

Uses sum(s_i^2) as captured energy. Requires the original data to compute total energy as ||data||_F^2. Returns 1.0 if total energy is near zero.

Source

pub fn compression_ratio(&self, original_elements: usize) -> f32

Compression ratio: original_elements * 4 bytes / storage_bytes.

Returns 0.0 if storage_bytes is zero.

Source

pub fn from_data_adaptive( data: &[f32], rows: usize, cols: usize, max_rank: usize, target_error: f32, ) -> Self

Create factors with adaptive rank selection.

Starts with rank 1 and increases until either max_rank is reached or the reconstruction error falls below target_error.

Trait Implementations§

Source§

impl Clone for FactorSet

Source§

fn clone(&self) -> FactorSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FactorSet

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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