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

Add option to provide your own PDF for the latent variables in FlowSequential (not necessarily Gaussian) #15

Open
joaompereira opened this issue Jan 8, 2020 · 0 comments

Comments

@joaompereira
Copy link

In our application, we've found the need to provide the PDF for the latent variables (in our case, it is useful that the PDF depends on the conditional inputs). We've found a small fix to your code that let's you have this option, by just adding an init method to FlowSequential and changing log_probs accordingly. I'll share the different code here. Here is the added init method

    def __init__(self, *args, log_probs = 'gaussian'):
        super(FlowSequential,self).__init__(*args)
        if log_probs = 'gaussian'
            def __log_probs(x, *_):
                return torch.sum(-0.5 * x ** 2 - 0.5 * math.log(2 * math.pi),
                                                            -1, keepdim=True)
            self.log_probs = __log_probs
        else:
            self.log_probs = log_probs

and here is the modified log_probs.

    def log_probs(self, inputs, cond_inputs = None):
        u, log_jacob = self(inputs, cond_inputs)
        log_probs = self.log_probs(u, cond_inputs)
        return (log_probs + log_jacob).sum(-1, keepdim=True)

Then, to provide your own PDF, just do
model = FlowSequential(*modules,logprobs=your_own_PDF)

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

No branches or pull requests

1 participant