r - Generating random numbers from various distributions in CUDA -
i playing around doing mcmc on gpu, , need implementations various samplers, written cuda.
most of posts i've seen on stackoverflow relate uniform, binomial, , normal sampling. there libraries allow me simplicity , variety of d-p-q-r functions in r (see this page)?
i able sample gamma, normal, binomial, , inverse distributions used in bayesian problems (inverse chi square, inverse gamma), , prefer not have write own using inverse probability transforms , acceptance-rejection sampling.
for gamma distribution, use @ moment. gsl function modified work curand.
__device__ double ran_gamma (curandstate localstate, const double a, const double b){ /* assume > 0 */ if (a < 1){ double u = curand_uniform_double(&localstate); return ran_gamma (localstate, 1.0 + a, b) * pow (u, 1.0 / a); } { double x, v, u; double d = - 1.0 / 3.0; double c = (1.0 / 3.0) / sqrt (d); while (1){ do{ x = curand_normal_double(&localstate); v = 1.0 + c * x; } while (v <= 0); v = v * v * v; u = curand_uniform_double(&localstate); if (u < 1 - 0.0331 * x * x * x * x) break; if (log (u) < 0.5 * x * x + d * (1 - v + log (v))) break; } return b * d * v; } }
Comments
Post a Comment