Skip to main content

Module dictionary_learning

Module dictionary_learning 

Source
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:

  1. Sparse coding step: with D fixed, solve for A using coordinate descent (lasso) or orthogonal matching pursuit (OMP).
  2. Dictionary update step: with A fixed, update D by 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§

DictionaryLearning
Dictionary Learning configuration.
FittedDictionaryLearning
A fitted dictionary learning model.

Enums§

DictFitAlgorithm
The algorithm for the sparse coding step during fitting.
DictTransformAlgorithm
The algorithm for the sparse coding step during transform.