ruthril 0.1.2

A powerful AI/ML framework is under development
Documentation
/// Base trait for prediction systems in Ruthril
/// Handles inference and prediction confidence using statistics
use ruthril::core::statistics::Statistics;

pub trait Predictor {
    type Input;
    type Output;
    type Error;
    
    /// Make a single prediction
    fn predict(&self, input: &Self::Input) -> Result<Self::Output, Self::Error>;
    
    /// Make batch predictions with confidence intervals
    fn predict_batch(&self, inputs: &[Self::Input]) -> Result<Vec<Self::Output>, Self::Error>;
    
    /// Calculate prediction confidence using statistical measures
    fn calculate_confidence(&self, predictions: &[f64]) -> PredictionConfidence {
        PredictionConfidence {
            mean_prediction: Statistics::mean(predictions).unwrap_or(0.0),
            prediction_variance: Statistics::variance(predictions).unwrap_or(0.0),
            prediction_std: Statistics::std_deviation(predictions).unwrap_or(0.0),
        }
    }
    
    /// Detect outliers in predictions using statistical thresholds
    fn detect_outliers(&self, predictions: &[f64], threshold_std: f64) -> Vec<usize> {
        if let (Some(mean), Some(std)) = (Statistics::mean(predictions), Statistics::std_deviation(predictions)) {
            predictions.iter()
                .enumerate()
                .filter_map(|(idx, &pred)| {
                    if (pred - mean).abs() > threshold_std * std {
                        Some(idx)
                    } else {
                        None
                    }
                })
                .collect()
        } else {
            Vec::new()
        }
    }
}

/// Prediction confidence metrics using Ruthril's statistics
#[derive(Debug, Clone)]
pub struct PredictionConfidence {
    pub mean_prediction: f64,
    pub prediction_variance: f64,
    pub prediction_std: f64,
}