Repository navigation
Description
Overview
Phase 4 of the EP framework review (umbrella: PyAutoMind/research/graphical_ep/ep_framework_review.md; audit #1332). EP fits currently emit one evidence/KL plot (graph.png) and a text graph.results; there is no machine-readable fit log, no record of how the mean field evolved, no per-factor status accounting, no guard against the F10 sigma-collapse pathology, and no post-fit summary helpers. This adds all of those, additively (no behaviour change to the fitting itself).
Autonomy: --auto, effective level supervised (feature cap). Plan below per contract; run parks at ship sign-off.
Coexistence note: PyAutoFit is also claimed by the parked ep-graphical-docs task (PR #1334, docs-only). This task's files (expectation_propagation/, new diagnostics module, test_autofit/graphical/) are disjoint from that diff (README, mean_field.py, composed_transform.py, abstract.py docstrings); disjointness is re-verified before ship. Human directed both to proceed in parallel.
Plan
New autofit/graphical/expectation_propagation/diagnostics.py:
MeanFieldSnapshotrecording per factor-step: step index, factor name, status (success/updated/flag), factor log-evidence, factor KL, and per-variable (mean, std) of the global mean field (arrays summarised as mean-of-means / max-std).EPDiagnosticscollector — accumulates snapshots during a run; writers for:ep_history.csv— step, factor, success, flag, log_evidence, kl_divergence;mean_field_history.csv— step, variable, mean, std;
mean_field_summary(mean_field)— post-fit text table (variable, mean, std) usable at the end of any example.check_sigma_collapse(...)— the F10 guard: flags variables whose std shrinks monotonically below a floor across steps; returned as warnings, logged at run end, and appended to the results text.
visualise.py upgrades:
- Enable the (currently commented-out) per-factor evidence/KL curves as
graph_factors.png. - New
mean_field_evolution.png— per-variable mean ± std band vs step, from the diagnostics collector.
optimiser.py wiring:
EPOptimiserinstantiatesEPDiagnosticswhenpathsis set; snapshot after each factor update (cheap float extraction); CSVs written atoutput_interval; final summary + collapse warnings emitted at run end.- Fix F3 while here: guard the unconditional
self.visualiser()/_output_resultsat the end ofParallelEPOptimiser.run(crash whenpaths=None) — one-line, same file, in scope as the wiring touches these call sites.
Tests (test_autofit/graphical/functionality/test_diagnostics.py, numpy-only):
- Tiny exact-conjugate graph run via
EPOptimiserwithpathsat tmp_path → CSVs exist, expected columns, row counts match steps×factors; summary text contains all variables. check_sigma_collapsefires on a synthetic collapsing history, silent on a healthy one.ParallelEPOptimisercompletion withpaths=Noneno longer raises (F3).
Out of scope: wiring diagnostics calls into workspace examples (follow-up on the parked Phase 3 branch or later); richer aggregated posterior views (graphical_scoping.md limitation 3 — the CSV/plot layer here is its foundation).
Activity
Jammy2211 commentedon Jul 8, 2026
Ship sign-off requested (supervised checkpoint — run parked)
Phase 4 implementation is complete in worktree
ep-diagnostics(branchfeature/ep-diagnostics). One approval covers the diff and the Heart YELLOW acknowledgement.Diff (6 files; all additive, no behaviour change to fitting)
expectation_propagation/diagnostics.py(new) —EPDiagnosticscollector (one snapshot per factor update: status/flag, global log-evidence, KL step size, every variable's mean/std); CSV writers (ep_history.csv,mean_field_history.csv, overwritten live so a running fit can be watched);mean_field_evolution.png(per-variable mean ± std band vs update);mean_field_summary()post-fit table;check_sigma_collapse()— the F10 guard (floor + monotone-shrink detection, warnings logged and written toep_diagnostics.results).optimiser.py—EPOptimiser/ParallelEPOptimisersnapshot each update and emit the artifacts atoutput_interval+ run end; F3 fixed (parallel end-of-runvisualiser()/_output_resultsnow guarded forpaths=None).visualise.py— newgraph_factors.png: per-factor evidence/KL curves (previously dead commented-out code), so one misbehaving factor is visible instead of averaged away.EPDiagnostics,mean_field_summary,check_sigma_collapsefromautofit.graphical(additive public API).test_autofit/graphical/functionality/test_diagnostics.py(new) — 7 tests: snapshot schema, CSV/plot/results artifacts, summary content, collapse detector (floor + monotone + healthy-negative), F3 guards.Verification
TransformedMessage/UniformPrior variables — no.stdattribute); fixed by deriving std fromvarianceinside the module, keeping the branch disjoint from PR docs: formal Bayesian specification of autofit.graphical (EP review phase 2) #1334's files. The failing case (test_other_priors.py::test_trivial) now passes.ep-graphical-docsbranch re-verified: zero file overlap (that diff: README,mean_field.py,messages/abstract.py,composed_transform.py; this diff:expectation_propagation/*, exports, tests).Heart
YELLOW, same 10 pre-existing organism-staleness reasons as the Phase 2/3 sign-offs; none touch this diff. Acknowledgement requested as part of this approval.
On approval
ship_libraryproceeds: commit, push, PR atpending-releasewith## API Changes(Added: the three exported functions/classes; no removals/migrations), workspace-impact analysis (expected: option i — small follow-up wiringmean_field_summarycalls into the Phase 3 example), stop at PR-open.Jammy2211 commentedon Jul 10, 2026
Shipped at PR-open (human-approved 2026-07-10) — #1349
PR #1349 open (
pending-release). Branch was merged with currentmain(post #1345/#1348/#1334) before validation: full suite 1457 passed / 14 skipped — so the diagnostics module is certified against this week's priors/messages fix batch and the merged docs spec, not the 07-08 snapshot. Heart YELLOW within the live 6-reason ack. Merge stays human. Post-merge follow-up (option i, small): wiremean_field_summary()into the Phase-3 walkthrough (autofit_workspace#82).Jammy2211 commentedon Jul 10, 2026
Merged —
1a06bbc14via #1349. Follow-up (wiremean_field_summary()into the Phase-3 walkthrough) queued as a Mind prompt. Closing.