Repository navigation
Description
Overview
Phase 1 of the priors/messages correctness batch surfaced by the EP framework review and re-verified on main @ 0f26ff2d8 (reproductions in #1330, decisions resolved on the hub #1331). This is the safe batch: crash fixes, a message log-partition correction, projection guards, and a normalisation-contract cleanup — all EP-isolated or numerically inert for standard non-linear searches. The behaviour-changing width-modifier pair (Decisions 2 + 5) is deliberately split into a separate Phase 2 follow-up because it changes prior-passing widths in search chaining and needs careful ordering + a regression test.
Resolves the awaiting-input state on #1330/#1331 and unblocks the #1332 EP fix batch.
Plan
- Overwriting a prior over-writes the upper / lower limits and resets them to +/- inf #1
LogGaussianPrior.with_limitscrashes on first call — drop the invalidlower_limit/upper_limitkwargs (log-Gaussian support is(0, ∞)); also fixes_new_for_base_message. - model_mapper does not return PpriorLimitException, but Raises it #2
UniformPrior.logpdffails on array input — vectorise withxp.where, keeping the scalar result bit-identical. - Backup results in a non-sim link directory. #4
TruncatedNormalMessage.log_partitionis missing the Gaussian term — via the generic exponential-family interface the pdf integrates to 2.27, not 1.0. Add the Gaussian log-partition (asNormalMessagealready does). This is the path the EP machinery consumes; sampling /log_prior_from_valueare unaffected. - Output results of classic grid search #10
FixedMessage.logpdf_cacheis an unbounded class-level dict that returns an aliased mutable array — drop the cache, returnxp.zeros_like(x). - Decision 1 — Beta projection clamp is a no-op: raise on negative α/β from
inv_beta_suffstatsrather than silently patching to 0.5. - Decision 3 —
GammaMessage.from_mode(mode, V)builds the wrong variance: preserve mean + variance (α = m²/V,β = m/V), consistent with the Normal family. - Decision 4 (Option A) —
log_prior_from_valuenormalisation: document the drop-additive-constants contract, bringTruncatedGaussianPriorinto line (it currently returns the fully-normalised density), and add an optional per-prior log-normaliser hook for evidence/Bayes-factor users. No posterior-shape or nested-sampling change (constants cancel in the MCMC ratio; nested samplers use the unit-cube ppf).
Not in this issue — Phase 2 follow-up: Decision 5 (
RelativeWidthModifier→abs(mean)+ configurable floor) landed with/before Decision 2 (NormalMessagestrictσ > 0), plus amean = 0chained-parameter regression test. Filed separately as this issue nears shipping.
Detailed implementation plan
Affected Repositories
- PyAutoLabs/PyAutoFit (primary)
Branch Survey
| Repository | Current Branch | Dirty? |
|---|---|---|
| ./PyAutoFit | main | clean |
Suggested branch: bug/priors-messages-fixes
Parallel disjoint PyAutoFit claim alongside ep-graphical-docs (#1334, autofit/graphical, awaiting-merge) and ep-diagnostics (#1335, autofit/graphical). This batch lives in autofit/mapper/prior/ + autofit/messages/ — zero file overlap with the graphical subtree.
Implementation Steps
autofit/mapper/prior/log_gaussian.py—with_limits/_new_for_base_message: droplower_limit/upper_limitkwargs.autofit/mapper/prior/uniform.py(+autofit/messages/normal.pyUniformNormalMessage) — vectoriselogpdfwithxp.where; assert scalar path unchanged.autofit/messages/truncated_normal.py— add Gaussian log-partition term; verify generic exp-family pdf integrates to 1.0.autofit/messages/fixed.py—FixedMessage: remove class-levellogpdf_cache, returnxp.zeros_like(x).autofit/messages/(inv_beta_suffstats) — raise on negative α/β.autofit/messages/gamma.py—GammaMessage.from_mode:α = m²/V,β = m/V.autofit/mapper/prior/*.py— Decision 4: docstring contract (constants dropped),TruncatedGaussianPrior.log_prior_from_valuedrops constants, add optional log-normaliser hook.
Key Files
autofit/mapper/prior/log_gaussian.py,uniform.py,truncated_gaussian.pyautofit/messages/truncated_normal.py,normal.py,fixed.py,gamma.py, Beta suff-stats
Testing
Full test_autofit/ suite (numpy-only unit tests) plus per-bug unit tests: with_limits round-trip, uniform array logpdf, truncated log_partition → pdf 1.0 integration, fixed-cache aliasing, beta-projection raise, gamma from_mode mean/var, log_prior drop-constants contract. No public API removals. Downstream workspace impact: none expected.
Activity
Jammy2211 commentedon Jul 10, 2026
Shipped at PR-open — #1345
All 7 Phase-1 fixes are implemented, verified, and up as PR #1345 (
pending-release).Verification story:
test_autofit/suite: 1437 passed, 14 skipped (was 1422/14 on main — the delta is the new regression file + contract-updated truncated tests).logpdfnow equalsscipy.truncnorm.logpdfpointwise to 1e-9 (including the half-bounded prior-passing geometry), the EP productlog_normtelescope identity holds against direct quadrature (the incomplete cumulant was silently breaking it),GammaMessage.from_modereproduces requested mean+variance exactly, and all fivelog_normalisationhooks recover the scipy-normalised densities.autofit_workspace_test/scripts/jax_assertions/priors_xp_dispatch.pyPASS (directly exercises the edited xp-dispatch paths);prior_correctness/emcee_gaussian_bias_check.pyrunning now — result to follow.Two discoveries during implementation (both disclosed in the PR body):
LogGaussianPrior._new_for_base_messagewas doubly broken — beyond the invalid kwargs, it called a nonexistentself.instance().id. It also has zero callers (dead code). Repaired fully rather than half-fixed.inv_beta_suffstats's internalnp.linalg.solveis shape-fragile for multi-element batch inputs — pre-existing and orthogonal to the Decision-1 guard; left untouched, noted for the EP fix-batch follow-up.Next: merge is human (#1345 carries the
--autovalidation checklist). Phase 2 — the width-modifier pair (Decision 5abs(mean)+floor landed with/before Decision 2 strict σ>0, plus amean=0chained-parameter regression test) — gets filed as its own issue now that Phase 1 is at PR-open, per the sequencing analysis (it's the only leg with real sampling-behaviour impact).Jammy2211 commentedon Jul 10, 2026
Smoke complete:
emcee_gaussian_bias_check.pyPASS as well — a real Emcee fit throughlog_prior_from_valuewith unbiased posterior recovery, which empirically confirms the D4 claim that the dropped constants cancel in the Metropolis ratio. All four ship-gate legs green: tests 1437/14 · smoke 2/2 · review CLEAN · Heart YELLOW-acked.Jammy2211 commentedon Jul 10, 2026
Merged —
c0b6c94b8via #1345 (merged-unchanged; pending-release). Phase 2 (Decisions 5+2, the width-modifier pair) is being filed as its own issue now — link to follow on decision hub #1331. Closing this Phase-1 tracker.