lazymatrix::ColumnStats
LazyMatrix for Rust · 0.8.1
pub trait ColumnStats<F: Scalar>: MatrixErrorTypeColumn-wise statistics of a design matrix, returned as plain Vec<F> of length ncols.
Implemented per backend so that sparse matrices compute these by walking stored entries — structurally absent entries are treated as zero — without ever densifying a column.
All means and standard deviations use the population convention (divide by n, the number of rows), matching the design-matrix normalization used by the R lazymatrix package.
Statistics follow IEEE floating-point behavior. In particular, means, standard deviations, minima, and ranges of a zero-row column are NaN; un-centered norms of a zero-row column are zero; and a stored NaN propagates through every statistic. Each method returns the backend error if reading or decoding the data fails.
Methods
col_l1
fn col_l1(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column 1-norms ‖x_j‖₁ of the un-centered column.
col_l1_centered
fn col_l1_centered(
&self,
centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column 1-norms of the centered columns, ‖x_j − c_j·1‖₁.
Computed sparsely via the closed form Σ_stored |v − c_j| + (n − nnz_j)·|c_j|, so it never densifies. centers must have length ncols.
col_l2
fn col_l2(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column 2-norms ‖x_j‖₂ of the un-centered column.
col_l2_centered
fn col_l2_centered(
&self,
centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column 2-norms of the centered columns, ‖x_j − c_j·1‖₂.
Computed sparsely via the closed form ‖x_j − c_j‖₂² = Σ_stored (v − c_j)² + (n − nnz_j)·c_j², so it never densifies. centers must have length ncols.
col_maxabs
fn col_maxabs(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column max-absolute values max_i |x_ij| of the un-centered column.
col_maxabs_centered
fn col_maxabs_centered(
&self,
centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column max-absolute values of the centered columns, max_i |x_ij − c_j|.
The implicit zero entries contribute |c_j|, folded in alongside the stored-entry maxima. centers must have length ncols.
col_means
fn col_means(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column means c_j = (Σ_i x_ij) / n.
col_mins
fn col_mins(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column minima min_i x_ij of the un-centered column.
col_ranges
fn col_ranges(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column ranges max_i x_ij - min_i x_ij of the un-centered column.
col_sds
fn col_sds(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>Column population standard deviations √(Σ_i (x_ij − c_j)²/n).
Centering-invariant, so this is also the standard deviation of the centered column. Implementations use a stable two-pass calculation.
normalization_stats
fn normalization_stats(
&self,
spec: Normalization
) -> Result<lazymatrix::NormalizationStats<F>, <Self as MatrixErrorType>::Error>Compute the centers and raw scales requested by spec.
Backends may override this hook to share scans between statistics. Exact zero scales are returned unchanged; crate::LazyMatrix::new replaces them with one. Each present vector must have length ncols.
Errors
Returns the first error encountered while computing the statistics.
Implementation of ColumnStats
impl<A: ZarrArray<F>, F: Scalar> ColumnStats<F> for lazymatrix::ZarrMatrix<A, F>Implementation of ColumnStats
impl<M, F, T> ColumnStats<F> for EagerMatrix<M, T> where M: ColumnStats<F>, F: ScalarImplementation of ColumnStats
impl<M: ColumnStats<F>, F: Scalar> ColumnStats<F> for SprsCsc<M>Implementation of ColumnStats
impl<M: ColumnStats<F>, F: Scalar> ColumnStats<F> for SprsCsr<M>
