use scirs2_core::ndarray::Array2;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use sklears_core::{error::Result, types::Float};
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum UpdateAlgorithm {
SVD,
GradientDescent,
Newton,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct UpdateConfig {
pub algorithm: UpdateAlgorithm,
pub learning_rate: Float,
}
impl Default for UpdateConfig {
fn default() -> Self {
Self {
algorithm: UpdateAlgorithm::SVD,
learning_rate: 0.01,
}
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DictionaryUpdateResult {
pub updated_dictionary: Array2<Float>,
pub convergence_error: Float,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DictionaryUpdater {
config: UpdateConfig,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AtomUpdater;
impl DictionaryUpdater {
pub fn new(config: UpdateConfig) -> Self {
Self { config }
}
pub fn update(
&self,
dictionary: &Array2<Float>,
_data: &Array2<Float>,
_codes: &Array2<Float>,
) -> Result<DictionaryUpdateResult> {
let updated_dictionary = dictionary.clone();
let convergence_error = 0.0;
Ok(DictionaryUpdateResult {
updated_dictionary,
convergence_error,
})
}
}