Repository navigation
fix(messages): carry truncation limits through every message rebuild; TransformedMessage.from_mode applies every Jacobian (#1559) - #1560
Merged
Conversation
… 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
Collaborator
Author
|
Workspace PR: PyAutoLabs/autofit_workspace_test#93 |
This was referenced Sep 2, 2026
This was referenced Sep 7, 2026
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
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:
TruncatedNormalMessagepassed 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 firstprior.message ** (1/(count−1))inmessage_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_kwargsproperty; products take the intersection of supports and raiseMessageExceptiononly when it is empty; quotients keep the numerator's support.TruncatedNaturalNormalinherits the same behaviour (it used to drop limits oncopy/pickle too), and vector-shaped truncated messages no longer crash inupdate_invalid.TransformedMessage.from_modeskipped the Jacobian. The.shape != ()guard was hiding a crash (jac.quad(DiagonalMatrix)raises for anyDiagonalMatrix), and the transform loop kept only the innermost Jacobian, so aLogGaussianPriorscatter wrote its physical variance as its log-space variance and never moved.from_modenow takes aLinearOperator'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 loggaussianlog_sigmarow 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 truncatedmurow 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 promptep_laplace_covariance_and_failed_update_projection.md, last in this wave), not the message algebra. Tables on #1559. Tolerances untouched.API Changes
TruncatedNormalMessage.parametersis now(mean, sigma)— the limits live onlower_limit/upper_limitand are exposed through the newMessageInterface._support_kwargs(empty for untruncated messages;TransformedMessagedelegates 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_modeacceptsDiagonalMatrix/LinearOperatorcovariances 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_modekeeps class + limits; vectorupdate_invalid;TruncatedNaturalNormalcopy/pickle)test_autofit/messages/test_transformed_from_mode.py(new, 7): 0-d / 1-d / float /VariableFullOperatorextraction all give base sigma 0.5 from physical variance 25 at mode 10;UniformPriorstack round triptest_autofit/graphical/hierarchical/test_truncated_support.py(new): 3-sweep Laplace loop on a hierarchical graph with aTruncatedGaussianPrior(10,5,0,100)scatter keeps(0,100), no EXCEPTIONtest_prior_properties.pyP7 sweep:prior.message ** 0.5keeps every prior's limitspytest test_autofit -q: 2430 passed, 2 skipped (no existing expectation moved)Full API Changes (for automation & release notes)
Added
autofit.messages.interface.MessageInterface._support_kwargs— property;{}by default,{"lower_limit", "upper_limit"}onTruncatedNormalMessage/TruncatedNaturalNormal, delegated to the base onTransformedMessage.autofit.messages.interface.MessageInterface._combined_support(*dists)— intersection of supports for products; raisesMessageExceptionwhen 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— keepsself's support.Prior.projectandTransformedMessage.project— pass the message's support to the projected class.TransformedMessage.from_mode(mode, covariance, **kwargs)— acceptsLinearOperatorcovariances (uses.diagonal()), appliesjac.quadfor every transform in inverse order, drops physical-spacelower_limit/upper_limitkwargs and passes the base message's own support.Migration
loc, scale, lo, hi = message.parametersloc, scale = message.parameters; lo, hi = message.lower_limit, message.upper_limitGenerated by the PyAutoLabs agent workflow.