Skip to content

fix(graphical): EP hierarchical factor returns -inf for out-of-support scale (nightly crash) - #1364

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/ep-negative-sigma-crash
Jul 13, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/ep-negative-sigma-crash

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

The EP guide (scripts/guides/modeling/advanced/expectation_propagation.py) crashed intermittently in the nightly workspace-validation with NormalMessage sigma cannot be negative. Root cause (pinned by deterministic reproduction): its HierarchicalFactor draws mass.slope from a GaussianPrior(mean, sigma) whose sigma is a truncated hyper-prior (lower_limit=0). The hierarchical factor's Laplace/Newton optimiser evaluates at proposed scales that dip just below 0 (the scale posterior sits at mean≈0.0005, hard against the boundary), so Factor.__call__ built GaussianPrior(sigma<0) and tripped the strict NormalMessage sigma guard.

A distribution parameterised outside its support has zero probability density, so the factor's log-value is -inf — not a hard error. Factor.__call__ now catches exc.MessageException and returns -inf. The strict guard is unchanged (still fires for genuine prior-passing misuse); its stale RelativeWidthModifier-only hint is corrected. Adds a deterministic regression test. The workspace guide is untouched (no autoimmunity — no seeding, no prior constraints).

Fixes #1363

API Changes

None — internal changes only. Behavioural: a HierarchicalFactor whose optimiser proposes an out-of-support distribution scale now yields a zero-density (-inf) factor value instead of raising MessageException. No public symbols added/removed/renamed and no signatures changed.
See full details below.

Test Plan

  • Full test_autofit/ suite: 1473 passed, 1 skipped (in-worktree).
  • New regression test test_autofit/graphical/hierarchical/test_negative_scale.py: the exact CI scales (−0.016, −0.17) return -inf; a valid scale returns finite; strict NormalMessage(sigma<0) still raises.
  • test_autofit/graphical/ in-order: 218 passed (EP-optimisation locus green).
  • EP guide in the nightly's exact mode (PYAUTO_TEST_MODE=1 PYAUTO_SMALL_DATASETS=1 PYAUTO_FAST_PLOTS=1): base crashes (sigma=-0.07… via graphical.laplace.newton); with the fix the guide runs to completion (exit 0, full MeanField output).
Full API Changes (for automation & release notes)

Changed Behaviour

  • autofit.graphical.declarative.factor.hierarchical.Factor.__call__ — returns -inf (zero density) when the distribution is parameterised outside its support (raising exc.MessageException), instead of propagating the exception. Internal to the EP hierarchical-factor machinery.
  • autofit.messages.normal.assert_sigma_non_negative — exception message text corrected (the RelativeWidthModifier path now uses abs(mean), so it is no longer the likely source); the sigma<0 rejection itself is unchanged.

Migration

  • None.

Validation checklist (--auto run — plan was not pre-approved)

  • Effective level: supervised (header: safe, cap: bug → supervised)
  • Plan: on the issue (fix(graphical): EP builds strict NormalMessage from negative-variance cavity → sigma<0 crash #1363), written at start, unmodified since
  • Gate: tests 1473p / 1s · smoke base-crashes / fix-clean in the nightly's exact test-mode · review CLEAN · Heart YELLOW (stale test_run 2026-07-09 + 58 stale parked scripts; human-acknowledged at the ship checkpoint as unrelated to this branch)
  • Human: plan sound in hindsight?
  • Human: diff matches plan (no scope creep)?
  • Human: merge, amend, or reject — then log the outcome

Generated by the PyAutoLabs agent workflow.

An EP factor optimiser can propose a transiently negative scale for a
GaussianPrior distribution drawn via a HierarchicalFactor (just below a
truncated scale hyper-prior's lower_limit=0). Factor.__call__ then built
GaussianPrior(sigma<0), tripping the strict NormalMessage sigma guard and
crashing the fit — the nightly workspace-validation RED on the EP guide
(scripts/guides/modeling/advanced/expectation_propagation.py).

A distribution parameterised outside its support has zero probability
density, so the factor's log-value is -inf rather than a hard error. The
strict NormalMessage sigma guard stays intact for genuine prior-passing
misuse; its stale RelativeWidthModifier-only hint is corrected. Adds a
regression test asserting negative scales return -inf and the guard still
raises.

Fixes #1363

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Jul 13, 2026
@Jammy2211
Jammy2211 merged commit 301c0a2 into main Jul 13, 2026
5 checks passed
@Jammy2211
Jammy2211 deleted the feature/ep-negative-sigma-crash branch July 13, 2026 15:46
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 4, 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.

fix(graphical): EP builds strict NormalMessage from negative-variance cavity → sigma<0 crash

1 participant