commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex D Herbert (JIRA)" <>
Subject [jira] [Created] (RNG-51) PoissonSampler single use speed improvements using a cache
Date Tue, 07 Aug 2018 19:52:00 GMT
Alex D Herbert created RNG-51:

             Summary: PoissonSampler single use speed improvements using a cache
                 Key: RNG-51
             Project: Commons RNG
          Issue Type: Improvement
    Affects Versions: 1.1
            Reporter: Alex D Herbert

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

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. 

This message was sent by Atlassian JIRA

View raw message