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

What is self.loc in MixtureCDFFlow class? #8

Open
ovshake opened this issue Jul 19, 2020 · 1 comment
Open

What is self.loc in MixtureCDFFlow class? #8

ovshake opened this issue Jul 19, 2020 · 1 comment

Comments

@ovshake
Copy link

ovshake commented Jul 19, 2020

I am trying to implement the 1D flow as shown in Flow Models Demos (Official).ipynb. I can't figure out what is self.loc in the MixtureCDFFlow class. Also, what does self.n_components denote?
This is the code

 def flow(self, x):
        # set up mixture distribution
        weights = F.softmax(self.weight_logits, dim=0).unsqueeze(0).repeat(x.shape[0], 1)
        mixture_dist = self.mixture_dist(self.loc, self.log_scale.exp())
        x_repeat = x.unsqueeze(1).repeat(1, self.n_components)

        # z = cdf of x
        z = (mixture_dist.cdf(x_repeat) * weights).sum(dim=1)

        # log_det = log dz/dx = log pdf(x)
        log_det = (mixture_dist.log_prob(x_repeat).exp() * weights).sum(dim=1).log()

        return z, log_det

Some help is really appreciated.

Thanks

@suryabulusu
Copy link

  • z = sum over k = 1...3 ( pi_k * normal_cdf (mu_k, sig_k) ) where n_components = 3

  • loc and exp(log_scale) are [mu_1, mu_2, mu_3] and [sig_1, sig_2, sig_3] respectively.

  • pi_k are the weights of each component.

CDFs map to [0, 1] and we can use uniform distribution for z. Mixture CDFs are preferred as they are more expressive.
Hope this helps!

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

2 participants