oxits 0.1.0

Time series classification and transformation library for Rust
Documentation
/// Stateless transformer: transform() is self-contained.
/// Example: StandardScaler, PAA, RecurrencePlot
pub trait Transformer {
    type Config;
    fn transform(config: &Self::Config, x: &[Vec<f64>]) -> Vec<Vec<f64>>;
}

/// Stateful transformer: fit() learns parameters, then transform() applies them.
/// Example: SFA (learns bin edges), MCB (learns bin edges)
pub trait FittableTransformer {
    type Config;
    type Fitted: Clone + Send + Sync;
    fn fit(config: &Self::Config, x: &[Vec<f64>], y: Option<&[String]>) -> Self::Fitted;
    fn transform(fitted: &Self::Fitted, x: &[Vec<f64>]) -> Vec<Vec<f64>>;
    fn fit_transform(config: &Self::Config, x: &[Vec<f64>], y: Option<&[String]>) -> Vec<Vec<f64>> {
        let fitted = Self::fit(config, x, y);
        Self::transform(&fitted, x)
    }
}

/// Classifier: fit() learns from training data, predict()/score() on test data.
pub trait Classifier {
    type Config;
    type Fitted: Clone + Send + Sync;
    fn fit(config: &Self::Config, x: &[Vec<f64>], y: &[String]) -> Self::Fitted;
    fn predict(fitted: &Self::Fitted, x: &[Vec<f64>]) -> Vec<String>;
    fn score(fitted: &Self::Fitted, x: &[Vec<f64>], y: &[String]) -> f64 {
        let predictions = Self::predict(fitted, x);
        let correct = predictions
            .iter()
            .zip(y.iter())
            .filter(|(p, t)| p == t)
            .count();
        correct as f64 / y.len() as f64
    }
}

/// Distance metric for time series pairs (used by KNN, DTW, etc.)
pub trait DistanceMetric: Clone + Send + Sync {
    fn distance(&self, a: &[f64], b: &[f64]) -> f64;
}