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
impl FactorSet
Sourcepub fn reconstruct(&self) -> Vec<f32>
pub fn reconstruct(&self) -> Vec<f32>
Reconstruct the full data from factors: U * diag(S) * V.
Sourcepub fn storage_bytes(&self) -> usize
pub fn storage_bytes(&self) -> usize
Compute storage size in bytes: (mk + k + kn) * 4.
Sourcepub fn from_data(data: &[f32], rows: usize, cols: usize, rank: usize) -> Self
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.
Sourcepub fn reconstruction_error(&self, original: &[f32]) -> f32
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.
Sourcepub fn energy_captured(&self, original: &[f32]) -> f32
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.
Sourcepub fn compression_ratio(&self, original_elements: usize) -> f32
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.