circuits-pca
Safe HaskellNone
LanguageGHC2024

Circuit.PCA

Description

Principal component analysis as optic residual ownership over harpie arrays.

Pipeline (see circuits examples/pca.md):

center → dagger-compose (Gram / SVD of centered data) → spectral cut
      → Optic (,) with major = focus, minor = owned residual

Dagger from circuits promises reverse wires; here reverse is matrix transpose and the spectral cut is hmatrix. The keep/discard protocol is Lens — hinge table cell A (own + finite residual).

'circuits-ad' is a sibling dependency for reverse-mode work on surrounding nets; this module does not yet differentiate through the spectral cut.

Synopsis

Model

data PCAModel Source #

Fitted PCA: column means, loadings (features × k), singular values.

Constructors

PCAModel 

Fields

Instances

Instances details
Show PCAModel Source # 
Instance details

Defined in Circuit.PCA

fit :: Int -> Array Double -> PCAModel Source #

Fit PCA with k components via thin SVD of centered data.

Data shape: samples × features. Uses right singular vectors as loadings (same subspace as eigendecomposition of the feature Gram).

fitSVD :: Int -> Array Double -> PCAModel Source #

Explicit SVD path (BLAS via hmatrix).

Project / reconstruct (optic face)

scores :: PCAModel -> Array Double -> Array Double Source #

Project centered rows to k-dimensional scores. Shape: samples × k.

reconstruct :: PCAModel -> Array Double -> Array Double Source #

Reconstruct data from scores: scores × components† + mean.

projectRows :: PCAModel -> Array Double -> Array Double Source #

Full project-through-model: reconstruct . scores.

Single-row optic

rowLens :: PCAModel -> Lens (Vector Double) (Vector Double) (Vector Double) (Vector Double) Source #

Product optic on one ambient row.

Focus = major scores (k); residual = reconstruction error in ambient space (owned). put replaces scores and re-adds the previous residual.

viewMajor :: PCAModel -> Vector Double -> Vector Double Source #

View major scores of one row.

setMajor :: PCAModel -> Vector Double -> Vector Double -> Vector Double Source #

Set major scores of one row (residual error held from row).

Re-exports