lawsynth/crates/lawsynth-discovery/tests/regime_segmentation.rs
caelum0x b5da90b795 feat: discovery Pareto frontier + regime/uncertainty stages + benchmark execution engine
Discovery (§8/§16): add Pareto-frontier construction over the multi-objective
candidate score vector (DiscoveryResult.frontier + pareto_frontier()), opt-in
regime segmentation (result.regimes), and bootstrap uncertainty attachment;
CLI --pareto/--regimes flags. Benchmarks: a real generate->run->score->classify
execution engine driving the compiled CLI (9 supported cases end-to-end, 21
honest capability boundaries).

Rust workspace 329->342 tests; benchmarks +8 tests. clippy -D warnings clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-17 17:00:40 +03:00

42 lines
1.7 KiB
Rust

//! Opt-in regime segmentation and default-path frontier regression coverage.
use lawsynth_core::Identifier;
use lawsynth_data::{Dataset, NumericColumn, TimeAxis};
use lawsynth_discovery::{DiscoveryConfig, discover};
/// A single-jump, piecewise-constant series: fifteen samples at 0.0 followed by
/// fifteen at 10.0. Exact PELT segmentation must recover precisely two regimes.
fn piecewise_constant_dataset() -> (Dataset, Identifier) {
let x = Identifier::new("x").unwrap();
let time = (0..30).map(|step| step as f64).collect::<Vec<_>>();
let values = (0..30).map(|step| if step < 15 { 0.0 } else { 10.0 }).collect::<Vec<_>>();
let dataset =
Dataset::new(TimeAxis::new(time).unwrap(), [NumericColumn::new(x.clone(), values)])
.unwrap();
(dataset, x)
}
#[test]
fn regimes_are_absent_on_the_default_path() {
let (dataset, x) = piecewise_constant_dataset();
let config = DiscoveryConfig::new([x]);
let result = discover(&dataset, &config).unwrap();
assert!(result.regimes.is_none());
// The frontier is always exposed and references only real candidate indices.
assert!(!result.frontier.is_empty());
assert!(result.frontier.iter().all(|index| *index < result.candidates.len()));
assert_eq!(result.pareto_frontier().len(), result.frontier.len());
}
#[test]
fn enabling_regimes_segments_the_primary_state() {
let (dataset, x) = piecewise_constant_dataset();
let mut config = DiscoveryConfig::new([x]);
config.polynomial_degree = 1;
config.enable_regimes();
let result = discover(&dataset, &config).unwrap();
let segmentation = result.regimes.expect("regime pass should record segments");
assert_eq!(segmentation.segments.len(), 2);
assert_eq!(segmentation.change_points(), vec![15]);
}