BVLC/caffe — pull request #297 by jeffdonahue (2014-04-07 03:04:51+00:00)
Title: Strange bug(?) with Boost RNG

I've observed some weird behavior with the new Boost RNG that I can't explain or fix, and am posting a PR here with test cases so others can hopefully reproduce the behavior. An explanation of the steps taken in the test `TestRngGaussianTimesBernoulli` to demonstrate the weird behavior:

1) Take N (= 10K) samples from a 0-mean Gaussian using `caffe_vRngGaussian` -- check that the samples are roughly half positive and half negative (with no zeros) as expected. These checks pass.
2) Take N samples from a Bernoulli with p = 0.3 using `caffe_vRngBernoulli` -- check that roughly N*p are ones and N*(1-p) are zeros (with no other values) as expected. These checks pass.
3) Element-wise multiply the Gaussian samples with the Bernoulli samples. Of the resulting product, check that roughly N*(1-p) are zeros as expected -- this check passes. Check that roughly N*p/2 are positive and N*p/2 are negative -- this check does NOT pass - instead, of the ~N*p non-zero elements, roughly 2/3 are positive and 1/3 are negative, indicating some kind of correlation between the Gaussian result and the Bernoulli result.

I also added the equivalent test but replacing the Gaussian with a uniform distribution on the interval [-1, 1] using `caffe_vRngUniform`. In this case the result indicates an exact inverse correlation between the Bernoulli and Gaussian results -- the product consists of ONLY negative values.

If anyone has a suggestion for what the problem might be and/or how to fix it, please comment here (and/or send a PR with the fix if you like). Thanks!