-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make TransformReparam compatible with .to_event() #886
Conversation
numpyro/infer/reparam.py
Outdated
decentered_fn = type(fn)(**params).expand(batch_shape) | ||
decentered_fn = type(fn)(**params) | ||
decentered_fn = self._wrap(decentered_fn, event_dim) | ||
decentered_fn = decentered_fn.expand(batch_shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed! We should correct event_dim first, then doing expand
. However, this might raise an issue for the case:
dist.Normal(0, 1).expand([10]).to_event(1)
, where decentered_fn = dist.Normal(0, 1)
and it can't be reinterpreted. I think we can do something like
decentered_fn = self._wrap(decentered_fn.expand(batch_shape + event_shape), event_dim)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it took me a while to understand. I just pushed an update to the ._wrap()
method which seems clean 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! It looks great!
3b7f154
to
90441ba
Compare
Port of pyro-ppl/pyro#2746
Fixes a bug on the forum.
This PR:
._unexpand()
into._unwrap()
to handle arbitrary interleavedIndependent
andExpandedDistribution
;._unwrap()
inTransformedDistribution
TransformDistribution
computation ofevent_dim
to support batched transforms applied to scalar base distributions.Tested