Batch 11 of expansion-v2. Extends discovery to spatiotemporal + conservation
structure, adds principled hyperparameter selection, and surfaces analysis in
the web app. Deterministic/offline/std-only (Rust) or typed/tested (TS).
crates/lawsynth-pde (new): evolution-PDE discovery (PDE-FIND). Central-difference
spatial/time derivatives on the interior + differential-term library (uᵖ·D_m) +
STLSQ on flattened u_t. Recovers heat (0.2002·u_xx), advection (−0.801·u_x), and
Burgers (−1.000·u·u_x + 0.100·u_xx) from snapshots; two-mode fixtures break the
u/u_xx collinearity; a finer-grid test confirms O(dx²). 32 tests.
crates/lawsynth-invariants (new): conserved-quantity detection. H parametrized
over a library; conserved ⇔ ∇H·f=0; the SVD nullspace of the sampled
Lie-derivative matrix yields invariants (constant excluded, canonically
normalized). Recovers x²+y² energy, two independent invariants for a decoupled
system, y²−2cos x for the pendulum (trig basis), and honestly returns EMPTY for
a damped oscillator (no false positive). 21 tests.
crates/lawsynth-modelselect (new): time-series cross-validated hyperparameter
selection. Forward-chaining/rolling folds (no shuffling), discover-on-train +
simulate-on-test predictive scoring via lawsynth-score, full auditable table,
simpler-model tie-break. Selects degree 3 for cubic Duffing, degree 1 for a
linear system, degree 2 for logistic. 27 tests.
apps/studio: analysis module surfacing all seven engine reports (stability/
control/domains/bifurcation/sensitivity/estimate/reduce) as UI view models via
the api-client parsers, wired as a navigable route. Honest cases handled
(inconclusive classification, empty fixed-point set, null validation). 16 groups.
specs/{pde-discovery,invariant-detection,model-selection}: boundary specs.
32 lines
1.3 KiB
Rust
32 lines
1.3 KiB
Rust
//! Determinism: identical `(field, dx, dt, config)` inputs yield a bit-identical
|
|
//! [`lawsynth_pde::PdeModel`].
|
|
|
|
mod common;
|
|
|
|
use common::{advection_two_mode, burgers_forward};
|
|
use lawsynth_pde::{PdeConfig, discover_pde};
|
|
|
|
#[test]
|
|
fn advection_discovery_is_bit_identical_across_runs() {
|
|
let fixture = advection_two_mode(0.7, 1.0, 3.0, 0.4, 80, 30, 0.01);
|
|
let config = PdeConfig::default();
|
|
let first = discover_pde(&fixture.field, fixture.dx, fixture.dt, &config).unwrap();
|
|
let second = discover_pde(&fixture.field, fixture.dx, fixture.dt, &config).unwrap();
|
|
// Struct equality compares every coefficient bit-for-bit (f64: PartialEq).
|
|
assert_eq!(first, second);
|
|
}
|
|
|
|
#[test]
|
|
fn burgers_discovery_is_bit_identical_across_runs() {
|
|
let fixture = burgers_forward(0.12, 96, 40, 0.004, 6);
|
|
let config = PdeConfig::default();
|
|
let first = discover_pde(&fixture.field, fixture.dx, fixture.dt, &config).unwrap();
|
|
let second = discover_pde(&fixture.field, fixture.dx, fixture.dt, &config).unwrap();
|
|
|
|
assert_eq!(first.residual_sum_squares.to_bits(), second.residual_sum_squares.to_bits());
|
|
for (a, b) in first.terms.iter().zip(&second.terms) {
|
|
assert_eq!(a.coefficient.to_bits(), b.coefficient.to_bits(), "term {} differs", a.label);
|
|
}
|
|
assert_eq!(first, second);
|
|
}
|