You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2017/02/09 00:22:10 UTC

[01/14] commons-rng git commit: RNG-35: Marker interface for N(0, 1) Gaussian sampler.

Repository: commons-rng
Updated Branches:
  refs/heads/master b2dd661df -> 688f36111


RNG-35: Marker interface for N(0,1) Gaussian sampler.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/72bf01f5
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/72bf01f5
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/72bf01f5

Branch: refs/heads/master
Commit: 72bf01f5fe930717884914220fc57cecb05fb435
Parents: b2dd661
Author: Gilles <er...@apache.org>
Authored: Tue Jan 24 00:06:21 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Tue Jan 24 00:06:21 2017 +0100

----------------------------------------------------------------------
 .../distribution/NormalizedGaussianSampler.java | 24 ++++++++++++++++++++
 1 file changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/72bf01f5/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/NormalizedGaussianSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/NormalizedGaussianSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/NormalizedGaussianSampler.java
new file mode 100644
index 0000000..014f275
--- /dev/null
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/NormalizedGaussianSampler.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.sampling.distribution;
+
+/**
+ * Marker interface for a sampler that generates values from an N(0,1)
+ * <a href="https://en.wikipedia.org/wiki/Normal_distribution">
+ *  Gaussian distribution</a>.
+ */
+public interface NormalizedGaussianSampler extends ContinuousSampler {}


[07/14] commons-rng git commit: RNG-36: Variation of the Box-Muller algorithm for Gaussian sampling.

Posted by er...@apache.org.
RNG-36: Variation of the Box-Muller algorithm for Gaussian sampling.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/c14e09ca
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/c14e09ca
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/c14e09ca

Branch: refs/heads/master
Commit: c14e09caa4161dc7cdbaa9fae3dbbd3cf02b70e3
Parents: 94f0843
Author: Gilles <er...@apache.org>
Authored: Thu Jan 26 23:54:52 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Thu Jan 26 23:54:52 2017 +0100

----------------------------------------------------------------------
 ...rWithRejectionNormalizedGaussianSampler.java | 88 ++++++++++++++++++++
 .../distribution/ContinuousSamplersList.java    |  4 +
 2 files changed, 92 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/c14e09ca/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java
