Database Reference
In-Depth Information
Figure 9.1
Given a method for sampling from the gamma distribution, sampling from
the chi-square and beta distributions is straightforward. The chi-square, of
course, is simply a special case of the gamma distribution so it can be drawn
directly:
public double nextChiSq( double k) { return nextGamma(k/
2,0.5); }
A beta random variable is also drawn by taking advantage of its relationship
with the gamma distribution—in this case, by taking the ratio of one gamma
distribution over the sum of two gamma distributions:
public double nextBeta(double a,double b) {
double x = nextGamma(a,1);
double y = nextGamma(b,1);
return x/(x+y);
}
 
Search WWH ::




Custom Search