Class MarsagliaTsangWangDiscreteSampler.Enumerated

  • Enclosing class:
    MarsagliaTsangWangDiscreteSampler

    public static final class MarsagliaTsangWangDiscreteSampler.Enumerated
    extends java.lang.Object
    Create a sampler for an enumerated distribution of n values each with an associated probability. The samples corresponding to each probability are assumed to be a natural sequence starting at zero.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String ENUMERATED_NAME
      The name of the enumerated probability distribution.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Enumerated()
      Class contains only static methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static int[] normaliseProbabilities​(double[] probabilities)
      Normalise the probabilities to integers that sum to 230.
      static SharedStateDiscreteSampler of​(UniformRandomProvider rng, double[] probabilities)
      Creates a sampler for an enumerated distribution of n values each with an associated probability.
      • Methods inherited from class java.lang.Object

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

      • ENUMERATED_NAME

        private static final java.lang.String ENUMERATED_NAME
        The name of the enumerated probability distribution.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Enumerated

        private Enumerated()
        Class contains only static methods.
    • Method Detail

      • of

        public static SharedStateDiscreteSampler of​(UniformRandomProvider rng,
                                                    double[] probabilities)
        Creates a sampler for an enumerated distribution of n values each with an associated probability.

        The probabilities will be normalised using their sum. The only requirement is the sum is positive.

        The sum of the probabilities is normalised to 230. Note that probabilities are adjusted to the nearest 2-30 due to round-off during the normalisation conversion. Consequently any probability less than 2-31 will not be observed in samples.

        Parameters:
        rng - Generator of uniformly distributed random numbers.
        probabilities - The list of probabilities.
        Returns:
        Sampler.
        Throws:
        java.lang.IllegalArgumentException - if probabilities is null or empty, a probability is negative, infinite or NaN, or the sum of all probabilities is not strictly positive.
      • normaliseProbabilities

        private static int[] normaliseProbabilities​(double[] probabilities)
        Normalise the probabilities to integers that sum to 230.
        Parameters:
        probabilities - The list of probabilities.
        Returns:
        the normalised probabilities.
        Throws:
        java.lang.IllegalArgumentException - if probabilities is null or empty, a probability is negative, infinite or NaN, or the sum of all probabilities is not strictly positive.