sklears_decomposition/dictionary_learning/
dictionary_update.rs1use scirs2_core::ndarray::Array2;
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6use sklears_core::{error::Result, types::Float};
7
8#[derive(Debug, Clone, Copy)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11pub enum UpdateAlgorithm {
12 SVD,
13 GradientDescent,
14 Newton,
15}
16
17#[derive(Debug, Clone)]
19#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
20pub struct UpdateConfig {
21 pub algorithm: UpdateAlgorithm,
22 pub learning_rate: Float,
23}
24
25impl Default for UpdateConfig {
26 fn default() -> Self {
27 Self {
28 algorithm: UpdateAlgorithm::SVD,
29 learning_rate: 0.01,
30 }
31 }
32}
33
34#[derive(Debug, Clone)]
36#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
37pub struct DictionaryUpdateResult {
38 pub updated_dictionary: Array2<Float>,
39 pub convergence_error: Float,
40}
41
42#[derive(Debug, Clone)]
44#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
45pub struct DictionaryUpdater {
46 config: UpdateConfig,
47}
48
49#[derive(Debug, Clone)]
51#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
52pub struct AtomUpdater;
53
54impl DictionaryUpdater {
55 pub fn new(config: UpdateConfig) -> Self {
56 Self { config }
57 }
58
59 pub fn update(
60 &self,
61 dictionary: &Array2<Float>,
62 _data: &Array2<Float>,
63 _codes: &Array2<Float>,
64 ) -> Result<DictionaryUpdateResult> {
65 let updated_dictionary = dictionary.clone();
66 let convergence_error = 0.0;
67
68 Ok(DictionaryUpdateResult {
69 updated_dictionary,
70 convergence_error,
71 })
72 }
73}