Skip to content

Implement LawAdherence module: constraint-residual metrics and diagnostics #33

Description

@jc-macdonald

Motivation

The lawful-learning manuscript (jcm-sci/lawful-learning) defines a formal taxonomy of
Law-Adherence Metrics (Definition 2.5) and Law-Adherence Diagnostics (Definition 2.6)
that quantify structural constraint satisfaction independently of data-fit accuracy. These are
complementary to the probabilistic scoring rules in ScoringRules.jl (#32): scoring rules
assess distributional calibration, law-adherence metrics assess structural fidelity.

TradeStudy.jl should expose both axes so that Pareto surfaces can span
(accuracy × lawfulness × calibration).

Scope

A LawAdherence submodule providing:

Core metric types

Following the manuscript's Definition 2.5, a law-adherence metric M : H²(D) → R≥0 satisfies:

  1. Constraint sensitivity — depends on surrogate only through constraint residuals
  2. Monotonicity — larger violations ⟹ larger metric values
  3. Interpretability — admits domain-meaningful interpretation

Concrete implementations

Metric Formula Notes
law_adherence_score S_law = (1/m) Σ 1[O_i(Ψ) ∈ A_i] Proportion of observables in admissible range; soft sigmoid variant for differentiable use
drift_index D = ‖Ψ - Ψ_ref‖ / ‖Ψ_ref‖ Relative deviation from lawful reference
violation_magnitude V = Σ_j ‖(H_j[Ψ])₋‖ Aggregate constraint violation size
margin M = min_j H_j[Ψ] Distance to nearest constraint boundary
violation_rate R = (1/N) Σ 1[∃j: H_j[Ψ(x_n)] < 0] Proportion of points with any violation
elasticity E = (x/Y)(∂Y/∂x) Signed diagnostic; abs(E) is a metric

Tier-stratified scoring

law_adherence_score(trial; tier=:all)   # aggregate
law_adherence_score(trial; tier=:E)     # embedded only (should be 1.0 for PESFs)
law_adherence_score(trial; tier=:P)     # penalized
law_adherence_score(trial; tier=:D)     # diagnostic

Dynamical-system extensions

Metric Description
conservation_drift Relative change in conserved quantity over horizon
time_to_violation First time any constraint is violated
violation_duration Total time constraints are violated
stability_fraction Proportion of trajectories remaining bounded
degradation_rate Rate of S_law decay under rollout

Integration with TradeStudy protocols

Dependencies

Non-goals

  • This module does not implement PESF training or constraint enforcement —
    that belongs in LawfulSurrogates.jl (Phase 5)
  • This module only evaluates constraint satisfaction, it does not enforce it

Cross-references

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions