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

Normalizing flows, transforms as Funsors? #309

Closed
fritzo opened this issue Jan 30, 2020 · 2 comments
Closed

Normalizing flows, transforms as Funsors? #309

fritzo opened this issue Jan 30, 2020 · 2 comments
Assignees

Comments

@fritzo
Copy link
Member

fritzo commented Jan 30, 2020

How would we implement normalizing flows / Transforms in Funsor?

As a first guess, each transform would be a funsor with one free variable of the same domain as its output, and we would have a .inv attribute like torch.distributions.Transform.inv to get the inverse transform. Additionally there would be rules for

  • eager substitution t(x) which simply calls the forward transform
  • inverse followed by eager substitution t.inv(x) which calls the inverse transform
  • eager substitution of Deltas
    Delta("x", x, log_density)(x=t("y"))
        => Delta("y", t.inv(x), log_density - t.log_abs_det_jacobian(x))
  • eager reduce of a substitution
    f(x=t(y)).reduce(ops.logaddexp, "y")
        => (f(x) + t.inv.log_abs_det_jacobian(x)).reduce(ops.logaddexp, "x")
  • other reduction rules?

I think we could implement this as a single class that took a PyTorch/NumPyro transform object

class Transform(Funsor):  # or maybe Bijector?
    "Funsor backed by a PyTorch transform object."
    def __init__(self, transform):
        self.transform = transform
    @property
    def inv(self):
        return Transform(self.transform.inv)
    def eager_subs(self, subs):
        ...
        return Tensor(self.transform(x.data))
    ...

cc @stefanwebb

@eb8680 eb8680 self-assigned this Apr 21, 2020
@stefanwebb stefanwebb self-assigned this Jul 27, 2020
@fritzo
Copy link
Member Author

fritzo commented Aug 7, 2020

Note @eb8680 and I sketched one possible direction in https://github.com/pyro-ppl/funsor/tree/lebesgue

@eb8680
Copy link
Member

eb8680 commented Jan 27, 2021

I'm going to close this as resolved by #365, #427 and #442. We can open a new issue if we decide to revisit the design.

@eb8680 eb8680 closed this as completed Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants