andresy/torch — pull request #87 by jucor (2012-12-03 14:39:23+00:00)
Title: Extend Bernoulli distribution to p=0 and p=1.

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](http://www.mathworks.co.uk/matlabcentral/fileexchange/7309-randraw).

The attached patch implements this tolerance and documents it.