circuits-pca
Safe HaskellNone
LanguageGHC2024

Circuit.PCA.Diff

Description

Differentiable PCA operations.

The fitted PCAModel is treated as constant: this module differentiates through the use of a PCA (centering, projection, reconstruction, loss), not yet through the spectral fit itself.

Each operation is packaged as a Diff arrow, so it composes with the rest of the circuits-ad stack.

Synopsis

Differentiable linear maps

scoresD :: PCAModel -> Diff' (Array Double) (Array Double) Source #

Differentiable scores: center, then project onto principal axes.

reconstructD :: PCAModel -> Diff' (Array Double) (Array Double) Source #

Differentiable reconstruction from scores.

projectRowsD :: PCAModel -> Diff' (Array Double) (Array Double) Source #

Full differentiable project-through-model: reconstruct . scores.

Differentiable loss

reconstructionLossD :: PCAModel -> Diff' (Array Double) Double Source #

Mean-squared reconstruction error, differentiable with respect to the input array.

Forward: loss = (1/n) * ||x - projectRows model x||² Pullback: dlossdx = (2n) * (x - projectRows model x)