- java.lang.Object
-
- org.jgrapht.alg.util.AliasMethodSampler
-
public class AliasMethodSampler extends Object
The alias method for sampling from a discrete probability distribution.The implementation is described in the paper: Michael D. Vose. A Linear Algorithm for Generating Random Numbers with a Given Distribution. IEEE Transactions on Software Engineering, 17(9):972--975, 1991.
Initialization takes $O(n)$ where $n$ is the number of items. Sampling takes $O(1)$.
- Author:
- Dimitrios Michail
-
-
Constructor Summary
Constructors Constructor Description AliasMethodSampler(double[] p)ConstructorAliasMethodSampler(double[] p, long seed)ConstructorAliasMethodSampler(double[] p, Random rng)ConstructorAliasMethodSampler(double[] p, Random rng, double epsilon)Constructor
-
-
-
Constructor Detail
-
AliasMethodSampler
public AliasMethodSampler(double[] p)
Constructor- Parameters:
p- the probability distribution where position i of the array is $Prob(X=i)$- Throws:
IllegalArgumentException- if an invalid probability distribution is supplied
-
AliasMethodSampler
public AliasMethodSampler(double[] p, long seed)Constructor- Parameters:
p- the probability distribution where position $i$ of the array is $Prob(X=i)$seed- seed to use for the random number generator- Throws:
IllegalArgumentException- if an invalid probability distribution is suppliedNullPointerException- ifrngisnull
-
AliasMethodSampler
public AliasMethodSampler(double[] p, Random rng)Constructor- Parameters:
p- the probability distribution where position $i$ of the array is $Prob(X=i)$rng- the random number generator- Throws:
IllegalArgumentException- if an invalid probability distribution is suppliedNullPointerException- ifrngisnull
-
AliasMethodSampler
public AliasMethodSampler(double[] p, Random rng, double epsilon)Constructor- Parameters:
p- the probability distribution where position $i$ of the array is $Prob(X=i)$rng- the random number generatorepsilon- tolerance used when comparing floating-point values- Throws:
IllegalArgumentException- if an invalid probability distribution is suppliedNullPointerException- ifrngisnull
-
-