MATH-1158.

Method "createSampler" overridden in "LogNormalDistribution".


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

Branch: refs/heads/feature-MATH-1158
Commit: 26d668f6d5a2f202ef7ff6a73ff3cbd7bbdf4b06
Parents: f72b5e6
Author: Gilles <er...@apache.org>
Authored: Sat Mar 12 03:12:54 2016 +0100
Committer: Gilles <er...@apache.org>
Committed: Sat Mar 12 03:12:54 2016 +0100

----------------------------------------------------------------------
 .../distribution/LogNormalDistribution.java     | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/26d668f6/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
 
b/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
index 58504ee..8bec045 100644
--- 
a/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
+++ 
b/src/main/java/org/apache/commons/math4/distribution/LogNormalDistribution.java
@@ -22,6 +22,7 @@ import 
org.apache.commons.math4.exception.NumberIsTooLargeException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
 import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.Well19937c;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.special.Erf;
 import org.apache.commons.math4.util.FastMath;
 
@@ -143,6 +144,7 @@ public class LogNormalDistribution extends 
AbstractRealDistribution {
      * @throws NotStrictlyPositiveException if {@code shape <= 0}.
      * @since 3.3
      */
+    @Deprecated
     public LogNormalDistribution(RandomGenerator rng, double scale, double 
shape)
         throws NotStrictlyPositiveException {
         this(rng, scale, shape, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
@@ -158,6 +160,7 @@ public class LogNormalDistribution extends 
AbstractRealDistribution {
      * @throws NotStrictlyPositiveException if {@code shape <= 0}.
      * @since 3.1
      */
+    @Deprecated
     public LogNormalDistribution(RandomGenerator rng,
                                  double scale,
                                  double shape,
@@ -345,8 +348,25 @@ public class LogNormalDistribution extends 
AbstractRealDistribution {
 
     /** {@inheritDoc} */
     @Override
+    @Deprecated
     public double sample()  {
         final double n = random.nextGaussian();
         return FastMath.exp(scale + shape * n);
     }
+
+    /** {@inheritDoc} */
+    @Override
+    public RealDistribution.Sampler createSampler(final UniformRandomProvider 
rng) {
+        return new RealDistribution.Sampler() {
+            /** Gaussian sampling. */
+            final RealDistribution.Sampler gaussian = new 
NormalDistribution().createSampler(rng);
+
+            /** {@inheritDoc} */
+            @Override
+            public double sample() {
+                final double n = random.nextGaussian();
+                return FastMath.exp(scale + shape * n);
+            }
+        };
+    }
 }

Reply via email to