[
https://issues.apache.org/jira/browse/RNG-150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17374224#comment-17374224
]
Alex Herbert commented on RNG-150:
----------------------------------
I added a temporary change to the DiscreteSamplersPerformance class in the JMH
package to have a mean for the Poisson sampler. This must be above 40 for the
sampler to use the LargeMeanPoissonSampler. It should be fractional to ensure
the full functionality is used (a Poisson sample with an integer mean is added
to a sample with mean in the range [0, 1)).
Here is a quick output of the speed of the current sampler:
{noformat}
Benchmark (mean) (randomSourceName)
(samplerType) Mode Cnt Score Error Units
DiscreteSamplersPerformance.baseline N/A N/A
N/A avgt 5 2.043 ± 0.013 ns/op
DiscreteSamplersPerformance.sample 40.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 69.775 ± 0.570 ns/op
DiscreteSamplersPerformance.sample 60.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 68.625 ± 0.447 ns/op
DiscreteSamplersPerformance.sample 100.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 66.874 ± 4.334 ns/op
DiscreteSamplersPerformance.sample 180.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 63.866 ± 0.144 ns/op
DiscreteSamplersPerformance.sample 340.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 62.073 ± 0.279 ns/op
{noformat}
And after the change to use the ZigguratExponentialSampler:
{noformat}
Benchmark (mean) (randomSourceName)
(samplerType) Mode Cnt Score Error Units
DiscreteSamplersPerformance.baseline N/A N/A
N/A avgt 5 2.093 ± 0.212 ns/op
DiscreteSamplersPerformance.sample 40.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 53.798 ± 2.234 ns/op
DiscreteSamplersPerformance.sample 60.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 53.035 ± 0.953 ns/op
DiscreteSamplersPerformance.sample 100.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 52.646 ± 0.807 ns/op
DiscreteSamplersPerformance.sample 180.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 48.005 ± 0.493 ns/op
DiscreteSamplersPerformance.sample 340.5 XO_RO_SHI_RO_128_PP
LargeMeanPoissonSampler avgt 5 49.246 ± 0.918 ns/op
{noformat}
So the change has made a 20% speed improvement.
Note that the ZigguratExponentialSampler can return infinity for a sample. This
is not possible for the AhrensDieterExponentialSampler. Looking at the code in
the LargeMeanPoissonSampler the use of the exponential deviate is robust to
infinity. This will be used as if it were a very large finite value. No NaN
generation can occur due to inf - inf or inf * 0. The sampler would be robust
to NaN anyway as any final result as a double is cast to an integer. The sample
method loops until conditions are met. So when extreme cases occur due to the
random deviates then it will repeat. This change should not effect the samplers
functionality.
> Update LargeMeanPoissionSampler to use the ZigguratExponentialSampler
> ---------------------------------------------------------------------
>
> Key: RNG-150
> URL: https://issues.apache.org/jira/browse/RNG-150
> Project: Commons RNG
> Issue Type: Improvement
> Components: sampling
> Affects Versions: 1.3
> Reporter: Alex Herbert
> Priority: Trivial
>
> The LargeMeanPoissionSampler uses a standard exponential deviate. This can be
> changed from the AhrensDieterExponentialSampler to the
> ZigguratExponentialSampler which is 4x faster.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)