Skip to content
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

Merged
merged 3 commits into from
Jan 24, 2021

Conversation

fritzo
Copy link
Member

@fritzo fritzo commented Jan 21, 2021

Port of pyro-ppl/pyro#2746
Fixes a bug on the forum.

This PR:

  • refactors ._unexpand() into ._unwrap() to handle arbitrary interleaved Independent and ExpandedDistribution;
  • uses ._unwrap() in TransformedDistribution
  • updates TransformDistribution computation of event_dim to support batched transforms applied to scalar base distributions.

Tested

  • added new test cases

@fritzo fritzo added bug Something isn't working awaiting review labels Jan 21, 2021
@fritzo fritzo requested a review from fehiepsi January 21, 2021 23:00
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)
Copy link
Member

@fehiepsi fehiepsi Jan 22, 2021

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)

Copy link
Member Author

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 😄

Copy link
Member

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!

@fehiepsi fehiepsi mentioned this pull request Jan 23, 2021
3 tasks
@fehiepsi fehiepsi merged commit 7892f2b into master Jan 24, 2021
@fehiepsi fehiepsi deleted the fix-transform-reparam branch January 24, 2021 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants