Skip to content

Plate-notation model figures for graphical models - #1617

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/model-figures-graphical
Sep 12, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/model-figures-graphical

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Phase 4 of the model-figures epic: af.ModelPlotter now draws plate notation for graphical models.
Passing a FactorGraphModel's global_prior_model to the plotter produces a figure where repeated
per-dataset structure collapses into a dashed dataset plate badged with the dataset count, shared
priors are hoisted into a card above the plate and linked back to it, hierarchically drawn
parameters carry a drawn pill fed by a violet arrow from their HierarchicalFactor card, observed
data enters as a green observed pill, and the footer splits the parameter count into
hyper-parameters, per-dataset parameters and unique sampled scalars.

This fills the three "visualization not implemented" holes: docs/features/graphical.md,
autofit_workspace/scripts/features/graphical_models.py and HowToFit chapter 3 (workspace PRs linked
below), and ships the shared-vs-hierarchical teaching pair.

API Changes

None — no public symbol added, removed, renamed or re-signatured (autofit/__init__.py is unchanged).
The change is behavioural: af.ModelPlotter(...).figure() previously drew a factor graph's global
model as ordinary repeated cards; it now detects the graphical structure and renders plate notation
(plates, hoisted shared cards, draw arrows, observed rows, hyper/per-dataset footer). Figures of
non-graphical models are unchanged.
See full details below.

Test Plan

  • pytest test_autofit/ — 2759 passed, 2 skipped, 0 failed
  • New suites: test_autofit/graph_spec/test_graphical.py, test_autofit/model_figure/test_graphical_presentation.py
  • black --check + pyflakes clean on touched files
  • Sphinx build: 30 warnings == main baseline (30)
  • Figures regenerated via docs/images/model_figures/make_figures.py and reviewed
Full API Changes (for automation & release notes)

Removed

  • None.

Added (internal — not exported from autofit)

  • autofit.graph_spec.FactorInfo — frozen dataclass describing a factor (name, dataset index, observed rows)
  • autofit.graph_spec.DrawEdge — frozen dataclass for a hierarchical draw (parent factor → drawn prior), used instead of a sharing link
  • GraphSpec.graphical_counts(raw_root) — hyper / per-dataset / unique-scalar counts for the footer
  • autofit.model_figure internals: dataset-plate detection, shared-prior hoisting, draw-route rendering, observed/drawn/shared pill states, split footer

Changed Signature (internal)

  • autofit.graph_spec._path_index(spec, model, hyper_paths=None) — new optional argument
  • autofit.model_figure.presentation._badge_colours(badge, state="free") — new optional argument

Changed Behaviour (public)

  • af.ModelPlotter(factor_graph.global_prior_model).figure() — renders plate notation for graphical/hierarchical models instead of repeated per-dataset cards

Migration

  • None required; existing calls produce the same figure for non-graphical models.

Opened under Heart RED (release validation FAILED, stage integrate — unrelated autolens scripts) with explicit human authorisation on 2026-09-12; merge stays human via /prm.

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AmyBwcVQBrWE4jSTqdATY6

Jammy2211 and others added 2 commits September 11, 2026 12:48
…AutoFit#1616)

Snapshot taken at laptop shutdown; not tested/shipped. Resume from the
active.md row of model-figures-graphical in PyAutoMind.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178yLU9v19GtACcRPFggjGa
Phase 4 of the model-figures epic: a `FactorGraphModel`'s global model now
draws as plate notation, so a graphical model is a picture rather than a
paragraph.

graph_spec: a graphical pass keyed off `GlobalPriorModel.factor` adds hyper
nodes for each `_HierarchicalFactor`, a `DrawEdge` from the hyper node to
every drawn variable, observed rows for each analysis' data, a `FactorInfo`
record of the `model.info` paths a hyper node replaces, and the graphical
counts (hyper-parameters, shared across datasets, per dataset, datasets).

presentation: the "shared across datasets" card is hoisted above the dataset
plates, drawn and observed parameters get their own pills, and the footer
splits into the graphical counts.

render: a violet arrow draws each draw edge from the hoisted hyper card into
the pill it lands on.

docs: `docs/features/graphical.md` replaces the "we haven't yet built
visualization" sentence with the figure of the page's own factor graph, and a
"Shared Or Hierarchical" section contrasting a shared prior (blue badge, one
hoisted card, 3 sampled scalars) with a hierarchical draw (violet card and
arrow, 11 sampled scalars), tied to HowToFit chapter 3 tutorial 4. Three new
PNGs under `docs/images/model_figures/` are written by `make_figures.py`.

tests: `test_autofit/graph_spec/test_graphical.py` and
`test_autofit/model_figure/test_graphical_presentation.py`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyBwcVQBrWE4jSTqdATY6
@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autofit_workspace#153

@Jammy2211

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/HowToFit#51

@Jammy2211
Jammy2211 merged commit 650cb88 into main Sep 12, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/model-figures-graphical branch September 12, 2026 18:36
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant