Open saatvikshah opened 5 years ago
Really nice write-up!
One comment, 3. we can definitely change the api here ... towards a more standard random
and random_normal
, or even better: rand()
, and randn()
I'd like to work on this as my next issue. One thing I realized while looking at the Random.h is that [0, 1] is not available within dSFMT used for vectorized double generation. So would have to do [0, 1) instead.
That should be fine imo as the boundaries are a set of zero measure i.e. P(x=1)=0
almost surely
As discussed with @karlnapf in #4424, there are several improvements/additions that could be made to the random number generation(RNG) API for SGMatrix/SGVector. Neither take advantage of the
CRandom::fill_array
vectorized RNGs. SGMatrix does not support RNG while SGVector simply loops over the entire legnth callingCMath::random
per index. In summary the proposal is to add the following for both SGMatrix/SGVector:SG*::random()
: Generates random numbers in the [0, 1] range for float types. Generates numbers in [std::numeric_limitsfill_array
vectorized RNG wherever possible and falls back to simple for loop otherwise. These will follow a uniform distribution.SG*::random_normal(mu, sigma)
: Uses SG*::random() followed by a possibly vectorized variant of the Box-Muller transform.SGVector::random(lb, ub)
is publicly exposed already I dont think it can be removed. A SG::random(lb, ub) could be additionally supplied which utilizes SG::random() to generate random numbers more efficiently.Finally, I also think it might be important to benchmark a simple
for-loop
vs.vectorized
variant for these cases.