Skip to main content

swarm_engine_core/validation/
mod.rs

1//! Validation Module - 学習結果の性能検証
2//!
3//! Learn Pipeline の **外** で使用される検証機能。
4//! Bootstrap 後に検証を行い、基準を満たした場合のみ Active に昇格させる。
5//!
6//! # 設計思想
7//!
8//! - **Validator**: 検証を実行する Executor(データ分割 + 評価)
9//! - **ValidationStrategy**: 検証基準を定義する trait
10//! - **ValidationResult**: 検証結果(Profile に保存される)
11//!
12//! Profile は ValidationResult を受け取るだけでロジックを持たない。
13//! 検証ロジックは全てこのモジュールに分離されている。
14//!
15//! # ライフサイクル
16//!
17//! ```text
18//! Draft → Bootstrapping → Validating → Active
19//!                             ↓
20//!                          Failed → (retry) → Draft
21//! ```
22//!
23//! # Example
24//!
25//! ```
26//! use swarm_engine_core::validation::{Validator, NoRegression, Improvement, Absolute};
27//!
28//! // NoRegression: current >= baseline なら PASS
29//! let validator = Validator::<f64>::with_80_20_split(Box::new(NoRegression::new()));
30//!
31//! // データを用意(例: 成功/失敗のリスト)
32//! let data: Vec<f64> = vec![1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
33//!
34//! let result = validator.validate(
35//!     &data,
36//!     |train| train.iter().sum::<f64>() / train.len() as f64,  // baseline
37//!     |test| test.iter().sum::<f64>() / test.len() as f64,     // current
38//! );
39//!
40//! assert!(result.passed);
41//! ```
42//!
43//! # Strategies
44//!
45//! | 戦略 | 判定 | ユースケース |
46//! |------|------|--------------|
47//! | [`NoRegression`] | current >= baseline | 回帰がなければOK(デフォルト) |
48//! | [`Improvement`] | current >= baseline × threshold | 明確な改善を要求 |
49//! | [`Absolute`] | current >= threshold | ベースラインに関係なく絶対値で判定 |
50//!
51//! # CLI 連携
52//!
53//! ```bash
54//! # Bootstrap 後に Validating 状態になる
55//! swarm profile bootstrap my_profile -n 10
56//!
57//! # 検証を実行
58//! swarm profile validate my_profile -n 5 --strategy no_regression
59//!
60//! # 検証をスキップして直接 Active にすることも可能
61//! swarm profile skip-validation my_profile
62//! ```
63
64mod result;
65mod strategy;
66mod validator;
67
68pub use result::ValidationResult;
69pub use strategy::{Absolute, Improvement, NoRegression, ValidationStrategy};
70pub use validator::Validator;