ruthril 0.1.2

A powerful AI/ML framework is under development
Documentation
/// Base trait for training algorithms in Ruthril
/// Provides standardized training interface with statistical validation
use ruthril::core::statistics::Statistics;

pub trait Trainer {
    type Model;
    type Data;
    type Error;
    
    /// Train a model with the provided dataset
    fn train(&self, model: &mut Self::Model, data: &Self::Data) -> Result<(), Self::Error>;
    
    /// Validate training progress using statistical measures
    fn validate_training(&self, losses: &[f64]) -> TrainingMetrics {
        TrainingMetrics {
            mean_loss: Statistics::mean(losses).unwrap_or(f64::INFINITY),
            loss_variance: Statistics::variance(losses).unwrap_or(0.0),
            loss_std: Statistics::std_deviation(losses).unwrap_or(0.0),
        }
    }
    
    /// Check if training has converged
    fn has_converged(&self, recent_losses: &[f64], threshold: f64) -> bool {
        if let Some(std) = Statistics::std_deviation(recent_losses) {
            std < threshold
        } else {
            false
        }
    }
}

/// Training metrics calculated using Ruthril's statistics
#[derive(Debug, Clone)]
pub struct TrainingMetrics {
    pub mean_loss: f64,
    pub loss_variance: f64,
    pub loss_std: f64,
}