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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
DictionaryLearning<T>
- Implements
- 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
nComponentsint?Number of dictionary atoms. Defaults to the number of features.
alphadoubleSparsity regularization parameter. Defaults to 1.0.
maxIterintMaximum iterations. Defaults to 1000.
toldoubleConvergence tolerance. Defaults to 1e-6.
fitAlgorithmDictionaryFitAlgorithmAlgorithm for dictionary learning. Defaults to CD.
transformAlgorithmSparseCodingAlgorithmAlgorithm for sparse coding. Defaults to LASSO.
randomStateint?Random seed for reproducibility.
columnIndicesint[]The column indices to use, or null for all columns.
Properties
Alpha
Gets the sparsity penalty.
public double Alpha { get; }
Property Value
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
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
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
TransformAlgorithm
Gets the sparse coding algorithm for transform.
public SparseCodingAlgorithm TransformAlgorithm { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits the dictionary using alternating minimization.
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>)
Transforms sparse codes back to original space.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Transforms data by computing sparse codes.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>