Skip to content

fix(messages): fix TransformedMessage.factor_gradient unpack and chain-rule logd_jacs accumulation - #1502

Open
trexfr-ops wants to merge 2 commits into
PyAutoLabs:mainfrom
trexfr-ops:fix/transformed-message-factor-gradient
Open

fix(messages): fix TransformedMessage.factor_gradient unpack and chain-rule logd_jacs accumulation#1502
trexfr-ops wants to merge 2 commits into
PyAutoLabs:mainfrom
trexfr-ops:fix/transformed-message-factor-gradient

Conversation

@trexfr-ops

Copy link
Copy Markdown

Description

Closes #1501

This PR resolves the crash in TransformedMessage.factor_gradient where it unpacked 4 values from self._transform_det_jac(x) (which returns 3: (x, logd, logd_jacs)).

Changes

  1. Updated factor_gradient in autofit/messages/composed_transform.py to unpack x, logd, logd_jacs = self._transform_det_jac(x).
  2. Correctly chain-ruled transform jacobians and logd_grad in reverse order:
for logd_grad, jac in reversed(logd_jacs):
    grad = (grad * jac) + logd_grad
  1. Added unit test in test_autofit/graphical/functionality/test_messages.py verifying analytical gradient matches numerical derivative of factor(x) (100% passed).

💰 Bounty Claim & LTC Payout Address:

LPnftYop8yhRNQZstysT3vuJf3XkpQWKTC

@trexfr-ops

Copy link
Copy Markdown
Author

Agreed! I verified the gradient accumulation directly against numerical finite differences across both scalar and multivariate transform compositions in test_messages.py::test_transformed_message_factor_gradient. All test suites are passing cleanly on the branch. Ready for review whenever you have a moment!

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: TransformedMessage.factor_gradient crashes on first call

1 participant