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

Alex Herbert commented on RNG-128:
----------------------------------

Note: Correction of the BallPoint method

The BallPoint method and the HypersphereDiscard method are very similar in that 
they normalise n samples from a standard normal distribution. Both sum the n 
samples squared. The BallPoint method adds an exponential sample to the sum. 
The HypersphereDiscard method adds two more standard normal samples squared. 
The sum is then square rooted and used to project the point described by the n 
samples inside the unit n-ball.

The two standard normal samples squared used in the HypersphereDiscard method 
are a sample from a Chi-squared distribution with 2 degrees of freedom. This is 
equivalent to a sample from an exponential distribution with rate 1/2 (mean 2):

[Gamma, exponential, and related 
distributions|https://en.wikipedia.org/wiki/Chi-square_distribution#Gamma,_exponential,_and_related_distributions]

If the BallPoint method is updated to use an exponential with a mean of 2 in 
place of 1 (as described on the Wolfram page) then the sampler passes the tests 
for uniformity. This has no effect on the current performance results. If an 
exponential sampler can be faster than 2 samples from a standard normal 
distribution then the BallPoint method may outperform the HypersphereDiscard 
method.


> UnitBallSampler
> ---------------
>
>                 Key: RNG-128
>                 URL: https://issues.apache.org/jira/browse/RNG-128
>             Project: Commons RNG
>          Issue Type: Improvement
>          Components: sampling
>            Reporter: Alex Herbert
>            Priority: Minor
>
> The *UnitSphereSampler* can generate isotropically distributed coordinates 
> *on the surface* of a hypersphere of a given dimension.
> I propose to create a *UnitBallSampler* to generate isotropically distributed 
> coordinates *within* a hypersphere of a given dimension.
> Wolfram describes a method that will work with any dimension and a method for 
> 2 dimensions:
> [Ball Point Picking|https://mathworld.wolfram.com/BallPointPicking.html]
>  [Disk Point Picking|https://mathworld.wolfram.com/DiskPointPicking.html]
> It also suggests that a simple rejection method when sampling inside an 
> n-cube of length 2 may be faster for small dimensions.
> Creating an abstract class with a factory method would allow the best 
> performing sampler to be created for each dimension:
> {code:java}
> public abstract class UnitBallSampler implements
>         SharedStateSampler<UnitBallSampler> {
>     /**
>      * @return a random Cartesian coordinate within the unit n-ball.
>      */
>     public double[] next() {
>         // ...
>     }
>     /**
>      * Create a unit n-ball sampler for the given dimension.
>      *
>      * @param dimension Space dimension.
>      * @param rng Generator for the individual components of the coordinates. 
>      * A shallow copy will be stored in this instance.
>      * @throws IllegalArgumentException If {@code dimension <= 0}
>      */
>     public static UnitBallSampler of(int dimension,
>                                      UniformRandomProvider rng) {
>         // ...
>     }
> }
> {code}
> The UnitSphereSampler sample method is named {{nextVector}}. The 
> corresponding method here could be:
>  * next
>  * nextVector
>  * nextCoordinate
>  * nextPoint
>  * sample
>  * ...



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

Reply via email to