datasynth_eval/
lib.rs

1//! Synthetic Data Evaluation Framework
2//!
3//! This crate provides comprehensive evaluation capabilities for validating
4//! the quality and correctness of generated synthetic financial data.
5//!
6//! # Features
7//!
8//! - **Statistical Quality**: Benford's Law, amount distributions, line item patterns
9//! - **Semantic Coherence**: Balance sheet validation, subledger reconciliation
10//! - **Data Quality**: Uniqueness, completeness, format consistency
11//! - **ML-Readiness**: Feature distributions, label quality, graph structure
12//! - **Reporting**: HTML and JSON reports with pass/fail thresholds
13//!
14//! # Example
15//!
16//! ```ignore
17//! use datasynth_eval::{Evaluator, EvaluationConfig};
18//!
19//! let config = EvaluationConfig::default();
20//! let evaluator = Evaluator::new(config);
21//!
22//! // Evaluate generated data
23//! let result = evaluator.evaluate(&generation_result)?;
24//!
25//! // Generate report
26//! result.generate_html_report("evaluation_report.html")?;
27//! ```
28
29pub mod config;
30pub mod enhancement;
31pub mod error;
32
33pub mod coherence;
34pub mod ml;
35pub mod quality;
36pub mod report;
37pub mod statistical;
38pub mod tuning;
39
40// Re-exports
41pub use config::{EvaluationConfig, EvaluationThresholds};
42pub use error::{EvalError, EvalResult};
43
44pub use statistical::{
45    AmountDistributionAnalysis, AmountDistributionAnalyzer, BenfordAnalysis, BenfordAnalyzer,
46    BenfordConformity, LineItemAnalysis, LineItemAnalyzer, LineItemEntry, StatisticalEvaluation,
47    TemporalAnalysis, TemporalAnalyzer, TemporalEntry,
48};
49
50pub use coherence::{
51    BalanceSheetEvaluation, BalanceSheetEvaluator, CoherenceEvaluation, DocumentChainEvaluation,
52    DocumentChainEvaluator, ICMatchingEvaluation, ICMatchingEvaluator,
53    ReferentialIntegrityEvaluation, ReferentialIntegrityEvaluator, SubledgerEvaluator,
54    SubledgerReconciliationEvaluation,
55};
56
57pub use quality::{
58    CompletenessAnalysis, CompletenessAnalyzer, ConsistencyAnalysis, ConsistencyAnalyzer,
59    ConsistencyRule, DuplicateInfo, FieldCompleteness, FormatAnalysis, FormatAnalyzer,
60    FormatVariation, QualityEvaluation, UniquenessAnalysis, UniquenessAnalyzer,
61};
62
63pub use ml::{
64    FeatureAnalysis, FeatureAnalyzer, FeatureStats, GraphAnalysis, GraphAnalyzer, GraphMetrics,
65    LabelAnalysis, LabelAnalyzer, LabelDistribution, MLReadinessEvaluation, SplitAnalysis,
66    SplitAnalyzer, SplitMetrics,
67};
68
69pub use report::{
70    BaselineComparison, ComparisonResult, EvaluationReport, HtmlReportGenerator,
71    JsonReportGenerator, MetricChange, ReportMetadata, ThresholdChecker, ThresholdResult,
72};
73
74pub use tuning::{
75    ConfigSuggestion, ConfigSuggestionGenerator, TuningAnalyzer, TuningCategory, TuningOpportunity,
76};
77
78pub use enhancement::{
79    AutoTuneResult, AutoTuner, ConfigPatch, EnhancementReport, Recommendation,
80    RecommendationCategory, RecommendationEngine, RecommendationPriority, RootCause,
81    SuggestedAction,
82};
83
84use serde::{Deserialize, Serialize};
85
86/// Comprehensive evaluation result combining all evaluation modules.
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct ComprehensiveEvaluation {
89    /// Statistical quality evaluation.
90    pub statistical: StatisticalEvaluation,
91    /// Semantic coherence evaluation.
92    pub coherence: CoherenceEvaluation,
93    /// Data quality evaluation.
94    pub quality: QualityEvaluation,
95    /// ML-readiness evaluation.
96    pub ml_readiness: MLReadinessEvaluation,
97    /// Overall pass/fail status.
98    pub passes: bool,
99    /// Summary of all failures.
100    pub failures: Vec<String>,
101    /// Tuning opportunities identified.
102    pub tuning_opportunities: Vec<TuningOpportunity>,
103    /// Configuration suggestions.
104    pub config_suggestions: Vec<ConfigSuggestion>,
105}
106
107impl ComprehensiveEvaluation {
108    /// Create a new empty evaluation.
109    pub fn new() -> Self {
110        Self {
111            statistical: StatisticalEvaluation::default(),
112            coherence: CoherenceEvaluation::default(),
113            quality: QualityEvaluation::default(),
114            ml_readiness: MLReadinessEvaluation::default(),
115            passes: true,
116            failures: Vec::new(),
117            tuning_opportunities: Vec::new(),
118            config_suggestions: Vec::new(),
119        }
120    }
121
122    /// Check all evaluations against thresholds and update overall status.
123    pub fn check_all_thresholds(&mut self, thresholds: &EvaluationThresholds) {
124        self.failures.clear();
125
126        // Check statistical thresholds
127        self.statistical.check_thresholds(thresholds);
128        self.failures.extend(self.statistical.failures.clone());
129
130        // Check coherence thresholds
131        self.coherence.check_thresholds(thresholds);
132        self.failures.extend(self.coherence.failures.clone());
133
134        // Check quality thresholds
135        self.quality.check_thresholds(thresholds);
136        self.failures.extend(self.quality.failures.clone());
137
138        // Check ML thresholds
139        self.ml_readiness.check_thresholds(thresholds);
140        self.failures.extend(self.ml_readiness.failures.clone());
141
142        self.passes = self.failures.is_empty();
143    }
144}
145
146impl Default for ComprehensiveEvaluation {
147    fn default() -> Self {
148        Self::new()
149    }
150}
151
152/// Main evaluator that coordinates all evaluation modules.
153pub struct Evaluator {
154    /// Evaluation configuration.
155    config: EvaluationConfig,
156}
157
158impl Evaluator {
159    /// Create a new evaluator with the given configuration.
160    pub fn new(config: EvaluationConfig) -> Self {
161        Self { config }
162    }
163
164    /// Create an evaluator with default configuration.
165    pub fn with_defaults() -> Self {
166        Self::new(EvaluationConfig::default())
167    }
168
169    /// Get the configuration.
170    pub fn config(&self) -> &EvaluationConfig {
171        &self.config
172    }
173
174    /// Run a comprehensive evaluation and return results.
175    ///
176    /// This is a placeholder - actual implementation would take
177    /// generation results as input.
178    pub fn run_evaluation(&self) -> ComprehensiveEvaluation {
179        let mut evaluation = ComprehensiveEvaluation::new();
180        evaluation.check_all_thresholds(&self.config.thresholds);
181        evaluation
182    }
183}
184
185#[cfg(test)]
186mod tests {
187    use super::*;
188
189    #[test]
190    fn test_comprehensive_evaluation_new() {
191        let eval = ComprehensiveEvaluation::new();
192        assert!(eval.passes);
193        assert!(eval.failures.is_empty());
194    }
195
196    #[test]
197    fn test_evaluator_creation() {
198        let evaluator = Evaluator::with_defaults();
199        assert_eq!(evaluator.config().thresholds.benford_p_value_min, 0.05);
200    }
201}