| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
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
- data PCAModel = PCAModel {}
- fit :: Int -> Array Double -> PCAModel
- fitSVD :: Int -> Array Double -> PCAModel
- scores :: PCAModel -> Array Double -> Array Double
- reconstruct :: PCAModel -> Array Double -> Array Double
- projectRows :: PCAModel -> Array Double -> Array Double
- rowLens :: PCAModel -> Lens (Vector Double) (Vector Double) (Vector Double) (Vector Double)
- viewMajor :: PCAModel -> Vector Double -> Vector Double
- setMajor :: PCAModel -> Vector Double -> Vector Double -> Vector Double
- module Circuit.PCA.Optic
- module Circuit.PCA.Lin
Model
Fitted PCA: column means, loadings (features × k), singular values.
Constructors
| PCAModel | |
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).
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.
setMajor :: PCAModel -> Vector Double -> Vector Double -> Vector Double Source #
Set major scores of one row (residual error held from row).
Re-exports
module Circuit.PCA.Optic
module Circuit.PCA.Lin