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

KL for discrete distributions #91

Open
alicanb opened this issue Jan 15, 2018 · 19 comments
Open

KL for discrete distributions #91

alicanb opened this issue Jan 15, 2018 · 19 comments

Comments

@alicanb
Copy link
Collaborator

alicanb commented Jan 15, 2018

No description provided.

@vishwakftw
Copy link

vishwakftw commented Jan 22, 2018

  • Bernoulli
  • Binomial
  • Categorical
  • Geometric
  • Multinomial (intractable)
  • Poisson (after merge with master)
  • OneHotCategorical

Are there more?

@fritzo
Copy link

fritzo commented Jan 22, 2018

You can get OneHotCategorical for free from Categorical. There is also Multinomial but I believe that is intractable.

@vishwakftw
Copy link

I will take this up for the time being. @fritzo @alicanb

@alicanb
Copy link
Collaborator Author

alicanb commented Jan 30, 2018 via email

@vishwakftw
Copy link

vishwakftw commented Jan 30, 2018

@alicanb Yeah, having a table would be a great idea. I don't know if it should be added in the Design doc. I think it will be better to have it in Markdown too.

@vishwakftw vishwakftw removed their assignment Jan 30, 2018
@vishwakftw
Copy link

I think I will look at this later. Sorry @alicanb

@fritzo
Copy link

fritzo commented Jun 21, 2018

@vishwakftw Do you think it's easy to compute KL(Binomial(n,p), Poisson(lambda))? @alicanb and I were looking at this the other day but got stuck.

@vishwakftw
Copy link

vishwakftw commented Jun 21, 2018

At a glance, I think there might be issues with the finite sum of the exponential term in the Poisson's pmf. Furthermore, the nCk term could also cause issues.

I will have a detailed look at it and revert to you tomorrow if that is fine.

@alicanb
Copy link
Collaborator Author

alicanb commented Jun 21, 2018

We can always calculate this numerically since binomial has enumerate_support, in fact I remember discussing adding default KL for distributions with enumerate_support with somebody (@rachtsingh was it you?)

@vishwakftw
Copy link

@fritzo I am stuck at one term in the summation. This is the one:

image

@alicanb It should be possible for finite support with some extra ops, but getting a closed form solution might be hard.

@vishwakftw
Copy link

The summation should actually not be hard to implement in PyTorch. Something like this should do the trick:

def this_sum(n, p):
    factor = n.lgamma.exp()
    valrange = torch.arange(0, n + 1).lgamma()
    return factor * (reverse(valrange) / (valrange + reverse(valrange)).exp()) * p.pow(valrange) * (1 - p).pow(reverse(valrange))).sum(-1)

@vishwakftw
Copy link

vishwakftw commented Jun 24, 2018

@fritzo @alicanb We could use the Ramanujan's approximation for computing this sum. The asymptotic error is O(1/n^{3}) . Let me know what you think.

EDIT: it might be hard to denote moments using this approximation, so we can also settle for Stirling's approximation.

@fritzo
Copy link

fritzo commented Jun 25, 2018

@vishwakftw I like the idea of implementing the exact sum. It should be cheap on GPUs, and I've seldom seen binomial used with large n.

@vishwakftw
Copy link

@fritzo Sure, we could do that. I will send in a PR soon.

@alicanb
Copy link
Collaborator Author

alicanb commented Jun 25, 2018

Give me a few hours, I already have something that tackles Binom-Binom, Binom-Geo, and Binom-Poi KLs

@vishwakftw
Copy link

Amazing!! Thanks @alicanb .

@vishwakftw
Copy link

@alicanb @fritzo I have prepared a script to show existing KL-div pairs in Markdown format. This is the script.

@alicanb
Copy link
Collaborator Author

alicanb commented Jun 26, 2018

@vishwakftw That's so cool, is there a way we can put that in docs?

@vishwakftw
Copy link

It should be possible, but the issue is that the table is too big.

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

3 participants