mixle.experimental.law_discovery module

Discover a validated empirical law from a black-box simulator – a scoped, honest step into the “derive an equation / propose a relationship” tier of the discovery vision.

Distinct from mixle.experimental.equation_discovery (SINDy recovery of a known ODE operator, graded against ground truth): this takes a real simulator you can only call – simulate(x) -> y – sweeps its input, fits a small library of candidate functional forms, selects the winner on a validation split, and confirms that winner once on an untouched holdout split. The independent confirmation score is the whole point: it is what separates a discovered law (predicts new inputs) from a model that merely won a finite candidate search. If no form generalizes, that is reported honestly, not dressed up as a discovery.

Exploratory mixle.experimental code.

class DiscoveredLaw(form, expression, params, train_r2, holdout_r2, n_train, n_holdout, passed, ranking=<factory>, selection_r2=-inf, n_selection=0)[source]

Bases: object

A discovered relationship + the verification that earns the word ‘discovered’.

The candidate library is ranked by selection_r2 on a validation split. holdout_r2 is then computed once for the winner on an untouched confirmation split and is the referee for passed.

Parameters:
discover_law(simulate, input_range, *, n_samples=24, holdout_fraction=1.0 / 3.0, min_holdout_r2=0.9, forms=None, log_spaced=False, seed=0)[source]

Sweep simulate over input_range, fit candidate functional forms, and return the one that wins validation and then passes an independent holdout confirmation.

Parameters:
  • simulate (Callable[[float], float]) – the black-box x -> y (a real simulator wrapped to scalar in/out).

  • input_range (tuple[float, float]) – (lo, hi) to sweep the input over.

  • n_samples (int) – total simulator evaluations across the sweep.

  • holdout_fraction (float) – fraction reserved for each of validation and independent confirmation. The remainder is used for fitting. A seeded partition keeps the two evaluation sets disjoint from fitting and from each other.

  • min_holdout_r2 (float) – the bar the selected form’s independent holdout R^2 must clear.

  • forms (tuple[str, ...] | None) – restrict the candidate library (default: all of CANDIDATE_FORMS whose positivity requirement the input range satisfies).

  • log_spaced (bool) – sweep inputs geometrically (for laws probed over decades, e.g. resistivity).

  • seed (int) – controls the deterministic train/validation/confirmation partition.

Returns:

A DiscoveredLaw – the winning form, its refitted params, train, selection, and independent holdout R^2 values. passed is false when confirmation misses the threshold.

Return type:

DiscoveredLaw