[ 
https://issues.apache.org/jira/browse/RNG-151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17376477#comment-17376477
 ] 

Alex Herbert commented on RNG-151:
----------------------------------

The paper by McFarland tests the distribution against the expected raw moments 
of the distributions. These are the sum of the sample values x raised to the 
power n, for the moment n.

The expected values of the first 6 raw moments are:
{noformat}
Exponential: 1, 2, 6, 24, 120, 720
Gaussian:    0, 1, 0, 3, 0, 15
{noformat}
The deviation from the expected moment should scale as {{1 / sqrt( n)}} with n 
the sample size.

Here are the outputs from 10^12 samples from the sampler. The deviations should 
have a relative error of 1e-6, or be different in the 6th significant digit. I 
include the previous ziggurat Gaussian sampler for reference.
{noformat}
ZigguratSampler.Exponential:
[0.999999668886954, 2.000006905574401, 6.000094811047854, 24.000943325259296, 
120.00841041424482, 720.0700790141025]

ZigguratSampler.NormalizedGaussian:
[-6.424931423385509E-7, 1.0000420203209586, 1.259765810387924E-7, 
2.999996240981223, 6.128453466790293E-6, 14.999936194739298]

ZigguratNormalizedGaussianSampler:
[-6.173652262113744E-7, 1.0000022279098377, -1.0104943849472868E-6, 
3.0000125601043686, 1.237634887159727E-5, 15.000049224072676]
{noformat}

So the samplers compute moments as expected.

> Modified Ziggurat algorithm for normal and exponential sampling
> ---------------------------------------------------------------
>
>                 Key: RNG-151
>                 URL: https://issues.apache.org/jira/browse/RNG-151
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: sampling
>    Affects Versions: 1.3
>            Reporter: Alex Herbert
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The following paper describes a modification of the ziggurat method for 
> sampling normal and exponential deviates:
> {noformat}
> McFarland, C.D. (2016)
> "A modified ziggurat algorithm for generating exponentially and normally 
> distributed pseudorandom numbers".
> Journal of Statistical Computation and Simulation 86, 1281-1294.
> {noformat}
> [McFarland (2016) JSCS 86, 
> 1281-294|https://www.tandfonline.com/doi/abs/10.1080/00949655.2015.1060234]
> Note: This method is the one that has been chosen as the default 
> implementation for the java.util.random.RandomGenerator nextGaussian and 
> nextExponential methods to be added in JDK 17.
> The method should be investigated in comparison to the current ziggurat 
> method of Marsaglia used in ZigguratNormalizedGaussianSampler and 
> ZigguratExponentialSampler.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to