Package edu.cmu.tetrad.util
Class RandomUtil
java.lang.Object
edu.cmu.tetrad.util.RandomUtil
Provides a common random number generator to be used throughout Tetrad, to avoid problems that happen when random
number generators are created more often than once per millisecond. When this happens, the generators are synced, and
there is less randomness than expected.
A seed can be set for the generator using the setSeed method. This is useful if an experiment needs to
be repeated under different conditions. The seed for an experiment can be printed using the getSeed
method.
The 64-bit Mersenne Twister implementation from the COLT library is used to generate random numbers.
To see what distributions are currently supported, look at the methods of the class. These many change over time.
- Version:
- $Id: $Id
- Author:
- josephramsey
-
Method Summary
Modifier and TypeMethodDescriptionstatic RandomUtilgetInstance.org.apache.commons.math3.random.RandomGeneratorGetter for the fieldrandomGenerator.static voidmain.doublenextBeta(double alpha, double beta) nextBeta.doublenextChiSquare(double df) nextChiSquare.doublenextDouble.doublenextExponential(double lambda) nextExponential.doublenextGamma(double shape, double scale) nextGamma.doublenextGaussian(double mean, double sd) nextNormal.doublenextGumbel(double mu, double beta) nextGumbel.intnextInt(int n) nextInt.longnextLong()nextLong.doublenextPoisson(double lambda) nextPoisson.doublenextT(double df) nextT.doublenextTruncatedNormal(double mean, double sd, double low, double high) nextTruncatedNormal.doublenextUniform(double low, double high) nextUniform.doublenormalCdf(double mean, double sd, double value) normalCdf.doublenormalPdf(double mean, double sd, double value) normalPdf.voidrevertSeed(long seed) revertSeed.voidsetSeed(long seed) Sets the seed to the given value.static voidThis is just the RandomUtil.shuffle method (thanks!) but using the Tetrad RandomUtil to get random numbers.
-
Method Details
-
getInstance
getInstance.
- Returns:
- the singleton instance of this class.
-
shuffle
This is just the RandomUtil.shuffle method (thanks!) but using the Tetrad RandomUtil to get random numbers. The purpose of this copying is to allow shuffles to happen deterministically given the Randomutils seed.- Parameters:
list- The list to be shuffled.
-
main
main.
- Parameters:
args- an array ofStringobjects
-
nextInt
public int nextInt(int n) nextInt.
- Parameters:
n- Ibid.- Returns:
- Ibid.
-
nextDouble
public double nextDouble()nextDouble.
- Returns:
- a double
-
nextUniform
public double nextUniform(double low, double high) nextUniform.
- Parameters:
low- Ibid.high- Ibid.- Returns:
- Ibid.
-
nextGaussian
public double nextGaussian(double mean, double sd) nextNormal.
- Parameters:
mean- The mean of the Normal.sd- The standard deviation of the Normal.- Returns:
- Ibid.
-
nextTruncatedNormal
public double nextTruncatedNormal(double mean, double sd, double low, double high) nextTruncatedNormal.
- Parameters:
mean- The mean of the Normal.sd- The standard deviation of the Normal.low- a doublehigh- a double- Returns:
- Ibid.
-
revertSeed
public void revertSeed(long seed) revertSeed.
- Parameters:
seed- a long
-
nextPoisson
public double nextPoisson(double lambda) nextPoisson.
- Parameters:
lambda- A positive real number equal to the expected number of occurrences during a given interval. See Wikipedia.- Returns:
- Ibid.
-
normalPdf
public double normalPdf(double mean, double sd, double value) normalPdf.
- Parameters:
mean- The mean of the normal to be used.sd- The standard deviation of the normal to be used.value- The domain value for the PDF.- Returns:
- Ibid.
-
normalCdf
public double normalCdf(double mean, double sd, double value) normalCdf.
- Parameters:
mean- The mean of the normal to be used.sd- The standard deviation of the normal to be used.value- The domain value for the CDF.- Returns:
- Ibid.
-
nextBeta
public double nextBeta(double alpha, double beta) nextBeta.
- Parameters:
alpha- See Wikipedia. This is the first parameter.beta- See Wikipedia. This is the second parameter.- Returns:
- Ibid.
-
nextT
public double nextT(double df) nextT.
- Parameters:
df- The degrees of freedom. See any stats book.- Returns:
- Ibid.
-
nextExponential
public double nextExponential(double lambda) nextExponential.
- Parameters:
lambda- The rate parameter. See Wikipedia.- Returns:
- Ibid.
-
nextGumbel
public double nextGumbel(double mu, double beta) nextGumbel.
- Parameters:
mu- a doublebeta- a double- Returns:
- Ibid.
-
nextChiSquare
public double nextChiSquare(double df) nextChiSquare.
- Parameters:
df- The degrees of freedom.- Returns:
- Ibid.
-
nextGamma
public double nextGamma(double shape, double scale) nextGamma.
- Parameters:
shape- The shape parameter.scale- The scale parameter.- Returns:
- Ibid.
-
setSeed
public void setSeed(long seed) Sets the seed to the given value.- Parameters:
seed- A long value. Once this seed is set, the behavior of the random number generator is deterministic, so setting the seed can be used to repeat previous behavior.
-
getRandomGenerator
public org.apache.commons.math3.random.RandomGenerator getRandomGenerator()Getter for the field
randomGenerator.- Returns:
- a
RandomGeneratorobject
-
nextLong
public long nextLong()nextLong.
- Returns:
- a long
-