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

Extend Bernoulli distribution to p=0 and p=1 #87

Merged
merged 2 commits into from
Dec 3, 2012

Conversation

jucor
Copy link
Contributor

@jucor jucor commented Dec 3, 2012

So far, torch.bernoulli(p) requires 0 < p < 1. While this is strictly speaking mathematically correct, allowing in practice p = 0 and p = 1 to sample from the limit constant case is very convenient in many algorithms (eg. over-parametrization of a state space, where neurons can degenerate with a weight arbitrarily close to 0).

This tolerance for p=0 and p=1 is implemented in Matlab's Stat Toolbox's binornd(), as well as in the very useful Randraw package.

The attached patch implements this tolerance and documents it.

@clementfarabet
Copy link
Member

It makes sense to me. I actually wrote an 'if then' somewhere recently to generate distributions with p=0 :-).

Everybody ok with that?

@andresy
Copy link
Member

andresy commented Dec 3, 2012

Sure!

andresy added a commit that referenced this pull request Dec 3, 2012
Extend Bernoulli distribution to p=0 and p=1
@andresy andresy merged commit 168f622 into torch:master Dec 3, 2012
@jucor
Copy link
Contributor Author

jucor commented Dec 3, 2012

Great, thanks for the reactivity :-) [I was too lazy to use the 'if then' used by Clement]

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

Successfully merging this pull request may close these issues.

3 participants