use scirs2_core::ndarray::Array2;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use sklears_core::{error::Result, types::Float};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KSVDConfig {
pub max_iter: usize,
pub tol: Float,
pub n_nonzero_coefs: usize,
}
impl Default for KSVDConfig {
fn default() -> Self {
Self {
max_iter: 100,
tol: 1e-6,
n_nonzero_coefs: 10,
}
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KSVDResult {
pub dictionary: Array2<Float>,
pub codes: Array2<Float>,
pub reconstruction_error: Float,
pub n_iter: usize,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KSVDEncoder {
config: KSVDConfig,
}
impl KSVDEncoder {
pub fn new(config: KSVDConfig) -> Self {
Self { config }
}
pub fn encode(
&self,
data: &Array2<Float>,
initial_dictionary: &Array2<Float>,
) -> Result<KSVDResult> {
let (n_samples, _n_features) = data.dim();
let n_atoms = initial_dictionary.nrows();
let dictionary = initial_dictionary.clone();
let codes = Array2::zeros((n_atoms, n_samples));
let reconstruction_error = 0.0;
Ok(KSVDResult {
dictionary,
codes,
reconstruction_error,
n_iter: 0,
})
}
}