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 RandomUtil
getInstance.org.apache.commons.math3.random.RandomGenerator
Getter for the fieldrandomGenerator
.static void
main.double
nextBeta
(double alpha, double beta) nextBeta.double
nextChiSquare
(double df) nextChiSquare.double
nextDouble.double
nextExponential
(double lambda) nextExponential.double
nextGamma
(double shape, double scale) nextGamma.double
nextGumbel
(double mu, double beta) nextGumbel.int
nextInt
(int n) nextInt.long
nextLong()
nextLong.double
nextNormal
(double mean, double sd) nextNormal.double
nextPoisson
(double lambda) nextPoisson.double
nextT
(double df) nextT.double
nextTruncatedNormal
(double mean, double sd, double low, double high) nextTruncatedNormal.double
nextUniform
(double low, double high) nextUniform.double
normalCdf
(double mean, double sd, double value) normalCdf.double
normalPdf
(double mean, double sd, double value) normalPdf.void
revertSeed
(long seed) revertSeed.void
setSeed
(long seed) Sets the seed to the given value.static void
This is just the RandomUtil.shuffle method (thanks!) but using the Tetrad RandomUtil to get random numbers.
-
Method Details
-
getInstance
-
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
-
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.
-
nextNormal
public double nextNormal(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
RandomGenerator
object
-
nextLong
public long nextLong()nextLong.
- Returns:
- a long
-