Χ2 RNG is actually a special case of Gamma RNG. The latter in MKL has 3 parameters, shape α, displacement a, and scale factor β. To generate a random number ~Χ2(ν), just let α=ν/2, a=0, and β=2.
(to be added non central Χ2 RNG)
The student t distribution needs also Gaussian RNG. If x~N(0,1), y~Χ2(ν), then x/√ y ~t(ν). Below are the sample codes.
const int n = 10000000;These codes utilized the vector calculation of MKL. Certainly there are also some other methods to generate above ramdom number. For example, we can use the inverse function of cdf(t). But again, MKL haven't implemented many (cumulative) density functions. It will take almost same efforts to assemble a RNG of t.
double df, alpha, beta, mean, sigma, a, gauss[n], chisq[n], t[n], scale;
int method, inc;
method= 0;
df = 4.;
scale = 1./df;
inc = 1;
alpha = df/2.;
beta = 2.;
a = 0.;
mean = 0.;
sigma = 1.;
status = vdRngGaussian( method, stream, n, gauss, mean, sigma );
status = vdRngGamma( method, stream, n, chisq, alpha, a, beta );
dscal(&n, &scale, chisq, &inc); //scales chisq by the 1/df
vdSqrt( n, chisq, chisq ); //square root of chisq
vdDiv( n, gauss, chisq, t ); //generates random t.
没有评论:
发表评论