circuits-pca
Safe HaskellNone
LanguageGHC2024

Circuit.PCA.Lin

Description

Linear array ops for PCA: center, Gram (dagger-compose), BLAS mult.

Data layout is always samples × features (rows = observations).

The dagger promise used here is the array transpose: covariance on the feature side is X† X via transpose-compose (up to scaling). Spectral work is delegated to hmatrix (same bridge pattern as Harpie.Hmatrix, which is flag-gated in harpie).

Synopsis

Layout

nSamples :: Array Double -> Int Source #

Number of samples (rows).

nFeatures :: Array Double -> Int Source #

Number of features (columns).

Center

columnMeans :: Array Double -> Array Double Source #

Column means as a length-p vector (shape [p]).

centerColumns :: Array Double -> (Array Double, Array Double) Source #

Center columns; returns (centered, means).

Dagger-compose

gramFeatures :: Array Double -> Array Double Source #

Feature Gram matrix X† X (features × features), unnormalised.

Dagger-compose: reverse wire is transpose, compose is BLAS mult. Scale by 1/(n-1) for sample covariance if desired.

BLAS

multM :: Array Double -> Array Double -> Array Double Source #

BLAS matrix multiply for rank-2 arrays.

transpose2 :: Array Double -> Array Double Source #

Rank-2 transpose.

hmatrix bridge

toMatrix :: Array Double -> Maybe (Matrix Double) Source #

Rank-2 storable array → hmatrix (Nothing if not rank 2).

fromMatrix :: Matrix Double -> Array Double Source #

hmatrix → rank-2 storable array.