Skip to content

lazymatrix::ColumnStats ​

LazyMatrix for Rust · 0.8.1

Source

rust
pub trait ColumnStats<F: Scalar>: MatrixErrorType

Column-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 ​

rust
fn col_l1(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

Column 1-norms ‖x_j‖₁ of the un-centered column.

col_l1_centered ​

rust
fn col_l1_centered(
    &self,
    centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

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 ​

rust
fn col_l2(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

Column 2-norms ‖x_j‖₂ of the un-centered column.

col_l2_centered ​

rust
fn col_l2_centered(
    &self,
    centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

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 ​

rust
fn col_maxabs(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

Column max-absolute values max_i |x_ij| of the un-centered column.

col_maxabs_centered ​

rust
fn col_maxabs_centered(
    &self,
    centers: &[F]
) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

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 ​

rust
fn col_means(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

Column means c_j = (Σ_i x_ij) / n.

col_mins ​

rust
fn col_mins(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

Column minima min_i x_ij of the un-centered column.

col_ranges ​

rust
fn col_ranges(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

Column ranges max_i x_ij - min_i x_ij of the un-centered column.

col_sds ​

rust
fn col_sds(&self) -> Result<Vec<F>, <Self as MatrixErrorType>::Error>

Source

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 ​

rust
fn normalization_stats(
    &self,
    spec: Normalization
) -> Result<lazymatrix::NormalizationStats<F>, <Self as MatrixErrorType>::Error>

Source

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 ​

Source

rust
impl<A: ZarrArray<F>, F: Scalar> ColumnStats<F> for lazymatrix::ZarrMatrix<A, F>

Implementation of ColumnStats ​

Source

rust
impl<M, F, T> ColumnStats<F> for EagerMatrix<M, T> where M: ColumnStats<F>, F: Scalar

Implementation of ColumnStats ​

Source

rust
impl<M: ColumnStats<F>, F: Scalar> ColumnStats<F> for SprsCsc<M>

Implementation of ColumnStats ​

Source

rust
impl<M: ColumnStats<F>, F: Scalar> ColumnStats<F> for SprsCsr<M>

Released under the MIT and Apache 2.0 licenses.