Table of Contents

Class DictionaryLearning<T>

Namespace
AiDotNet.Preprocessing.DimensionalityReduction
Assembly
AiDotNet.dll

Dictionary Learning for sparse representation.

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

Remarks

Dictionary Learning finds a dictionary D and sparse codes A such that X ≈ D × A. The dictionary atoms (columns of D) form a basis that allows sparse representation of the data.

Unlike PCA which enforces orthogonality, dictionary learning allows overcomplete dictionaries (more atoms than dimensions) and enforces sparsity on the codes.

For Beginners: Dictionary Learning is like building a "parts library": - Dictionary: Collection of basic building blocks (atoms) - Sparse codes: Which parts to use and how much (mostly zeros) - Goal: Represent each sample using few dictionary atoms - Used for: Image denoising, compression, feature extraction

Constructors

DictionaryLearning(int?, double, int, double, DictionaryFitAlgorithm, SparseCodingAlgorithm, int?, int[]?)

Creates a new instance of DictionaryLearning<T>.

public DictionaryLearning(int? nComponents = null, double alpha = 1, int maxIter = 1000, double tol = 1E-06, DictionaryFitAlgorithm fitAlgorithm = DictionaryFitAlgorithm.CD, SparseCodingAlgorithm transformAlgorithm = SparseCodingAlgorithm.LASSO, int? randomState = null, int[]? columnIndices = null)

Parameters

nComponents int?

Number of dictionary atoms. Defaults to the number of features.

alpha double

Sparsity regularization parameter. Defaults to 1.0.

maxIter int

Maximum iterations. Defaults to 1000.

tol double

Convergence tolerance. Defaults to 1e-6.

fitAlgorithm DictionaryFitAlgorithm

Algorithm for dictionary learning. Defaults to CD.

transformAlgorithm SparseCodingAlgorithm

Algorithm for sparse coding. Defaults to LASSO.

randomState int?

Random seed for reproducibility.

columnIndices int[]

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

Properties

Alpha

Gets the sparsity penalty.

public double Alpha { get; }

Property Value

double

Components

Gets the dictionary atoms (each row is an atom).

public double[,]? Components { get; }

Property Value

double[,]

FitAlgorithm

Gets the dictionary fitting algorithm.

public DictionaryFitAlgorithm FitAlgorithm { get; }

Property Value

DictionaryFitAlgorithm

Mean

Gets the mean of each feature.

public double[]? Mean { get; }

Property Value

double[]

NComponents

Gets the number of dictionary atoms.

public int NComponents { get; }

Property Value

int

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

TransformAlgorithm

Gets the sparse coding algorithm for transform.

public SparseCodingAlgorithm TransformAlgorithm { get; }

Property Value

SparseCodingAlgorithm

Methods

FitCore(Matrix<T>)

Fits the dictionary using alternating minimization.

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>)

Transforms sparse codes back to original space.

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

Parameters

data Matrix<T>

Returns

Matrix<T>

TransformCore(Matrix<T>)

Transforms data by computing sparse codes.

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

Parameters

data Matrix<T>

Returns

Matrix<T>