Package cc.mallet.util
Class Randoms
- java.lang.Object
-
- java.util.Random
-
- cc.mallet.util.Randoms
-
- All Implemented Interfaces:
java.io.Serializable
public class Randoms extends java.util.Random
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static double
ONE_OVER_E
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Random
asJavaRandom()
Deprecated.static void
main(java.lang.String[] args)
double
nextBeta(double alpha, double beta)
Return a random double drawn from a Beta distribution with mean a/(a+b) and variance ab/((a+b+1)(a+b)^2).java.util.BitSet
nextBitSet(int size, double p)
Return a random BitSet with "size" bits, each having probability p of being true.boolean
nextBoolean()
Return a random boolean, equally likely to be true or false.boolean
nextBoolean(double p)
Return a random boolean, with probability p of being true.double
nextChiSq()
Return a random double drawn from an Chi-squarted distribution with mean 1 and variance 2.double
nextChiSq(int df)
Return a random double drawn from an Chi-squared distribution with mean df and variance 2*df.double
nextChiSq(int df, double lambda)
Return a random double drawn from an Chi-squared distribution with mean df+lambda and variance 2*df.int
nextDiscrete(double[] a)
Draw a single sample from multinomial "a".int
nextDiscrete(double[] a, double sum)
draw a single sample from (unnormalized) multinomial "a", with normalizing factor "sum".double
nextExp()
Return a random double drawn from an Exponential distribution with mean 1 and variance 1.double
nextExp(double beta)
Return a random double drawn from an Exponential distribution with mean beta and variance beta^2.double
nextExp(double beta, double lambda)
Return a random double drawn from an Exponential distribution with mean beta+lambda and variance beta^2.double
nextGamma()
Return a random double drawn from a Gamma distribution with mean 1.0 and variance 1.0.double
nextGamma(double alpha)
Return a random double drawn from a Gamma distribution with mean alpha and variance 1.0.double
nextGamma(double alpha, double beta)
Return a random double drawn from a Gamma distribution with mean alpha*beta and variance alpha*beta^2.double
nextGamma(double alpha, double beta, double lambda)
Return a random double drawn from a Gamma distribution with mean alpha*beta+lamba and variance alpha*beta^2.double
nextGaussian()
Return a random double drawn from a Gaussian distribution with mean 0 and variance 1.double
nextGaussian(double m, double s2)
Return a random double drawn from a Gaussian distribution with mean m and variance s2.int
nextPoisson()
Return nextPoisson(1).int
nextPoisson(double lambda)
Return random integer from Poission with parameter lambda.double
nextUniform()
Return a random double in the range 0 to 1, inclusive, uniformly sampled from that range.double
nextUniform(double a, double b)
Return a random double in the range a to b, inclusive, uniformly sampled from that range.double
oldNextGamma(int ia)
-
-
-
Method Detail
-
nextPoisson
public int nextPoisson(double lambda)
Return random integer from Poission with parameter lambda. The mean of this distribution is lambda. The variance is lambda.
-
nextPoisson
public int nextPoisson()
Return nextPoisson(1).
-
nextBoolean
public boolean nextBoolean()
Return a random boolean, equally likely to be true or false.- Overrides:
nextBoolean
in classjava.util.Random
-
nextBoolean
public boolean nextBoolean(double p)
Return a random boolean, with probability p of being true.
-
nextBitSet
public java.util.BitSet nextBitSet(int size, double p)
Return a random BitSet with "size" bits, each having probability p of being true.
-
nextUniform
public double nextUniform()
Return a random double in the range 0 to 1, inclusive, uniformly sampled from that range. The mean of this distribution is 0.5. The variance is 1/12.
-
nextUniform
public double nextUniform(double a, double b)
Return a random double in the range a to b, inclusive, uniformly sampled from that range. The mean of this distribution is (b-a)/2. The variance is (b-a)^2/12
-
nextDiscrete
public int nextDiscrete(double[] a)
Draw a single sample from multinomial "a".
-
nextDiscrete
public int nextDiscrete(double[] a, double sum)
draw a single sample from (unnormalized) multinomial "a", with normalizing factor "sum".
-
nextGaussian
public double nextGaussian()
Return a random double drawn from a Gaussian distribution with mean 0 and variance 1.- Overrides:
nextGaussian
in classjava.util.Random
-
nextGaussian
public double nextGaussian(double m, double s2)
Return a random double drawn from a Gaussian distribution with mean m and variance s2.
-
nextGamma
public double nextGamma()
Return a random double drawn from a Gamma distribution with mean 1.0 and variance 1.0.
-
nextGamma
public double nextGamma(double alpha)
Return a random double drawn from a Gamma distribution with mean alpha and variance 1.0.
-
oldNextGamma
public double oldNextGamma(int ia)
-
nextGamma
public double nextGamma(double alpha, double beta)
Return a random double drawn from a Gamma distribution with mean alpha*beta and variance alpha*beta^2.
-
nextGamma
public double nextGamma(double alpha, double beta, double lambda)
Return a random double drawn from a Gamma distribution with mean alpha*beta+lamba and variance alpha*beta^2. Note that this means the pdf is:frac{ x^{alpha-1} exp(-x/beta) }{ beta^alpha Gamma(alpha) }
in other words, beta is a "scale" parameter. An alternative parameterization would use 1/beta, the "rate" parameter.
-
nextExp
public double nextExp()
Return a random double drawn from an Exponential distribution with mean 1 and variance 1.
-
nextExp
public double nextExp(double beta)
Return a random double drawn from an Exponential distribution with mean beta and variance beta^2.
-
nextExp
public double nextExp(double beta, double lambda)
Return a random double drawn from an Exponential distribution with mean beta+lambda and variance beta^2.
-
nextChiSq
public double nextChiSq()
Return a random double drawn from an Chi-squarted distribution with mean 1 and variance 2. Equivalent to nextChiSq(1)
-
nextChiSq
public double nextChiSq(int df)
Return a random double drawn from an Chi-squared distribution with mean df and variance 2*df.
-
nextChiSq
public double nextChiSq(int df, double lambda)
Return a random double drawn from an Chi-squared distribution with mean df+lambda and variance 2*df.
-
nextBeta
public double nextBeta(double alpha, double beta)
Return a random double drawn from a Beta distribution with mean a/(a+b) and variance ab/((a+b+1)(a+b)^2).
-
asJavaRandom
@Deprecated public java.util.Random asJavaRandom()
Deprecated.Wrap this instance as a java random, so it can be passed to legacy methods. All methods of the returned java.util.Random object will affect the state of this object, as well.
-
main
public static void main(java.lang.String[] args)
-
-