Rename shape/scale to mu/sigma
diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogNormalDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogNormalDistribution.java
index 26f5609..6421430 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogNormalDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/LogNormalDistribution.java
@@ -33,13 +33,11 @@
* is given by (for {@code x > 0})
* </p>
* <p>
- * {@code exp(-0.5 * ((ln(x) - m) / s)^2) / (s * sqrt(2 * pi) * x)}
+ * {@code exp(-0.5 * ((ln(x) - mu) / s)^2) / (s * sqrt(2 * pi) * x)}
* </p>
* <ul>
- * <li>{@code m} is the <em>scale</em> parameter: this is the mean of the
- * normally distributed natural logarithm of this distribution,</li>
- * <li>{@code s} is the <em>shape</em> parameter: this is the standard
- * deviation of the normally distributed natural logarithm of this
+ * <li>{@code mu} is the mean of the normally distributed natural logarithm of this distribution,</li>
+ * <li>{@code s} is standard deviation of the normally distributed natural logarithm of this
* distribution.
* </ul>
*/
@@ -48,57 +46,61 @@
private static final double SQRT2PI = Math.sqrt(2 * Math.PI);
/** √(2). */
private static final double SQRT2 = Math.sqrt(2);
- /** The scale parameter of this distribution. */
- private final double scale;
- /** The shape parameter of this distribution. */
- private final double shape;
- /** The value of {@code log(shape) + 0.5 * log(2*PI)} stored for faster computation. */
+ /** The mu parameter of this distribution. */
+ private final double mu;
+ /** The sigma parameter of this distribution. */
+ private final double sigma;
+ /** The value of {@code log(sigma) + 0.5 * log(2*PI)} stored for faster computation. */
private final double logShapePlusHalfLog2Pi;
/**
* Creates a log-normal distribution.
*
- * @param scale Scale parameter of this distribution.
- * @param shape Shape parameter of this distribution.
- * @throws IllegalArgumentException if {@code shape <= 0}.
+ * @param mu Mean of the natural logarithm of the distribution values.
+ * @param sigma Standard deviation of the natural logarithm of the distribution values.
+ * @throws IllegalArgumentException if {@code sigma <= 0}.
*/
- public LogNormalDistribution(double scale,
- double shape) {
- if (shape <= 0) {
- throw new DistributionException(DistributionException.NOT_STRICTLY_POSITIVE, shape);
+ public LogNormalDistribution(double mu,
+ double sigma) {
+ if (sigma <= 0) {
+ throw new DistributionException(DistributionException.NOT_STRICTLY_POSITIVE, sigma);
}
- this.scale = scale;
- this.shape = shape;
- this.logShapePlusHalfLog2Pi = Math.log(shape) + 0.5 * Math.log(2 * Math.PI);
+ this.mu = mu;
+ this.sigma = sigma;
+ this.logShapePlusHalfLog2Pi = Math.log(sigma) + 0.5 * Math.log(2 * Math.PI);
}
/**
- * Returns the scale parameter of this distribution.
+ * Returns the mu parameter of this distribution.
+ * This is the mean of the natural logarithm of the distribution values,
+ * not the mean of distribution.
*
- * @return the scale parameter
+ * @return the mu parameter
*/
- public double getScale() {
- return scale;
+ public double getMu() {
+ return mu;
}
/**
- * Returns the shape parameter of this distribution.
+ * Returns the sigma parameter of this distribution.
+ * This is the standard deviation of the natural logarithm of the distribution values,
+ * not the standard deviation of distribution.
*
- * @return the shape parameter
+ * @return the sigma parameter
*/
- public double getShape() {
- return shape;
+ public double getSigma() {
+ return sigma;
}
/**
* {@inheritDoc}
*
- * <p>For scale {@code m}, and shape {@code s} of this distribution, the PDF
+ * <p>For {@code mu}, and sigma {@code s} of this distribution, the PDF
* is given by
* <ul>
* <li>{@code 0} if {@code x <= 0},</li>
- * <li>{@code exp(-0.5 * ((ln(x) - m) / s)^2) / (s * sqrt(2 * pi) * x)}
+ * <li>{@code exp(-0.5 * ((ln(x) - mu) / s)^2) / (s * sqrt(2 * pi) * x)}
* otherwise.</li>
* </ul>
*/
@@ -107,9 +109,9 @@
if (x <= 0) {
return 0;
}
- final double x0 = Math.log(x) - scale;
- final double x1 = x0 / shape;
- return Math.exp(-0.5 * x1 * x1) / (shape * SQRT2PI * x);
+ final double x0 = Math.log(x) - mu;
+ final double x1 = x0 / sigma;
+ return Math.exp(-0.5 * x1 * x1) / (sigma * SQRT2PI * x);
}
/** {@inheritDoc} */
@@ -124,9 +126,9 @@
return super.probability(x0, x1);
}
// Assumes x1 >= x0 && x0 > 0
- final double denom = shape * SQRT2;
- final double v0 = (Math.log(x0) - scale) / denom;
- final double v1 = (Math.log(x1) - scale) / denom;
+ final double denom = sigma * SQRT2;
+ final double v0 = (Math.log(x0) - mu) / denom;
+ final double v1 = (Math.log(x1) - mu) / denom;
return 0.5 * ErfDifference.value(v0, v1);
}
@@ -140,24 +142,24 @@
return Double.NEGATIVE_INFINITY;
}
final double logX = Math.log(x);
- final double x0 = logX - scale;
- final double x1 = x0 / shape;
+ final double x0 = logX - mu;
+ final double x1 = x0 / sigma;
return -0.5 * x1 * x1 - (logShapePlusHalfLog2Pi + logX);
}
/**
* {@inheritDoc}
*
- * <p>For scale {@code m}, and shape {@code s} of this distribution, the CDF
+ * <p>For {@code mu}, and sigma {@code s} of this distribution, the CDF
* is given by
* <ul>
* <li>{@code 0} if {@code x <= 0},</li>
- * <li>{@code 0} if {@code ln(x) - m < 0} and {@code m - ln(x) > 40 * s}, as
+ * <li>{@code 0} if {@code ln(x) - mu < 0} and {@code mu - ln(x) > 40 * s}, as
* in these cases the actual value is within {@code Double.MIN_VALUE} of 0,
- * <li>{@code 1} if {@code ln(x) - m >= 0} and {@code ln(x) - m > 40 * s},
+ * <li>{@code 1} if {@code ln(x) - mu >= 0} and {@code ln(x) - mu > 40 * s},
* as in these cases the actual value is within {@code Double.MIN_VALUE} of
* 1,</li>
- * <li>{@code 0.5 + 0.5 * erf((ln(x) - m) / (s * sqrt(2))} otherwise.</li>
+ * <li>{@code 0.5 + 0.5 * erf((ln(x) - mu) / (s * sqrt(2))} otherwise.</li>
* </ul>
*/
@Override
@@ -165,11 +167,11 @@
if (x <= 0) {
return 0;
}
- final double dev = Math.log(x) - scale;
- if (Math.abs(dev) > 40 * shape) {
+ final double dev = Math.log(x) - mu;
+ if (Math.abs(dev) > 40 * sigma) {
return dev < 0 ? 0.0d : 1.0d;
}
- return 0.5 * Erfc.value(-dev / (shape * SQRT2));
+ return 0.5 * Erfc.value(-dev / (sigma * SQRT2));
}
/** {@inheritDoc} */
@@ -178,36 +180,36 @@
if (x <= 0) {
return 1;
}
- final double dev = Math.log(x) - scale;
- if (Math.abs(dev) > 40 * shape) {
+ final double dev = Math.log(x) - mu;
+ if (Math.abs(dev) > 40 * sigma) {
return dev > 0 ? 0.0d : 1.0d;
}
- return 0.5 * Erfc.value(dev / (shape * SQRT2));
+ return 0.5 * Erfc.value(dev / (sigma * SQRT2));
}
/**
* {@inheritDoc}
*
- * <p>For scale {@code m} and shape {@code s}, the mean is
+ * <p>For {@code mu} and sigma {@code s}, the mean is
* {@code exp(m + s^2 / 2)}.
*/
@Override
public double getMean() {
- final double s = shape;
- return Math.exp(scale + (s * s / 2));
+ final double s = sigma;
+ return Math.exp(mu + (s * s / 2));
}
/**
* {@inheritDoc}
*
- * <p>For scale {@code m} and shape {@code s}, the variance is
+ * <p>For {@code mu} and sigma {@code s}, the variance is
* {@code (exp(s^2) - 1) * exp(2 * m + s^2)}.
*/
@Override
public double getVariance() {
- final double s = shape;
+ final double s = sigma;
final double ss = s * s;
- return Math.expm1(ss) * Math.exp(2 * scale + ss);
+ return Math.expm1(ss) * Math.exp(2 * mu + ss);
}
/**
@@ -252,6 +254,6 @@
@Override
public ContinuousDistribution.Sampler createSampler(final UniformRandomProvider rng) {
// Log normal distribution sampler.
- return new LogNormalSampler(new ZigguratNormalizedGaussianSampler(rng), scale, shape)::sample;
+ return new LogNormalSampler(new ZigguratNormalizedGaussianSampler(rng), mu, sigma)::sample;
}
}
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/LogNormalDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/LogNormalDistributionTest.java
index e6685f8..d44d960 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/LogNormalDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/LogNormalDistributionTest.java
@@ -116,8 +116,8 @@
private void verifyQuantiles() {
final LogNormalDistribution distribution = (LogNormalDistribution)getDistribution();
- final double mu = distribution.getScale();
- final double sigma = distribution.getShape();
+ final double mu = distribution.getMu();
+ final double sigma = distribution.getSigma();
setCumulativeTestPoints(new double[] {mu - 2 * sigma, mu - sigma,
mu, mu + sigma,
mu + 2 * sigma, mu + 3 * sigma,
@@ -190,8 +190,8 @@
@Test
void testParameterAccessors() {
final LogNormalDistribution distribution = (LogNormalDistribution)getDistribution();
- Assertions.assertEquals(2.1, distribution.getScale());
- Assertions.assertEquals(1.4, distribution.getShape());
+ Assertions.assertEquals(2.1, distribution.getMu());
+ Assertions.assertEquals(1.4, distribution.getSigma());
}
@Test