You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2021/04/15 22:03:00 UTC
[jira] [Resolved] (RNG-129) Performance improvement for
UnitSphereSampler
[ https://issues.apache.org/jira/browse/RNG-129?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Alex Herbert resolved RNG-129.
------------------------------
Fix Version/s: 1.4
Assignee: Alex Herbert
Resolution: Implemented
In git master.
Commit: 5692fe119d9f5866e4448a47472ba20a4ea7a813
> Performance improvement for UnitSphereSampler
> ---------------------------------------------
>
> Key: RNG-129
> URL: https://issues.apache.org/jira/browse/RNG-129
> Project: Commons RNG
> Issue Type: Improvement
> Components: sampling
> Affects Versions: 1.3
> Reporter: Alex Herbert
> Assignee: Alex Herbert
> Priority: Minor
> Fix For: 1.4
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> The UnitSphereSampler accepts a dimension argument and creates the sample using iteration over an array of the given dimension creating n Gaussian samples. This can be optimised for low order dimensions to remove the use of array iteration, e.g.
> {code:java}
> final double[] v = new double[dimension];
> double sum = 0;
> for (int i = 0; i < dimension; i++) {
> final double x = sampler.sample();
> v[i] = x;
> sum += x * x;
> }
> {code}
> becomes for 3D:
> {code:java}
> final double x = sampler.sample();
> final double y = sampler.sample();
> final double z = sampler.sample();
> final double sum = x * x + y * y + z * z;
> {code}
> The special case of 1D sampling can be handled by returning either 1 or -1 in a vector based on a single bit of the random source.
> Optimised versions can be created by adding a factory method to the class:
> {code:java}
> public static UnitSphereSampler of(int dimension, UniformRandomProvider rng) {
> // ...
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)