Skip to content

Priors & messages: 9 confirmed bugs — guidance wanted on 5 decisions #1331

Open

Description

@Jammy2211

An AI-assisted audit of autofit/mapper/prior/ and autofit/messages/ (follow-up to the LogUniform fix, #1329) found 9 real bugs plus refactor ideas. Every finding has now been independently re-verified on main @ 0f26ff2d8 — reproductions and full detail in #1330. This issue is the decision hub: maintainer guidance + contributor input wanted, especially from anyone with exponential-family / EP background (@rhayes777).

Will fix as one batch — no decision needed

  • LogGaussianPrior.with_limits crashes on first call (TypeError: passes lower_limit/upper_limit kwargs the ctor doesn't accept); _new_for_base_message also broken. Fix: drop the kwargs — a log-Gaussian has support (0, ∞).
  • UniformPrior.logpdf fails on array input (scalar-only boundary snap, acknowledged # TODO). Fix: vectorise with np.where.
  • TruncatedNormalMessage.log_partition is missing the Gaussian term — via the generic exponential-family interface the pdf integrates to 2.27, not 1.0 (error factor exactly σ·exp(μ²/2σ²)). Sampling and log_prior_from_value are unaffected; the wrong path is the one the EP machinery consumes. Fix: add the Gaussian log-partition (as NormalMessage already does).
  • FixedMessage.logpdf_cache is an unbounded class-level dict that also returns an aliased mutable array (mutating a result corrupts later calls). Fix: np.zeros_like(x), no cache.

Decisions wanted (my recommendation in bold)

  1. Beta projection clamp is a no-op (inv_beta_suffstats clamps into a local that's immediately overwritten, so negative α, β escape with only a warning). When Newton–Raphson goes negative: raise (a failed projection shouldn't be silently patched to 0.5), or make the clamp work as originally intended?
  2. NormalMessage accepts negative sigma (the assert is commented out; TruncatedNormalMessage rejects it, so the two disagree). Enforce reject σ ≤ 0 strictly, or reject only σ < 0 and permit a σ = 0 point-mass?
  3. GammaMessage.from_mode(mode, V) builds the wrong variance — inversely wrong: request var 0.25, get 2.0; request 4.0, get 0.235 (α = 1 + m²·V has V upside-down). Which invariant should from_mode preserve: match mean + variance (α = m²/V, β = m/V — consistent with the Normal family), the α ≥ 1-guaranteed variant (α = 1 + m²/V), or solve the quadratic to match mode + variance exactly?
  4. log_prior_from_value normalisation is inconsistent: Uniform/LogUniform/Gaussian/LogGaussian drop their additive constants; TruncatedNormal returns the fully normalised density. Posterior shape is unaffected either way, but evidence/Bayes-factor arithmetic and logpdf users see silently different conventions. Option A: drop constants everywhere, document it as the contract, add an optional per-prior log-normaliser hook — or Option B: fully normalised density everywhere (scipy convention, touches every prior + JAX paths)?
  5. RelativeWidthModifier (the default prior-passing width, 0.5·mean) yields σ = 0 for means at zero and σ < 0 for negative means — silently, until (2) lands. Scope: minimal — use abs(mean) with an optional configurable absolute floor, mandatory floor with config migration, or a full width-modifier redesign?

Parked (design work, sequenced behind the EP framework review)

Property-based prior tests (after the fixes land), TransformedMessage semantics documentation, the single-source-of-truth density refactor, the Prior/Message hierarchy collapse, and bijector-library migration. These will be shaped by the EP statistics review now underway and get their own design issues later.

🤖 Generated with Claude Code

Activity

  1. Jammy2211 commented on Jul 10, 2026

    @Jammy2211
    CollaboratorAuthor

    Status update — fixes are landing.

    • Phase 1 MERGED (c0b6c94b8 via fix(priors): correctness batch — crashes, log-partition, projections #1345, tracker fix(priors): correctness batch — crashes, log-partition, projections #1344 closed): the 4 no-decision fixes plus Decisions 1 (Beta clamp → raise), 3 (Gamma from_mode matches mean+variance), and 4 (Option A — drop-constants contract documented everywhere, TruncatedNormal brought into line, new Prior.log_normalisation() hook recovers the constant for evidence users). Statistics independently re-verified on Fable; full suite 1437/14; Emcee bias-check smoke confirms posteriors unchanged.
    • Phase 2 filed: fix(priors): width-modifier safety + strict sigma>0 (Phase 2 of #1331) #1346 — Decisions 5 + 2 as one PR (the width-modifier pair): RelativeWidthModifier → abs(mean) + opt-in absolute_floor, strict σ ≤ 0 rejection on both message classes, and a parameter-named PriorException when a chained width still comes out ≤ 0. This is the only leg that changes sampling behaviour in chained fits (for the better); split out and sequenced deliberately.
    • Still parked here (design work, post-EP-review as planned): property-based prior tests (09), TransformedMessage semantics doc (11 — code half shipped in Phase 1's docstrings), single-source density refactor (12), Prior/Message collapse (13), bijector migration (14).
  2. Jammy2211 commented on Jul 14, 2026

    @Jammy2211
    CollaboratorAuthor

    Resolved — all 9 bugs fixed, all 5 decisions taken (2026-07-10)

    Recording the outcome so this hub reflects reality. Everything below is merged and verified live on main (2026-07-14).

    Batch fixes (no decision) — PR #1345

    • LogGaussianPrior.with_limits crash — fixed (bad ctor kwargs dropped; _new_for_base_message repaired)
    • UniformPrior.logpdf array input — vectorised with np.where
    • TruncatedNormalMessage.log_partition (pdf integrated to 2.27) — Gaussian cumulant added → integrates to 1.0; EP log_norm telescope identity holds
    • FixedMessage.logpdf_cache aliasing — cache removed, returns fresh np.zeros_like(x)

    Decisions — PRs #1345 (1, 3, 4) and #1348 (2, 5)

    1. Beta projection clamp → raises ValueError on negative Newton–Raphson projection (no silent escape).
    2. NormalMessage negative σ → σ < 0 rejected, σ = 0 permitted. Evidence-based deviation from the strict recommendation: strict σ ≤ 0 broke 20 tests across the deliberate σ=0 point-mass idiom (latent simple_model_for_kwargs, from_mode(covariance=0), model_centred_relative). The two message classes now agree. Strict would require a first-class point-mass representation first (separate design prompt on request).
    3. Gamma from_mode → match mean+variance (α = m²/V, β = m/V), consistent with the Normal family. α < 1 now reachable when V > m² (accepted trade).
    4. log_prior_from_value normalisation → Option A: drop additive constants everywhere as the documented contract, plus an opt-in Prior.log_normalisation() hook recovering the constant for evidence/Bayes-factor users.
    5. RelativeWidthModifier → abs(mean) + optional absolute_floor; the default prior-passing path now raises a parameter-named PriorException on a non-positive computed width instead of silently freezing the parameter.

    Regression coverage: test_priors_messages_fixes_1331.py (12) + test_prior_width_safety.py (11); full suite green (1447 passed / 14 skipped).

    Leaving this issue open only for the parked design items (property-based prior tests, TransformedMessage semantics docs, single-source density refactor, Prior/Message hierarchy collapse, bijector migration), which are sequenced behind the EP framework review (#1332).

  3. Jammy2211 commented on Aug 18, 2026

    @Jammy2211
    CollaboratorAuthor

    Parked-items status (2026-08-18) — the design backlog this hub stayed open for is now fully in motion:

    Once #1499 merges and #1500 has a direction, everything this hub tracks is either shipped or has its own live issue — it can then close in favour of #1500.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions