Class FastLoadedDiceRollerDiscreteSampler.FLDRSampler

java.lang.Object
org.apache.commons.rng.sampling.distribution.FastLoadedDiceRollerDiscreteSampler
org.apache.commons.rng.sampling.distribution.FastLoadedDiceRollerDiscreteSampler.FLDRSampler
All Implemented Interfaces:
DiscreteSampler, SharedStateDiscreteSampler, SharedStateSampler<SharedStateDiscreteSampler>
Enclosing class:
FastLoadedDiceRollerDiscreteSampler

private static class FastLoadedDiceRollerDiscreteSampler.FLDRSampler extends FastLoadedDiceRollerDiscreteSampler
Class to implement the FLDR sample algorithm.
  • Field Details

    • 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:
    • rng

      private final UniformRandomProvider rng
      Underlying source of randomness.
    • 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 Details

    • 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.
    • FLDRSampler

      Creates a copy with a new source of randomness.
      Parameters:
      rng - Generator of uniformly distributed random numbers.
      source - Source to copy.
  • Method Details