Class InternalUtils


  • final class InternalUtils
    extends java.lang.Object
    Functions used by some of the samplers. This class is not part of the public API, as it would be better to group these utilities in a dedicated component.
    • Field Detail

      • FACTORIALS

        private static final long[] FACTORIALS
        All long-representable factorials.
      • BEGIN_LOG_FACTORIALS

        private static final int BEGIN_LOG_FACTORIALS
        The first array index with a non-zero log factorial.
        See Also:
        Constant Field Values
      • DOUBLE_MULTIPLIER

        private static final double DOUBLE_MULTIPLIER
        The multiplier to convert the least significant 53-bits of a long to a double. Taken from org.apache.commons.rng.core.util.NumberFactory.
        See Also:
        Constant Field Values
    • Constructor Detail

      • InternalUtils

        private InternalUtils()
        Utility class.
    • Method Detail

      • factorial

        static long factorial​(int n)
        Parameters:
        n - Argument.
        Returns:
        n!
        Throws:
        java.lang.IndexOutOfBoundsException - if the result is too large to be represented by a long (i.e. if n > 20), or n is negative.
      • validateProbabilities

        static double validateProbabilities​(double[] probabilities)
        Validate the probabilities sum to a finite positive number.
        Parameters:
        probabilities - the probabilities
        Returns:
        the sum
        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.
      • validateProbability

        static void validateProbability​(double probability)
        Validate the probability is a finite positive number.
        Parameters:
        probability - Probability.
        Throws:
        java.lang.IllegalArgumentException - if probability is negative, infinite or NaN.
      • makeNonZeroDouble

        static double makeNonZeroDouble​(long v)
        Creates a double in the interval (0, 1] from a long value.
        Parameters:
        v - Number.
        Returns:
        a double value in the interval (0, 1].