Skip to content

fix(messages): carry truncation limits through every message rebuild; TransformedMessage.from_mode applies every Jacobian (#1559) - #1560

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/ep-message-support
Sep 2, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/ep-message-support

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Closes #1559. Found by the analytic Gaussian benchmark (autofit_workspace_test#91 / PR #92). Two message-layer defects made every non-Gaussian hyper-prior family in an EP graph wrong from the first sweep:

  • D4 — truncation limits lost. TruncatedNormalMessage passed its limits as positional parameters, so every natural-parameter rebuild (__pow__, products, quotients, from_natural_parameters) came back as (mean, sigma) with the limits reset to (−inf, inf) — starting with the very first prior.message ** (1/(count−1)) in message_dict. The limits are now message state, carried through every rebuild (copy, __getitem__, merge, scalar ops, __pow__, update_invalid, _init_kwargs, pickle) by a _support_kwargs property; products take the intersection of supports and raise MessageException only when it is empty; quotients keep the numerator's support. TruncatedNaturalNormal inherits the same behaviour (it used to drop limits on copy/pickle too), and vector-shaped truncated messages no longer crash in update_invalid.
  • D5 — TransformedMessage.from_mode skipped the Jacobian. The .shape != () guard was hiding a crash (jac.quad(DiagonalMatrix) raises for any DiagonalMatrix), and the transform loop kept only the innermost Jacobian, so a LogGaussianPrior scatter wrote its physical variance as its log-space variance and never moved. from_mode now takes a LinearOperator's diagonal, accumulates every Jacobian in the stack in the inverse order (UniformPrior(0,10) round-trips exactly at modes 2/5/8), and never passes physical-space limits to the base message.

Referee after this PR (shimmed read-out, see API Changes): the truncated family's scatter message reports limits (0, 100) (was (−inf, inf)); the loggaussian log_sigma row moves off its start (2.3026 → 1.5459 ± 0.167 vs closed form 1.8338 ± 0.361) and its hierarchical updates go from 150 BAD_PROJECTION to 91 BAD_PROJECTION / 59 SUCCESS. The truncated mu row does not pass yet: with the gradient fixed (#1558) the Laplace projection now actually runs and drives the scatter to ~2e-4 whether or not the limits are carried — that is the Laplace-covariance defect (Mind prompt ep_laplace_covariance_and_failed_update_projection.md, last in this wave), not the message algebra. Tables on #1559. Tolerances untouched.

API Changes

TruncatedNormalMessage.parameters is now (mean, sigma) — the limits live on lower_limit/upper_limit and are exposed through the new MessageInterface._support_kwargs (empty for untruncated messages; TransformedMessage delegates to its base). Code that unpacked the 4-tuple must read the attributes instead (one known consumer: autofit_workspace_test/scripts/graphical/analytic_autofit.py, workspace PR to follow). Products of messages with different supports now intersect (empty intersection raises); TransformedMessage.from_mode accepts DiagonalMatrix/LinearOperator covariances and applies every Jacobian. Pickles written before this change still load.
See full details below.

Test Plan

  • test_autofit/messages/test_truncated_normal.py +19 (11-way support-survival sweep incl. pickle and old 3-tuple payloads; Truncated × Normal keeps (0,100); mismatched supports intersect / raise; from_mode keeps class + limits; vector update_invalid; TruncatedNaturalNormal copy/pickle)
  • test_autofit/messages/test_transformed_from_mode.py (new, 7): 0-d / 1-d / float / VariableFullOperator extraction all give base sigma 0.5 from physical variance 25 at mode 10; UniformPrior stack round trip
  • test_autofit/graphical/hierarchical/test_truncated_support.py (new): 3-sweep Laplace loop on a hierarchical graph with a TruncatedGaussianPrior(10,5,0,100) scatter keeps (0,100), no EXCEPTION
  • test_prior_properties.py P7 sweep: prior.message ** 0.5 keeps every prior's limits
  • pytest test_autofit -q: 2430 passed, 2 skipped (no existing expectation moved)
  • CI green (unittest 3.12 / 3.13 / nojax, docs)
Full API Changes (for automation & release notes)

Added

  • autofit.messages.interface.MessageInterface._support_kwargs — property; {} by default, {"lower_limit", "upper_limit"} on TruncatedNormalMessage / TruncatedNaturalNormal, delegated to the base on TransformedMessage.
  • autofit.messages.interface.MessageInterface._combined_support(*dists) — intersection of supports for products; raises MessageException when empty.

Changed Behaviour

  • TruncatedNormalMessage.parameters — (mean, sigma) (was (mean, sigma, lower_limit, upper_limit)); the limits are attributes.
  • AbstractMessage.copy / __getitem__ / merge / __mul__ / __truediv__ / __pow__ / update_invalid / _init_kwargs / __reduce__ — forward _support_kwargs; _reconstruct(cls, parameters, log_norm, id_, support_kwargs=None, *args) accepts old 3-tuple payloads.
  • MessageInterface.sum_natural_parameters — result support = intersection of operand supports; sub_natural_parameters — keeps self's support.
  • Prior.project and TransformedMessage.project — pass the message's support to the projected class.
  • TransformedMessage.from_mode(mode, covariance, **kwargs) — accepts LinearOperator covariances (uses .diagonal()), applies jac.quad for every transform in inverse order, drops physical-space lower_limit/upper_limit kwargs and passes the base message's own support.

Migration

  • Before: loc, scale, lo, hi = message.parameters
  • After: loc, scale = message.parameters; lo, hi = message.lower_limit, message.upper_limit

Generated by the PyAutoLabs agent workflow.

… TransformedMessage.from_mode applies every Jacobian to DiagonalMatrix covariances (#1559)

D4: the (lower_limit, upper_limit) of a TruncatedNormalMessage are support
state, not natural parameters. They are no longer positional parameters and
are forwarded via a `_support_kwargs` property at every rebuild site (copy,
__getitem__, merge, scalar mul/div, __pow__, update_invalid, _init_kwargs,
sum/sub_natural_parameters, project callers, pickle). Products take the
intersection of supports and raise MessageException only when empty;
quotients keep self's support. Old 3-tuple pickle payloads still load.

D5: TransformedMessage.from_mode reduces a LinearOperator covariance to its
diagonal, accumulates jac.quad through every transform (outermost first,
the inverse of `variance`'s invquad composition) and never passes physical
limits to the base message.

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

Copy link
Copy Markdown
Collaborator Author

Workspace PR: PyAutoLabs/autofit_workspace_test#93

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(messages): truncation limits lost on natural-parameter ops; TransformedMessage.from_mode skips the Jacobian (EP)

1 participant