Class SmallMeanPoissonSampler

    • Field Detail

      • p0

        private final double p0
        Pre-compute Math.exp(-mean). Note: This is the probability of the Poisson sample P(n=0).
      • limit

        private final int limit
        Pre-compute 1000 * mean as the upper limit of the sample.
    • Constructor Detail

      • SmallMeanPoissonSampler

        public SmallMeanPoissonSampler​(UniformRandomProvider rng,
                                       double mean)
        Create an instance.
        Parameters:
        rng - Generator of uniformly distributed random numbers.
        mean - Mean.
        Throws:
        java.lang.IllegalArgumentException - if mean <= 0 or Math.exp(-mean) == 0
      • SmallMeanPoissonSampler

        private SmallMeanPoissonSampler​(UniformRandomProvider rng,
                                        double mean,
                                        double p0)
        Instantiates a new small mean poisson sampler.
        Parameters:
        rng - Generator of uniformly distributed random numbers.
        mean - Mean.
        p0 - Math.exp(-mean).
    • Method Detail

      • sample

        public int sample()
        Creates an int sample.
        Specified by:
        sample in interface DiscreteSampler
        Returns:
        a sample.
      • toString

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

        public static SharedStateDiscreteSampler of​(UniformRandomProvider rng,
                                                    double mean)
        Creates a new sampler for the Poisson distribution.
        Parameters:
        rng - Generator of uniformly distributed random numbers.
        mean - Mean of the distribution.
        Returns:
        the sampler
        Throws:
        java.lang.IllegalArgumentException - if mean <= 0 or Math.exp(-mean) == 0.
        Since:
        1.3
      • computeP0

        private static double computeP0​(double mean)
        Compute Math.exp(-mean).

        This method exists to raise an exception before invocation of the private constructor; this mitigates Finalizer attacks (see SpotBugs CT_CONSTRUCTOR_THROW).

        Parameters:
        mean - Mean.
        Returns:
        the mean
        Throws:
        java.lang.IllegalArgumentException - if mean <= 0 or Math.exp(-mean) == 0