# Deep learning: what is done with sampling in practice?

I have come against a small issue when implementing some deep learning techniques.

Sometimes, if one is implementing a classic Bernoulli-Bernoulli Restricted Boltzmann Machine (RBM), the sampling functions (i.e. particularly the function that samples the hidden units given the visible units, $p(h|v)$) requires using a binomial distribution.

However, I have found in my code that it's entirely possible to generate a row in matrix using the binomial distribution (using the visible means computed from a propagate down function as the p value and $n = 1$) with all 0's or all 1's. This can lead to certain numerical problems (akin to numerical analysis issues such as NaN's appearing in the computation given that later matrix operations use division or Log) in later computations.

My question is:

What is done in practice (obviously most deep learning papers to my knowledge, as well as tutorial sites, do not address these small technical issues) in such cases?

A binomial distribution sampling could generate a row in a matrix with all 0's. What I've done is decided that I need to check for such cases and add some very slight noise to one of these 0's (let's say I write a small sub-routine to check that a matrix doesn't contain any rows of all 0's and will then randomly select a cell in any such bad-case-row and then, insert a noise value such as $10^{-2}$).

I know I'm giving up some accuracy in introducing some slight noise to nudge the computation in the right direction, but once I do I get correct predictions/label constructions (for all cases) so it appears my code works fine. So while I believe I may have found one technical workaround, I would like to know what is actually done to handle this scenario?

Update: Is this a technical challenge no one really encounters? Is there something special about Python (and usu. Theano) that magically ensures there are never any sample rows in a sampled matrix that are all 0's or all 1's? even though a binomial sampling is used)?