[
https://issues.apache.org/jira/browse/RNG-51?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16616752#comment-16616752
]
Alex D Herbert commented on RNG-51:
-----------------------------------
{quote}Have you reached a conclusion?{quote}
I think the cache would be worthwhile at least for my use case where many
Poisson samples will be made with a unique mean.
I put this on hold when 1.1 was being released. I was waiting for a 1.2 branch
to appear or for master to have 1.2 as the version in the POM.
I can put what I have in a PR against the current master. There is a change to
the {{LargeMeanPoissonSampler}} that adds a lot of extra code for a second
constructor. This totally encapsulates the creation of the internal state to
that class. The Poisson cache is just responsible for storing state to be
reused.
It does require changing the visibility of the {{PIVOT}} variable from
{{PoissonSampler}} from private to package scope so that the cache operates in
the same way as using {{new PoissonSampler(...)}}.
The new methods in the LargeMeanPoissonSampler could be package scope to
prevent confusion of the public API.
I can put the speed test into the JMH module.
I'll try and do this this week.
> PoissonSampler single use speed improvements using a cache
> ----------------------------------------------------------
>
> Key: RNG-51
> URL: https://issues.apache.org/jira/browse/RNG-51
> Project: Commons RNG
> Issue Type: Improvement
> Affects Versions: 1.1
> Reporter: Alex D Herbert
> Priority: Minor
> Labels: performance
>
> 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|https://github.com/aherbert/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
(v7.6.3#76005)