Table of Contents

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

T

The numeric type for calculations (e.g., float, double).

Inheritance
TransformerBase<T, Matrix<T>, Matrix<T>>
FactorAnalysis<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
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

nComponents int

Number of latent factors. Defaults to 2.

maxIter int

Maximum EM iterations. Defaults to 1000.

tol double

Convergence tolerance. Defaults to 1e-4.

rotation FactorRotation

Factor rotation method. Defaults to None.

randomState int?

Random seed for reproducibility.

columnIndices int[]

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

int

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

FactorRotation

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Fits Factor Analysis using the EM algorithm.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)

Parameters

inputFeatureNames string[]

Returns

string[]

InverseTransformCore(Matrix<T>)

Inverse transformation is not supported for Factor Analysis.

protected override Matrix<T> InverseTransformCore(Matrix<T> data)

Parameters

data Matrix<T>

Returns

Matrix<T>

TransformCore(Matrix<T>)

Transforms the data by computing factor scores.

protected override Matrix<T> TransformCore(Matrix<T> data)

Parameters

data Matrix<T>

Returns

Matrix<T>