Expand description
Factor Analysis (FA) via the EM algorithm.
Factor Analysis assumes that data is generated by a linear combination of latent factors plus independent Gaussian noise:
X = W Z + μ + ε, Z ~ N(0, I), ε ~ N(0, diag(ψ))where:
Wis the(n_features × n_components)loading matrix,Zis the(n_components,)latent factor vector,ψis the(n_features,)noise variance vector.
§Algorithm
- Centre the data:
X_c = X - μ. - E-step: compute the posterior mean and covariance of
Z:Σ_z = (I + W^T diag(ψ)⁻¹ W)⁻¹ E[Z | X] = Σ_z W^T diag(ψ)⁻¹ X_c^T - M-step: update
Wandψvia maximum-likelihood closed-form updates. - Repeat until convergence (log-likelihood change <
tol).
§Examples
use ferrolearn_decomp::factor_analysis::FactorAnalysis;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::Array2;
let fa = FactorAnalysis::new(2);
let x = Array2::from_shape_vec(
(10, 4),
(0..40).map(|v| v as f64 * 0.1 + (v % 3) as f64 * 0.5).collect(),
).unwrap();
let fitted = fa.fit(&x, &()).unwrap();
let scores = fitted.transform(&x).unwrap();
assert_eq!(scores.ncols(), 2);Structs§
- Factor
Analysis - Factor Analysis configuration.
- Fitted
Factor Analysis - A fitted Factor Analysis model.