Expand description
Dictionary Learning.
DictionaryLearning learns a dictionary D and sparse codes A such
that X ~ A * D. The dictionary atoms form an overcomplete basis, and
the codes are encouraged to be sparse via an L1 penalty.
§Algorithm
Alternating optimisation:
- Sparse coding step: with
Dfixed, solve forAusing coordinate descent (lasso) or orthogonal matching pursuit (OMP). - Dictionary update step: with
Afixed, updateDby solving a least-squares problem and normalising the atoms.
§Examples
use ferrolearn_decomp::DictionaryLearning;
use ferrolearn_core::traits::{Fit, Transform};
use ndarray::Array2;
let x = Array2::<f64>::from_shape_fn((20, 10), |(i, j)| {
((i * 7 + j * 3) % 11) as f64
});
let dl = DictionaryLearning::new(5)
.with_max_iter(50)
.with_random_state(42);
let fitted = dl.fit(&x, &()).unwrap();
let codes = fitted.transform(&x).unwrap();
assert_eq!(codes.dim(), (20, 5));Structs§
- Dictionary
Learning - Dictionary Learning configuration.
- Fitted
Dictionary Learning - A fitted dictionary learning model.
Enums§
- Dict
FitAlgorithm - The algorithm for the sparse coding step during fitting.
- Dict
Transform Algorithm - The algorithm for the sparse coding step during transform.