Class FactorAnalysis<T>
- Namespace
- AiDotNet.Preprocessing.DimensionalityReduction
- Assembly
- AiDotNet.dll
Factor Analysis for dimensionality reduction with noise modeling.
public class FactorAnalysis<T> : TransformerBase<T, Matrix<T>, Matrix<T>>, IDataTransformer<T, Matrix<T>, Matrix<T>>
Type Parameters
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
FactorAnalysis<T>
- Implements
- Inherited Members
Remarks
Factor Analysis assumes that the observed data X is generated from a set of latent factors F plus feature-specific noise: X = F * W + noise. Unlike PCA, Factor Analysis explicitly models unique variance (noise) for each feature.
The model assumes: - X = W * F + ε - Where ε ~ N(0, Ψ) and Ψ is diagonal (unique variances) - F ~ N(0, I) are the latent factors
For Beginners: Factor Analysis is like PCA but smarter about noise: - PCA assumes all variance is signal - Factor Analysis separates "common variance" (shared across features) from "unique variance" (noise specific to each feature) - Use when your features have different noise levels - Popular in psychology, social sciences, and survey analysis
Constructors
FactorAnalysis(int, int, double, FactorRotation, int?, int[]?)
Creates a new instance of FactorAnalysis<T>.
public FactorAnalysis(int nComponents = 2, int maxIter = 1000, double tol = 0.0001, FactorRotation rotation = FactorRotation.None, int? randomState = null, int[]? columnIndices = null)
Parameters
nComponentsintNumber of latent factors. Defaults to 2.
maxIterintMaximum EM iterations. Defaults to 1000.
toldoubleConvergence tolerance. Defaults to 1e-4.
rotationFactorRotationFactor rotation method. Defaults to None.
randomStateint?Random seed for reproducibility.
columnIndicesint[]The column indices to use, or null for all columns.
Properties
Components
Gets the factor loadings (each column is a factor).
public double[,]? Components { get; }
Property Value
- double[,]
Mean
Gets the mean of each feature.
public double[]? Mean { get; }
Property Value
- double[]
NComponents
Gets the number of factors.
public int NComponents { get; }
Property Value
NoiseVariance
Gets the unique variance (noise) for each feature.
public double[]? NoiseVariance { get; }
Property Value
- double[]
Rotation
Gets the rotation method.
public FactorRotation Rotation { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits Factor Analysis using the EM algorithm.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]
Returns
- string[]
InverseTransformCore(Matrix<T>)
Inverse transformation is not supported for Factor Analysis.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Transforms the data by computing factor scores.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>