fix(graphical): EP hierarchical factor returns -inf for out-of-support scale (nightly crash)#1364
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The EP guide (
scripts/guides/modeling/advanced/expectation_propagation.py) crashed intermittently in the nightlyworkspace-validationwithNormalMessage sigma cannot be negative. Root cause (pinned by deterministic reproduction): itsHierarchicalFactordrawsmass.slopefrom aGaussianPrior(mean, sigma)whosesigmais a truncated hyper-prior (lower_limit=0). The hierarchical factor's Laplace/Newton optimiser evaluates at proposed scales that dip just below0(the scale posterior sits atmean≈0.0005, hard against the boundary), soFactor.__call__builtGaussianPrior(sigma<0)and tripped the strictNormalMessagesigma 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 catchesexc.MessageExceptionand returns-inf. The strict guard is unchanged (still fires for genuine prior-passing misuse); its staleRelativeWidthModifier-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
HierarchicalFactorwhose optimiser proposes an out-of-support distribution scale now yields a zero-density (-inf) factor value instead of raisingMessageException. No public symbols added/removed/renamed and no signatures changed.See full details below.
Test Plan
test_autofit/suite: 1473 passed, 1 skipped (in-worktree).test_autofit/graphical/hierarchical/test_negative_scale.py: the exact CI scales (−0.016, −0.17) return-inf; a valid scale returns finite; strictNormalMessage(sigma<0)still raises.test_autofit/graphical/in-order: 218 passed (EP-optimisation locus green).PYAUTO_TEST_MODE=1 PYAUTO_SMALL_DATASETS=1 PYAUTO_FAST_PLOTS=1): base crashes (sigma=-0.07…viagraphical.laplace.newton); with the fix the guide runs to completion (exit 0, fullMeanFieldoutput).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 (raisingexc.MessageException), instead of propagating the exception. Internal to the EP hierarchical-factor machinery.autofit.messages.normal.assert_sigma_non_negative— exception message text corrected (theRelativeWidthModifierpath now usesabs(mean), so it is no longer the likely source); thesigma<0rejection itself is unchanged.Migration
Validation checklist (--auto run — plan was not pre-approved)
safe, cap:bug→supervised)test_run2026-07-09 + 58 stale parked scripts; human-acknowledged at the ship checkpoint as unrelated to this branch)Generated by the PyAutoLabs agent workflow.