new file mode 100644
index 0000000..58d1b1f
--- /dev/null
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.sampling.distribution;
+
+import org.apache.commons.rng.UniformRandomProvider;
+
+/**
+ * <a href="https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform">
+ * Box-Muller algorithm</a> for sampling from Gaussian distribution with
+ * mean 0 and standard deviation 1.
+ * This is a variation, suggested in <a href="http://haifux.org/lectures/79/random.pdf">
+ * this presentation</a> (page 39), of the algorithm implemented in
+ * {@link BoxMullerNormalizedGaussianSampler}, 
+ *
+ * @since 1.1
+ */
+public class BoxMullerWithRejectionNormalizedGaussianSampler
+    extends SamplerBase
+    implements NormalizedGaussianSampler {
+    /** Next gaussian. */
+    private double nextGaussian = Double.NaN;
+
+    /**
+     * @param rng Generator of uniformly distributed random numbers.
+     */
+    public BoxMullerWithRejectionNormalizedGaussianSampler(UniformRandomProvider rng) {
+        super(rng);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double sample() {
+        final double random;
+        if (Double.isNaN(nextGaussian)) {
+            // Rejection scheme for selecting a pair that lies within the unit circle.
+            SAMPLE: while (true) {
+                // Generate a pair of numbers within [-1 , 1).
+                final double x = 2 * nextDouble() - 1;
+                final double y = 2 * nextDouble() - 1;
+                final double r2 = x * x + y * y;
+
+                if (r2 < 1) {
+                    // Pair (x, y) is within unit circle.
+
+                    final double r = Math.sqrt(r2);
+                    final double alpha = 2 * Math.sqrt(-Math.log(r)) / r;
+
+                    // Return the first element of the generated pair.
+                    random = alpha * x;
+
+                    // Keep second element of the pair for next invocation.
+                    nextGaussian = alpha * y;
+                    break SAMPLE;
+                }
+                // Pair is not within the unit circle: Generate another one.
+            }
+        } else {
+            // Use the second element of the pair (generated at the
+            // previous invocation).
+            random = nextGaussian;
+
+            // Both elements of the pair have been used.
+            nextGaussian = Double.NaN;
+        }
+
+        return random;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "Box-Muller (with rejection) normalized Gaussian deviate [" + super.toString() + "]";
+    }
+}

http://git-wip-us.apache.org/repos/asf/commons-rng/blob/c14e09ca/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java
index c24e786..aa0e458 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java
@@ -48,6 +48,10 @@ public class ContinuousSamplersList {
             add(LIST, new org.apache.commons.math3.distribution.NormalDistribution(meanNormal, sigmaNormal),
                 new GaussianSampler(new BoxMullerNormalizedGaussianSampler(RandomSource.create(RandomSource.MT)),
                                     meanNormal, sigmaNormal));
+            // Gaussian ("Box-Muller" with rejection).
+            add(LIST, new org.apache.commons.math3.distribution.NormalDistribution(meanNormal, sigmaNormal),
+                new GaussianSampler(new BoxMullerWithRejectionNormalizedGaussianSampler(RandomSource.create(RandomSource.MT)),
+                                    meanNormal, sigmaNormal));
 
             // Beta ("inverse method").
             final double alphaBeta = 4.3;


[12/14] commons-rng git commit: Add "package-info.java" (CheckStyle).

Posted by er...@apache.org.
Add "package-info.java" (CheckStyle).


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/23fdd63d
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/23fdd63d
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/23fdd63d

Branch: refs/heads/master
Commit: 23fdd63dbc057af14f8cb9a2b8d40648ce4ef671
Parents: 31dba79
Author: Gilles <er...@apache.org>
Authored: Wed Feb 8 14:31:21 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Wed Feb 8 14:31:21 2017 +0100

----------------------------------------------------------------------
 .../rng/jmh/distribution/package-info.java      | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/23fdd63d/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/package-info.java
----------------------------------------------------------------------
diff --git a/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/package-info.java b/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/package-info.java
new file mode 100644
index 0000000..ab7f0f6
--- /dev/null
+++ b/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Benchmarks for samplers.
+ */
+
+package org.apache.commons.rng.jmh.distribution;


[06/14] commons-rng git commit: RNG-35: Use "BoxMullerNormalizedGaussianSampler" as building block for other samplers.

Posted by er...@apache.org.
RNG-35: Use "BoxMullerNormalizedGaussianSampler" as building block for other samplers.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/94f08432
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/94f08432
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/94f08432

Branch: refs/heads/master
Commit: 94f084324a99f4f84464ad3b5574a84adc1028e9
Parents: 3b4b798
Author: Gilles <er...@apache.org>
Authored: Tue Jan 24 00:20:07 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Tue Jan 24 00:20:07 2017 +0100

----------------------------------------------------------------------
 .../distribution/AhrensDieterMarsagliaTsangGammaSampler.java     | 4 ++--
 .../rng/sampling/distribution/BoxMullerLogNormalSampler.java     | 4 ++--
 .../apache/commons/rng/sampling/distribution/PoissonSampler.java | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/94f08432/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
index ef5243a..180b531 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
@@ -47,7 +47,7 @@ public class AhrensDieterMarsagliaTsangGammaSampler
     /** The alpha parameter. */
     private final double alpha;
     /** Gaussian sampling. */
-    private final BoxMullerGaussianSampler gaussian;
+    private final NormalizedGaussianSampler gaussian;
 
     /**
      * @param rng Generator of uniformly distributed random numbers.
@@ -60,7 +60,7 @@ public class AhrensDieterMarsagliaTsangGammaSampler
         super(rng);
         this.alpha = alpha;
         this.theta = theta;
-        gaussian = new BoxMullerGaussianSampler(rng, 0, 1);
+        gaussian = new BoxMullerNormalizedGaussianSampler(rng);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/commons-rng/blob/94f08432/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java
index f43a9e5..354b8d4 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java
@@ -30,7 +30,7 @@ public class BoxMullerLogNormalSampler
     /** Shape. */
     private final double shape;
     /** Gaussian sampling. */
-    private final BoxMullerGaussianSampler gaussian;
+    private final NormalizedGaussianSampler gaussian;
 
     /**
      * @param rng Generator of uniformly distributed random numbers.
@@ -43,7 +43,7 @@ public class BoxMullerLogNormalSampler
         super(null); // Not used.
         this.scale = scale;
         this.shape = shape;
-        gaussian = new BoxMullerGaussianSampler(rng, 0, 1);
+        gaussian = new BoxMullerNormalizedGaussianSampler(rng);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/commons-rng/blob/94f08432/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java
index f189a92..d872be9 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java
@@ -46,7 +46,7 @@ public class PoissonSampler
     /** Exponential. */
     private final ContinuousSampler exponential;
     /** Gaussian. */
-    private final ContinuousSampler gaussian;
+    private final NormalizedGaussianSampler gaussian;
     /** {@code log(n!)}. */
     private final InternalUtils.FactorialLog factorialLog;
 
@@ -64,7 +64,7 @@ public class PoissonSampler
 
         this.mean = mean;
 
-        gaussian = new BoxMullerGaussianSampler(rng, 0, 1);
+        gaussian = new BoxMullerNormalizedGaussianSampler(rng);
         exponential = new AhrensDieterExponentialSampler(rng, 1);
         factorialLog = mean < PIVOT ?
             null : // Not used.


[04/14] commons-rng git commit: RNG-35: Deprecate Box-Muller implementation for N(mu, sigma) sampling.

Posted by er...@apache.org.
RNG-35: Deprecate Box-Muller implementation for N(mu,sigma) sampling.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/82476dfc
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/82476dfc
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/82476dfc

Branch: refs/heads/master
Commit: 82476dfcdf97ea7181b4d1939e9f559443801d2b
Parents: 8b4a5ec
Author: Gilles <er...@apache.org>
Authored: Tue Jan 24 00:13:13 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Tue Jan 24 00:13:13 2017 +0100

----------------------------------------------------------------------
 .../rng/sampling/distribution/BoxMullerGaussianSampler.java      | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/82476dfc/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerGaussianSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerGaussianSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerGaussianSampler.java
index a2b4f00..489cda3 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerGaussianSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerGaussianSampler.java
@@ -21,7 +21,11 @@ import org.apache.commons.rng.UniformRandomProvider;
 /**
  * <a href="https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform">
  * Box-Muller algorithm</a> for sampling from a Gaussian distribution.
+ *
+ * @deprecated since v1.1. Please use {@link BoxMullerNormalizedGaussianSampler}
+ * and {@link GaussianSampler} instead.
  */
+@Deprecated
 public class BoxMullerGaussianSampler
     extends SamplerBase
     implements ContinuousSampler {


[05/14] commons-rng git commit: RNG-35: Unit testing of "BoxMullerNormalizedGaussianSampler".

Posted by er...@apache.org.
RNG-35: Unit testing of "BoxMullerNormalizedGaussianSampler".


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/3b4b798f
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/3b4b798f
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/3b4b798f

Branch: refs/heads/master
Commit: 3b4b798f7e344774f3f3c4f4abbf8fb2242fd9e8
Parents: 82476df
Author: Gilles <er...@apache.org>
Authored: Tue Jan 24 00:17:43 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Tue Jan 24 00:17:43 2017 +0100

----------------------------------------------------------------------
 .../rng/sampling/distribution/ContinuousSamplersList.java      | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/3b4b798f/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java
index 0cdf0b6..c24e786 100644
--- a/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java
+++ b/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/ContinuousSamplersList.java
@@ -41,9 +41,13 @@ public class ContinuousSamplersList {
             final double sigmaNormal = 6.789;
             add(LIST, new org.apache.commons.math3.distribution.NormalDistribution(meanNormal, sigmaNormal),
                 RandomSource.create(RandomSource.KISS));
-            // Gaussian ("Box-Muller").
+            // Gaussian (DEPRECATED "Box-Muller").
             add(LIST, new org.apache.commons.math3.distribution.NormalDistribution(meanNormal, sigmaNormal),
                 new BoxMullerGaussianSampler(RandomSource.create(RandomSource.MT), meanNormal, sigmaNormal));
+            // Gaussian ("Box-Muller").
+            add(LIST, new org.apache.commons.math3.distribution.NormalDistribution(meanNormal, sigmaNormal),
+                new GaussianSampler(new BoxMullerNormalizedGaussianSampler(RandomSource.create(RandomSource.MT)),
+                                    meanNormal, sigmaNormal));
 
             // Beta ("inverse method").
             final double alphaBeta = 4.3;


[02/14] commons-rng git commit: RNG-35: General N(mu, sigma) sampler based on N(0, 1) sampler interface.

Posted by er...@apache.org.
RNG-35: General N(mu,sigma) sampler based on N(0,1) sampler interface.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/cf65f676
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/cf65f676
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/cf65f676

Branch: refs/heads/master
Commit: cf65f676ccafdf5265e0069eb1eccf1c2a973cfc
Parents: 72bf01f
Author: Gilles <er...@apache.org>
Authored: Tue Jan 24 00:08:34 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Tue Jan 24 00:08:34 2017 +0100

----------------------------------------------------------------------
 .../sampling/distribution/GaussianSampler.java  | 59 ++++++++++++++++++++
 1 file changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/cf65f676/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java
new file mode 100644
index 0000000..3fda5c5
--- /dev/null
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.sampling.distribution;
+
+import org.apache.commons.rng.UniformRandomProvider;
+
+/**
+ * Sampling from a Gaussian distribution with given mean and
+ * standard deviation.
+ *
+ * @since 1.1
+ */
+public class GaussianSampler implements ContinuousSampler {
+    /** Mean. */
+    private final double mean;
+    /** standardDeviation. */
+    private final double standardDeviation;
+    /** Normalized Gaussian sampler. */
+    private final NormalizedGaussianSampler normalized;
+
+    /**
+     * @param normalized Generator of N(0,1) Gaussian distributed random numbers.
+     * @param mean Mean of the Gaussian distribution.
+     * @param standardDeviation Standard deviation of the Gaussian distribution.
+     */
+    public GaussianSampler(NormalizedGaussianSampler normalized,
+                           double mean,
+                           double standardDeviation) {
+        this.normalized = normalized;
+        this.mean = mean;
+        this.standardDeviation = standardDeviation;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double sample() {
+        return standardDeviation * normalized.sample() + mean;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "Gaussian deviate [" + normalized.toString() + "]";
+    }
+}


[03/14] commons-rng git commit: RNG-35: Box-Muller algorithm for N(0, 1) sampling.

Posted by er...@apache.org.
RNG-35: Box-Muller algorithm for N(0,1) sampling.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/8b4a5ec2
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/8b4a5ec2
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/8b4a5ec2

Branch: refs/heads/master
Commit: 8b4a5ec2c9e88846c34fd73567c093c702be1500
Parents: cf65f67
Author: Gilles <er...@apache.org>
Authored: Tue Jan 24 00:11:47 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Tue Jan 24 00:11:47 2017 +0100

----------------------------------------------------------------------
 .../BoxMullerNormalizedGaussianSampler.java     | 75 ++++++++++++++++++++
 1 file changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/8b4a5ec2/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerNormalizedGaussianSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerNormalizedGaussianSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerNormalizedGaussianSampler.java
new file mode 100644
index 0000000..43882fb
--- /dev/null
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerNormalizedGaussianSampler.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.sampling.distribution;
+
+import org.apache.commons.rng.UniformRandomProvider;
+
+/**
+ * <a href="https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform">
+ * Box-Muller algorithm</a> for sampling from Gaussian distribution with
+ * mean 0 and standard deviation 1.
+ *
+ * @since 1.1
+ */
+public class BoxMullerNormalizedGaussianSampler
+    extends SamplerBase
+    implements NormalizedGaussianSampler {
+    /** Next gaussian. */
+    private double nextGaussian = Double.NaN;
+
+    /**
+     * @param rng Generator of uniformly distributed random numbers.
+     */
+    public BoxMullerNormalizedGaussianSampler(UniformRandomProvider rng) {
+        super(rng);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public double sample() {
+        final double random;
+        if (Double.isNaN(nextGaussian)) {
+            // Generate a pair of Gaussian numbers.
+
+            final double x = nextDouble();
+            final double y = nextDouble();
+            final double alpha = 2 * Math.PI * x;
+            final double r = Math.sqrt(-2 * Math.log(y));
+
+            // Return the first element of the generated pair.
+            random = r * Math.cos(alpha);
+
+            // Keep second element of the pair for next invocation.
+            nextGaussian = r * Math.sin(alpha);
+        } else {
+            // Use the second element of the pair (generated at the
+            // previous invocation).
+            random = nextGaussian;
+
+            // Both elements of the pair have been used.
+            nextGaussian = Double.NaN;
+        }
+
+        return random;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String toString() {
+        return "Box-Muller normalized Gaussian deviate [" + super.toString() + "]";
+    }
+}


[13/14] commons-rng git commit: Add benchmarks.

Posted by er...@apache.org.
Add benchmarks.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/cd7ebb45
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/cd7ebb45
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/cd7ebb45

Branch: refs/heads/master
Commit: cd7ebb455accdbc2ce7437d90d252c9c20ddfc1e
Parents: 23fdd63
Author: Gilles <er...@apache.org>
Authored: Wed Feb 8 14:32:45 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Wed Feb 8 14:32:45 2017 +0100

----------------------------------------------------------------------
 .../jmh/distribution/SamplersPerformance.java   | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/cd7ebb45/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java
----------------------------------------------------------------------
diff --git a/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java b/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java
index ea73bcc..b05bfb1 100644
--- a/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java
+++ b/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java
@@ -36,6 +36,8 @@ import org.apache.commons.rng.simple.RandomSource;
 import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
 import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
 import org.apache.commons.rng.sampling.distribution.BoxMullerGaussianSampler;
+import org.apache.commons.rng.sampling.distribution.BoxMullerNormalizedGaussianSampler;
+import org.apache.commons.rng.sampling.distribution.BoxMullerWithRejectionNormalizedGaussianSampler;
 import org.apache.commons.rng.sampling.distribution.AhrensDieterExponentialSampler;
 import org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler;
 import org.apache.commons.rng.sampling.distribution.BoxMullerLogNormalSampler;
@@ -145,6 +147,26 @@ public class SamplersPerformance {
      * @param bh Data sink.
      */
     @Benchmark
+    public void runBoxMullerNormalizedGaussianSampler(Sources sources,
+                                                      Blackhole bh) {
+        runSample(new BoxMullerNormalizedGaussianSampler(sources.getGenerator()), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runBoxMullerWithRejectionNormalizedGaussianSampler(Sources sources,
+                                                                   Blackhole bh) {
+        runSample(new BoxMullerWithRejectionNormalizedGaussianSampler(sources.getGenerator()), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
     public void runAhrensDieterExponentialSampler(Sources sources,
                                                   Blackhole bh) {
         runSample(new AhrensDieterExponentialSampler(sources.getGenerator(), 4.56), bh);


[08/14] commons-rng git commit: RNG-43: Benchmarks for the samplers.

Posted by er...@apache.org.
RNG-43: Benchmarks for the samplers.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/baee35db
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/baee35db
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/baee35db

Branch: refs/heads/master
Commit: baee35dbbe9ad48da2b2c6261364d9b1952227af
Parents: b2dd661
Author: Gilles <er...@apache.org>
Authored: Wed Feb 8 12:23:12 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Wed Feb 8 12:23:12 2017 +0100

----------------------------------------------------------------------
 commons-rng-jmh/pom.xml                         |   6 +
 .../jmh/distribution/SamplersPerformance.java   | 222 +++++++++++++++++++
 2 files changed, 228 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/baee35db/commons-rng-jmh/pom.xml
----------------------------------------------------------------------
diff --git a/commons-rng-jmh/pom.xml b/commons-rng-jmh/pom.xml
index be8ce5a..b4f5285 100644
--- a/commons-rng-jmh/pom.xml
+++ b/commons-rng-jmh/pom.xml
@@ -41,6 +41,12 @@
     </dependency>
 
     <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-rng-sampling</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
       <groupId>org.openjdk.jmh</groupId>
       <artifactId>jmh-core</artifactId>
       <version>${jmh.version}</version>

http://git-wip-us.apache.org/repos/asf/commons-rng/blob/baee35db/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java
----------------------------------------------------------------------
diff --git a/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java b/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java
new file mode 100644
index 0000000..ea73bcc
--- /dev/null
+++ b/commons-rng-jmh/src/main/java/org/apache/commons/rng/jmh/distribution/SamplersPerformance.java
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.rng.jmh.distribution;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.infra.Blackhole;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.simple.RandomSource;
+import org.apache.commons.rng.sampling.distribution.ContinuousSampler;
+import org.apache.commons.rng.sampling.distribution.DiscreteSampler;
+import org.apache.commons.rng.sampling.distribution.BoxMullerGaussianSampler;
+import org.apache.commons.rng.sampling.distribution.AhrensDieterExponentialSampler;
+import org.apache.commons.rng.sampling.distribution.AhrensDieterMarsagliaTsangGammaSampler;
+import org.apache.commons.rng.sampling.distribution.BoxMullerLogNormalSampler;
+import org.apache.commons.rng.sampling.distribution.ChengBetaSampler;
+import org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler;
+import org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler;
+import org.apache.commons.rng.sampling.distribution.RejectionInversionZipfSampler;
+import org.apache.commons.rng.sampling.distribution.PoissonSampler;
+
+/**
+ * Executes benchmark to compare the speed of generation of random numbers
+ * from the various source providers.
+ */
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@State(Scope.Benchmark)
+@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
+public class SamplersPerformance {
+    /** Number of samples per run. */
+    private final int NUM_SAMPLES = 10000000;
+
+    /**
+     * The benchmark state (retrieve the various "RandomSource"s).
+     */
+    @State(Scope.Benchmark)
+    public static class Sources {
+        /**
+         * RNG providers.
+         */
+        @Param({"JDK",
+                "WELL_512_A",
+                "WELL_1024_A",
+                "WELL_19937_A",
+                "WELL_19937_C",
+                "WELL_44497_A",
+                "WELL_44497_B",
+                "MT",
+                "ISAAC",
+                "SPLIT_MIX_64",
+                "MWC_256",
+                "KISS",
+                "XOR_SHIFT_1024_S",
+                "TWO_CMRES",
+                "MT_64" })
+        private String randomSourceName;
+
+        /** RNG. */
+        private UniformRandomProvider generator;
+
+        /**
+         * @return the RNG.
+         */
+        public UniformRandomProvider getGenerator() {
+            return generator;
+        }
+
+        /** Intantiates generator. */
+        @Setup
+        public void setup() {
+            final RandomSource randomSource = RandomSource.valueOf(randomSourceName);
+            generator = RandomSource.create(randomSource);
+        }
+    }
+
+    /**
+     * Exercises a continuous sampler.
+     *
+     * @param sampler Sampler.
+     * @param bh Data sink.
+     */
+    private void runSample(ContinuousSampler sampler,
+                           Blackhole bh) {
+        for (int i = 0; i < NUM_SAMPLES; i++) {
+            bh.consume(sampler.sample());
+        }
+    }
+
+    /**
+     * Exercises a discrete sampler.
+     *
+     * @param sampler Sampler.
+     * @param bh Data sink.
+     */
+    private void runSample(DiscreteSampler sampler,
+                           Blackhole bh) {
+        for (int i = 0; i < NUM_SAMPLES; i++) {
+            bh.consume(sampler.sample());
+        }
+    }
+
+    // Benchmarks methods below.
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runBoxMullerGaussianSampler(Sources sources,
+                                            Blackhole bh) {
+        runSample(new BoxMullerGaussianSampler(sources.getGenerator(), 0, 1), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runAhrensDieterExponentialSampler(Sources sources,
+                                                  Blackhole bh) {
+        runSample(new AhrensDieterExponentialSampler(sources.getGenerator(), 4.56), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runAhrensDieterMarsagliaTsangGammaSampler(Sources sources,
+                                                          Blackhole bh) {
+        runSample(new AhrensDieterMarsagliaTsangGammaSampler(sources.getGenerator(), 9.8, 0.76), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runBoxMullerLogNormalSampler(Sources sources,
+                                             Blackhole bh) {
+        runSample(new BoxMullerLogNormalSampler(sources.getGenerator(), 12.3, 4.6), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runChengBetaSampler(Sources sources,
+                                    Blackhole bh) {
+        runSample(new ChengBetaSampler(sources.getGenerator(), 0.45, 6.7), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runContinuousUniformSampler(Sources sources,
+                                            Blackhole bh) {
+        runSample(new ContinuousUniformSampler(sources.getGenerator(), 123.4, 5678.9), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runDiscreteUniformSampler(Sources sources,
+                                          Blackhole bh) {
+        runSample(new DiscreteUniformSampler(sources.getGenerator(), -98, 76), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runRejectionInversionZipfSampler(Sources sources,
+                                                 Blackhole bh) {
+        runSample(new RejectionInversionZipfSampler(sources.getGenerator(), 43, 2.1), bh);
+    }
+
+    /**
+     * @param sources Source of randomness.
+     * @param bh Data sink.
+     */
+    @Benchmark
+    public void runPoissonSampler(Sources sources,
+                                  Blackhole bh) {
+        runSample(new PoissonSampler(sources.getGenerator(), 8.9), bh);
+    }
+}


[11/14] commons-rng git commit: Unused import.

Posted by er...@apache.org.
Unused import.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/31dba790
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/31dba790
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/31dba790

Branch: refs/heads/master
Commit: 31dba790c02f59a6c19c84a35cdd21c773f04505
Parents: 99db6ce
Author: Gilles <er...@apache.org>
Authored: Wed Feb 8 13:31:23 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Wed Feb 8 13:31:23 2017 +0100

----------------------------------------------------------------------
 .../apache/commons/rng/sampling/distribution/GaussianSampler.java  | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/31dba790/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java
index 3fda5c5..47fe5f8 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/GaussianSampler.java
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.rng.sampling.distribution;
 
-import org.apache.commons.rng.UniformRandomProvider;
-
 /**
  * Sampling from a Gaussian distribution with given mean and
  * standard deviation.


[10/14] commons-rng git commit: Typo.

Posted by er...@apache.org.
Typo.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/99db6ced
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/99db6ced
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/99db6ced

Branch: refs/heads/master
Commit: 99db6cedc853d3a9b13d7cc3ff7ef2cb35ceccd6
Parents: 5b1c21e
Author: Gilles <er...@apache.org>
Authored: Wed Feb 8 13:31:09 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Wed Feb 8 13:31:09 2017 +0100

----------------------------------------------------------------------
 .../BoxMullerWithRejectionNormalizedGaussianSampler.java           | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/99db6ced/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java
index 58d1b1f..ae77ce6 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerWithRejectionNormalizedGaussianSampler.java
@@ -24,7 +24,7 @@ import org.apache.commons.rng.UniformRandomProvider;
  * mean 0 and standard deviation 1.
  * This is a variation, suggested in <a href="http://haifux.org/lectures/79/random.pdf">
  * this presentation</a> (page 39), of the algorithm implemented in
- * {@link BoxMullerNormalizedGaussianSampler}, 
+ * {@link BoxMullerNormalizedGaussianSampler}.
  *
  * @since 1.1
  */


[14/14] commons-rng git commit: RNG-36: Use faster version of the normalized Gaussian sampler.

Posted by er...@apache.org.
RNG-36: Use faster version of the normalized Gaussian sampler.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/688f3611
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/688f3611
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/688f3611

Branch: refs/heads/master
Commit: 688f3611131e05a072d998edb93e13492c3ed256
Parents: cd7ebb4
Author: Gilles <er...@apache.org>
Authored: Thu Feb 9 01:20:27 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Thu Feb 9 01:20:27 2017 +0100

----------------------------------------------------------------------
 .../distribution/AhrensDieterMarsagliaTsangGammaSampler.java       | 2 +-
 .../rng/sampling/distribution/BoxMullerLogNormalSampler.java       | 2 +-
 .../apache/commons/rng/sampling/distribution/PoissonSampler.java   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/688f3611/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
index 180b531..baf3b17 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
@@ -60,7 +60,7 @@ public class AhrensDieterMarsagliaTsangGammaSampler
         super(rng);
         this.alpha = alpha;
         this.theta = theta;
-        gaussian = new BoxMullerNormalizedGaussianSampler(rng);
+        gaussian = new BoxMullerWithRejectionNormalizedGaussianSampler(rng);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/commons-rng/blob/688f3611/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java
index 354b8d4..5e4ba22 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/BoxMullerLogNormalSampler.java
@@ -43,7 +43,7 @@ public class BoxMullerLogNormalSampler
         super(null); // Not used.
         this.scale = scale;
         this.shape = shape;
-        gaussian = new BoxMullerNormalizedGaussianSampler(rng);
+        gaussian = new BoxMullerWithRejectionNormalizedGaussianSampler(rng);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/commons-rng/blob/688f3611/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java
index d872be9..ea40f81 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/PoissonSampler.java
@@ -64,7 +64,7 @@ public class PoissonSampler
 
         this.mean = mean;
 
-        gaussian = new BoxMullerNormalizedGaussianSampler(rng);
+        gaussian = new BoxMullerWithRejectionNormalizedGaussianSampler(rng);
         exponential = new AhrensDieterExponentialSampler(rng, 1);
         factorialLog = mean < PIVOT ?
             null : // Not used.


[09/14] commons-rng git commit: Merge branch 'feature__RNG-35'

Posted by er...@apache.org.
Merge branch 'feature__RNG-35'

Completes the following issues (see JIRA):
 * RNG-35
 * RNG-36


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/5b1c21e5
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/5b1c21e5
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/5b1c21e5

Branch: refs/heads/master
Commit: 5b1c21e50840ba08516a38eec18b2472896db238
Parents: baee35d c14e09c
Author: Gilles <er...@apache.org>
Authored: Wed Feb 8 12:41:14 2017 +0100
Committer: Gilles <er...@apache.org>
Committed: Wed Feb 8 12:41:14 2017 +0100

----------------------------------------------------------------------
 .../AhrensDieterMarsagliaTsangGammaSampler.java |  4 +-
 .../distribution/BoxMullerGaussianSampler.java  |  4 +
 .../distribution/BoxMullerLogNormalSampler.java |  4 +-
 .../BoxMullerNormalizedGaussianSampler.java     | 75 +++++++++++++++++
 ...rWithRejectionNormalizedGaussianSampler.java | 88 ++++++++++++++++++++
 .../sampling/distribution/GaussianSampler.java  | 59 +++++++++++++
 .../distribution/NormalizedGaussianSampler.java | 24 ++++++
 .../sampling/distribution/PoissonSampler.java   |  4 +-
 .../distribution/ContinuousSamplersList.java    | 10 ++-
 9 files changed, 265 insertions(+), 7 deletions(-)
----------------------------------------------------------------------