Batch 3 of the expansion-v2 roadmap, all deterministic/offline/std-only with honest capability boundaries. crates/lawsynth-reduce (new): deterministic symmetry & separability detection. Numerical-derivative probe (finite differences replace AI-Feynman's trained NN gradients) over a reconstructed Cartesian grid; additive/multiplicative separability + difference/sum/product/ratio symmetries. Every detection is a HYPOTHESIS verified by reconstruction residual, never a proof; non-grid data is honestly rejected (NotReconstructed). 17 tests. crates/lawsynth-score: two-part MDL objective (L_data + L_model in nats) and O(n log n) pareto_front_2d (sort-then-sweep), verified equal to the O(n^2) front across 12 deterministic sets. +5 tests; crate fmt-normalized to config. python/lawsynth export.py (new): to_sympy/to_torch/to_jax + dep-free numeric_derivatives anchor. Constants+params hoisted into one trainable vector so autograd reaches every coefficient (Neural-ODE vector field). Backends absent here degrade gracefully (MissingDependencyError subclasses ImportError). Faithful to native simulate at 1.1e-16. 10 tests + 6 honest skips. benchmarks: SRBench Feynman (15: 12 static algebraic relations as honest capability-boundaries, 3 dynamics-framed ODEs executed at R2~=1.0) and black-box (4 systems, predictive R2 + parsimony, no ground truth) families. Fixes a pre-existing _runner.py failure where Strogatz cases leaked into the legacy contract suite. 31 benchmark tests. specs/structural-reductions: boundary spec (detection-is-a-hypothesis contract).
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
//! Shared helpers for structural-reduction integration tests.
|
|
|
|
use lawsynth_core::Identifier;
|
|
use lawsynth_data::{Dataset, NumericColumn, TimeAxis};
|
|
|
|
fn id(name: &str) -> Identifier {
|
|
Identifier::new(name).unwrap()
|
|
}
|
|
|
|
/// Builds a `Dataset` from `f(x, y)` sampled over a Cartesian grid, flattened in
|
|
/// row-major order with a synthetic monotonic time index.
|
|
pub fn grid_dataset_2d(xs: &[f64], ys: &[f64], f: impl Fn(f64, f64) -> f64) -> Dataset {
|
|
let (mut xc, mut yc, mut fc) = (Vec::new(), Vec::new(), Vec::new());
|
|
for &x in xs {
|
|
for &y in ys {
|
|
xc.push(x);
|
|
yc.push(y);
|
|
fc.push(f(x, y));
|
|
}
|
|
}
|
|
let time: Vec<f64> = (0..xc.len()).map(|i| i as f64).collect();
|
|
Dataset::new(
|
|
TimeAxis::new(time).unwrap(),
|
|
[
|
|
NumericColumn::new(id("x"), xc),
|
|
NumericColumn::new(id("y"), yc),
|
|
NumericColumn::new(id("f"), fc),
|
|
],
|
|
)
|
|
.unwrap()
|
|
}
|
|
|
|
/// A standard evenly spaced axis of `n` points from `start` with `step`.
|
|
pub fn axis(start: f64, step: f64, n: usize) -> Vec<f64> {
|
|
(0..n).map(|i| start + step * i as f64).collect()
|
|
}
|