package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
/**
* This class implements random variate generators with the
* chi square distribution with n > 0 degrees of freedom.
* Its density function is
*
*
*
* f (x) = xn/2-1e-x/2/(2n/2Γ(n/2)) for x > 0, 0 elsewhere
*
* where
* Γ(x) is the gamma function defined
* in {@link GammaGen}.
*
*
* The (non-static) nextDouble method simply calls inverseF on the
* distribution.
*
*/
public class ChiSquareGen extends RandomVariateGen {
protected int n = -1;
/**
* Creates a chi square random variate generator with
* n degrees of freedom, using stream s.
*
*/
public ChiSquareGen (RandomStream s, int n) {
super (s, new ChiSquareDist(n));
setParams (n);
}
/**
* Create a new generator for the distribution dist
* and stream s.
*
*/
public ChiSquareGen (RandomStream s, ChiSquareDist dist) {
super (s, dist);
if (dist != null)
setParams (dist.getN ());
}
/**
* Generates a new variate from the chi square distribution
* with n degrees of freedom, using stream s.
*
*/
public static double nextDouble (RandomStream s, int n) {
return ChiSquareDist.inverseF (n, s.nextDouble());
}
/**
* Returns the value of n for this object.
*
*
*/
public int getN() {
return n;
}
protected void setParams (int n) {
if (n <= 0)
throw new IllegalArgumentException ("n <= 0");
this.n = n;
}
}
Ads help maintain this website.