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/12 12:51:00 UTC
[jira] [Updated] (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 updated RNG-129:
-----------------------------
Description:
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}
was:
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}
> 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
> Priority: Minor
>
> 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)