Class FastLoadedDiceRollerDiscreteSampler.FLDRSampler

    • Field Detail

      • EMPTY_BOOL_SOURCE

        private static final int EMPTY_BOOL_SOURCE
        Empty boolean source. This is the location of the sign-bit after 31 right shifts on the boolean source.
        See Also:
        Constant Field Values
      • n

        private final int n
        Number of categories.
      • k

        private final int k
        Number of levels in the discrete distribution generating (DDG) tree. Equal to ceil(log2(m)) where m is the sum of observations.
      • h

        private final int[] h
        Number of leaf nodes at each level.
      • lH

        private final int[] lH
        Stores the leaf node labels in increasing order. Named H in the FLDR paper.
      • booleanSource

        private int booleanSource
        Provides a bit source for booleans.

        A cached value from a call to UniformRandomProvider.nextInt().

        Only stores 31-bits when full as 1 bit has already been consumed. The sign bit is a flag that shifts down so the source eventually equals 1 when all bits are consumed and will trigger a refill.

    • Constructor Detail

      • FLDRSampler

        FLDRSampler​(UniformRandomProvider rng,
                    int n,
                    int k,
                    int[] h,
                    int[] lH)
        Creates a sampler.

        The input parameters are not validated and must be correctly computed tables.

        Parameters:
        rng - Generator of uniformly distributed random numbers.
        n - Number of categories
        k - Number of levels in the discrete distribution generating (DDG) tree. Equal to ceil(log2(m)) where m is the sum of observations.
        h - Number of leaf nodes at each level.
        lH - Stores the leaf node labels in increasing order.
    • Method Detail

      • sample

        public int sample()
        Creates an int sample.
        Returns:
        a sample.
      • flip

        private int flip()
        Provides a source of boolean bits.

        Note: This replicates the boolean cache functionality of o.a.c.rng.core.source32.IntProvider. The method has been simplified to return an int value rather than a boolean.

        Returns:
        the bit (0 or 1)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object