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

Ensure BlockNeuralAutoregressiveTransform maps real->real #1897

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danielward27
Copy link
Contributor

This fixes #1655 by changing BNAF activation to $y=\text{tanh}(x) + cx$, by default (with c=0.01). This ensures the transform maps from real->real, which e.g.

  1. Means BlockNeuralAutoregressiveTransform will have the correct codomain (currently set as real_vector)
  2. Unbounded distributions transformed using the transform will remain unbounded
  3. Transforming a distribution with the inverse transformation will now lead to properly normalised densities

Let me know if you think there are any problems with this solution.

@fehiepsi
Copy link
Member

Maybe using LeakyReLU likes in the paper instead?

By the way, is there a reference for LeakyTanh?

@danielward27
Copy link
Contributor Author

I believe that all the results from the paper use tanh. From personal experience (on admittedly a very limited set of applications), leaky relu performs far worse than either tanh or leaky tanh.

No, I don't have a reference for it, I just chose it to solve the problem to ensure dy/dx is at least a threshold value, whilst maintaining similar results on a couple toy density estimation tasks.

I completely understand if you'd prefer to keep it to how it is defined in the paper, but IMO the other issues are bound to arise some point e.g. people expecting (sensibly defined) BNAF guides to be supported on the same set as the true posterior, or expecting normalised densities when transforming with the inverse.

"""
An implementation of Block Neural Autoregressive neural network.

In contrast to the original paper, by default, we use ``LeakyTanh`` as the
activation, defined as :math:`y=Tanh(x) + cx` with :math:`c` being a small constant,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: c being a small constant (default to 0.01)

@fehiepsi
Copy link
Member

LGTM! Could you double check if the change still works for https://num.pyro.ai/en/stable/examples/covtype.html and https://num.pyro.ai/en/stable/examples/neutra.html tutorials?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Block Neural Autoregressive Flow density not properly normalised
2 participants