Class AliasMethod


  • public final class AliasMethod
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      AliasMethod​(double[] probabilities)
      Constructs a new AliasMethod to sample from a discrete distribution and hand back outcomes based on the probability distribution.
      AliasMethod​(double[] probabilities, java.util.SplittableRandom random)
      Constructs a new AliasMethod to sample from a discrete distribution and hand back outcomes based on the probability distribution.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getProbabilitiesSize()  
      int next()
      Samples a value from the underlying distribution.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AliasMethod

        public AliasMethod​(double[] probabilities)
        Constructs a new AliasMethod to sample from a discrete distribution and hand back outcomes based on the probability distribution.

        Given as input a list of probabilities corresponding to outcomes 0, 1, ..., n - 1, this constructor creates the probability and alias tables needed to efficiently sample from this distribution.

        Parameters:
        probabilities - The list of probabilities.
      • AliasMethod

        public AliasMethod​(double[] probabilities,
                           java.util.SplittableRandom random)
        Constructs a new AliasMethod to sample from a discrete distribution and hand back outcomes based on the probability distribution.

        Given as input a list of probabilities corresponding to outcomes 0, 1, ..., n - 1, along with the random number generator that should be used as the underlying generator, this constructor creates the probability and alias tables needed to efficiently sample from this distribution.

        Parameters:
        probabilities - The list of probabilities.
        random2 - The random number generator
    • Method Detail

      • next

        public int next()
        Samples a value from the underlying distribution. NOT THREAD SAFE
        Returns:
        A random value sampled from the underlying distribution.
      • getProbabilitiesSize

        public int getProbabilitiesSize()