Table of Contents

Class ProbabilisticPCA<T>

Namespace
AiDotNet.Preprocessing.DimensionalityReduction
Assembly
AiDotNet.dll

Probabilistic Principal Component Analysis (PPCA).

public class ProbabilisticPCA<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>>
ProbabilisticPCA<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
Inherited Members

Remarks

Probabilistic PCA is a probabilistic formulation of PCA that models data as being generated from a lower-dimensional latent space with added Gaussian noise. This provides a proper likelihood model, enables handling of missing data, and allows for Bayesian extensions.

The model: x = W * z + μ + ε where z ~ N(0, I), ε ~ N(0, σ²I)

The algorithm: 1. Center the data 2. Use EM algorithm or closed-form solution to estimate W and σ² 3. Project data to latent space using posterior mean

For Beginners: PPCA extends standard PCA by: - Providing a probabilistic model for the data - Estimating noise variance σ² separately - Enabling computation of data likelihoods - Handling missing values naturally

Use cases:

  • When you need uncertainty estimates
  • Data with missing values
  • Model comparison using likelihoods
  • Bayesian machine learning pipelines

Constructors

ProbabilisticPCA(int, int, double, int?, int[]?)

Creates a new instance of ProbabilisticPCA<T>.

public ProbabilisticPCA(int nComponents = 2, int maxIter = 100, double tol = 0.0001, int? randomState = null, int[]? columnIndices = null)

Parameters

nComponents int

Target dimensionality. Defaults to 2.

maxIter int

Maximum number of EM iterations. Defaults to 100.

tol double

Tolerance for convergence. Defaults to 1e-4.

randomState int?

Random seed for reproducibility.

columnIndices int[]

The column indices to use, or null for all columns.

Properties

LoadingMatrix

Gets the loading matrix W.

public double[,]? LoadingMatrix { get; }

Property Value

double[,]

NComponents

Gets the number of components (dimensions).

public int NComponents { get; }

Property Value

int

NoiseVariance

Gets the estimated noise variance.

public double NoiseVariance { get; }

Property Value

double

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Fits Probabilistic PCA 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>)

Reconstructs data from the latent space.

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

Parameters

data Matrix<T>

Returns

Matrix<T>

Score(Matrix<T>)

Computes the log-likelihood of the data under the model.

public double Score(Matrix<T> data)

Parameters

data Matrix<T>

The data to evaluate.

Returns

double

The log-likelihood.

TransformCore(Matrix<T>)

Transforms data by projecting to the latent space.

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

Parameters

data Matrix<T>

Returns

Matrix<T>