Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-51

PoissonSampler single use speed improvements using a cache

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • 1.1
    • 1.2
    • sampling

    Description

      This improvement is a follow on fromĀ RNG-50.

      That improved the PoissonSampler by splitting it into two samplers for the different algorithms (SmallMeanPoissonSampler and LargeMeanPoissonSampler) and moving initialisation computations from the sample method into the constructor. This improved the speed of repeat use of the same sampler by up to 3-fold. It does not effect single-use of a sampler.

      In the case of the LargeMeanPoissonSampler the initialisation 'state' computed within the constructor involves 2 Math.log, 2 Math.exp, 2 Math.sqrt and 1 logFactorial computations. If the sampler is used to generate only 1 sample then the cost of computing the state is a significant portion of the sample time.

      However the state is not unique to the mean of the Poisson distribution but the (int)Math.floor(mean). This means the initialisation state can be shared and reused by PoissonSamplers with different means.

      This was demonstrated using a JMH benchmark speed test comparing the standard PoissonSampler verses a PoissonSamplerCache that can store the initialisation state of the PoissonSampler.

      For single-use Poisson samples with a mean within a known range the cache can provide 1.3 to 2x speed-up as initialisation state can be reused.

      The original benchmark was performed using Version 1.0. The Version 1.1. samplers use a new faster Gaussian sampler internally. So the benchmark should be repeated for Version 1.1.

      The test project containing the V1.0 JMH benchmark is here: poisson-sampler-test-code

      I propose to update this project to reference V1.1 of Commons RNG and repeat the test of the PoissonSamplerCache. Results will be posted when available.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: