Skip to content

Latest commit

 

History

History
140 lines (116 loc) · 7.5 KB

formalism_to_code.md

File metadata and controls

140 lines (116 loc) · 7.5 KB

From formal objects to executable evidence

The suite treats a formalism as useful only when a reader can follow it into code, tests, artifacts, and a bounded claim. This is a traceability requirement —not a claim that code alone proves a theorem.

The executable chain

formal object → public symbol → source module → real-value test
             → deterministic result/artifact → claim class → explicit non-claim

The canonical registry is generated by active_inference_power.formalism.formalism_registry() and written to output/formalism_registry.json. Each entry contains:

  • a stable identifier, layer, title, and formal statement;
  • the public symbols that instantiate the formal object;
  • project-relative source and test paths;
  • the assumptions required for interpretation;
  • an evidence class (formal_conditional, analytic_reference, conditional_operating_characteristic, calibration_diagnostic, trace_diagnostic, stress_test, or provenance_contract);
  • the artifact destinations, literature roles, claim, and non-claim boundary.

The registry is embedded in output/results.json, validated against the executable package at result-generation time, and hashed into the release manifest. This prevents a prose-only formalism map from drifting away from the code that produced the evidence.

Registry anchors are executable implementation anchors, not an additional public namespace. During validation, each dotted reference is resolved against the installed active_inference_power package, including class and function attributes. A missing module, missing attribute, malformed reference, or source/test path fails closed. This distinguishes three useful questions that are often conflated: whether a formal object is stated, whether a package symbol realizes the declared interface, and whether the resulting evidence supports the claim boundary. Passing the first two checks does not establish the statistical assumptions in the third.

Four connections that must remain distinct

1. Generative-model formalism → inference code

GenerativeModelSpec declares the state, observation, prior, likelihood, transition, action, and preference objects used by the agent. In the reference binary channel, a closed-form posterior-odds update is the oracle and the real pymdp agent is the implementation under test. Agreement is checked on every observed step. This establishes semantic correspondence for the declared model; it does not validate a broader active-inference interpretation.

2. Generative-process formalism → simulation environment

GenerativeProcessSpec owns hidden truth, action-conditioned transitions and emissions, missingness, and cost. Time-varying schedules declare whether they hold their last value, cycle periodically, or fail outside their stated support; this avoids an implicit extrapolation rule. The policy receives a visible history, while hidden states are retained in a separate evaluator-only trace. This separation is the code-level version of the filtration boundary: evaluator information cannot silently become policy information. The process's cost_unit and cost_scale_id are hash-bound alongside those mechanisms. They make $C$ a scenario-local simulated resource quantity rather than a common currency; cross-scenario cost or power-per-cost comparisons require matching identifiers.

3. Testing formalism → evidence accounting

SettingSpec declares the hypothesis family, correction, stopping rule, budget, and validity assumptions. Fixed-horizon p-values, likelihood-ratio e-process values $E_t$, LORD++/SAFFRON procedural alpha-wealth $W_t^\alpha$, e-LOND cumulative nominal-level allocation $\sum_{i\le t}\alpha_i$, and posterior beliefs are recorded as different quantities. e-LOND emits $\alpha_t$ and tests $E_t\ge 1/\alpha_t$; its recycled allocation trace is not a remaining budget or alpha-wealth. The suite never promotes a posterior threshold to FDR control, or a finite calibration plot to a theorem.

The global-null BH quantities are kept separate in the registry and API: bh_global_null_fdr represents the Simes/FDR identity FDR = P(R > 0), whereas expected_false_rejections_global_null computes the expected rejection count E[R] from the finite ordered-threshold distribution. The latter is not interchangeable with the former.

4. Formal estimand → replication metrics and publication artifacts

PowerScenario serializes the scientific model/process/testing-setting components (s=(M_A,P_N,T)), plus scenario identity and claim metadata. Its setting includes a default stopping rule; an action-loop row records the executed policy, so the evaluated design is (d=(s,\pi)), not a separately supplied surface policy hidden inside the scenario hash. ActionLoopTrace records one visible path; ActionLoopReplicationMetrics uses evaluator-only truth after that path ends to convert independent traces into mean-TPR power, the separately named any-true-detection rate, FDR, FWER, target rates, cost, stopping, and paired contrasts. Every scenario in a surface requires a unique scenario identifier in addition to its configuration hash. The identifier is user-supplied (the reference factory derives one from parameters only when no identifier is supplied), which makes a surface cell addressable in tables and plots. The configuration hash is the authoritative fingerprint of the complete serialized contract, including the identifier, description, claim role, metadata, model, process, and setting. Schema validation rejects duplicate identifiers or a mismatch between declared identifiers and serialized contracts, and the executable surface API rejects duplicate scenario or policy keys before simulation begins. Fractional replication means such as power and mean FDP use the declared Student-t Monte-Carlo interval, binary event rates such as FWER use Wilson intervals, and bounded planning summaries state their separate Hoeffding-style accounting. Captions, alt text, manuscript variables, and the dashboard consume the same result object.

How to extend the registry

Every new method or formal claim must add one registry entry before it is described as part of the suite. The entry must name a source symbol, a real test, assumptions, an evidence class, an artifact, a citation role when appropriate, and a non-claim. The implementation PR must also add or update the claim ledger and the research roadmap entry criteria.

Run the traceability tests and a fresh, isolated smoke lane with:

formalism_parent="$(mktemp -d "${TMPDIR:-/tmp}/active_inference_power_formalism.XXXXXX")"
formalism_root="$formalism_parent/results"
test ! -e "$formalism_root"
uv run pytest tests/test_formalism.py tests/test_scholarship.py
uv run python scripts/generate_results.py --profile fast --output-root "$formalism_root"

This writes a fresh result-derived registry at $formalism_root/formalism_registry.json without mutating the canonical output/ tree. It is a fast smoke, not a release, so it does not hydrate a manuscript or invoke a finalizer. The generated manuscript table is updated only through the full release chain; the registry remains the source of truth and this page explains how to read it.

Stale-evidence behavior

Visual refreshes validate the existing result contract before replacing any figure. An older or incomplete result bundle is therefore rejected rather than silently adapted to the current registry. Re-run the declared profile to materialize a current bundle; retain the rejected or failed ledger state as operational evidence, and do not mark its manifest complete.