From 26d668f6d5a2f202ef7ff6a73ff3cbd7bbdf4b06 Mon Sep 17 00:00:00 2001 From: Gilles Date: Sat, 12 Mar 2016 03:12:54 +0100 Subject: [PATCH] MATH-1158. Method "createSampler" overridden in "LogNormalDistribution". --- .../distribution/LogNormalDistribution.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 58504ee25..8bec045e4 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); + } + }; + } }