diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 15c942506..0a78444b6 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -51,6 +51,11 @@ If the output is not quite correct, check for invisible trailing spaces! + + Added overloaded constructors for subclasses of "RealDistribution" implementations + which do not require an explicit "inverseCumulativeAccuracy". The default accuracy will + be used instead. + Added overloaded methods for "Frequency#incrementValue(Comparable, long)" with int, long and char primitive arguments. diff --git a/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java b/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java index a3ab82479..bb1ba8045 100644 --- a/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/BetaDistribution.java @@ -74,6 +74,18 @@ public class BetaDistribution extends AbstractRealDistribution { this(new Well19937c(), alpha, beta, inverseCumAccuracy); } + /** + * Creates a β distribution. + * + * @param rng Random number generator. + * @param alpha First shape parameter (must be positive). + * @param beta Second shape parameter (must be positive). + * @since 3.3 + */ + public BetaDistribution(RandomGenerator rng, double alpha, double beta) { + this(rng, alpha, beta, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates a β distribution. * diff --git a/src/main/java/org/apache/commons/math3/distribution/CauchyDistribution.java b/src/main/java/org/apache/commons/math3/distribution/CauchyDistribution.java index 310e8f331..e1a69fcc2 100644 --- a/src/main/java/org/apache/commons/math3/distribution/CauchyDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/CauchyDistribution.java @@ -80,6 +80,19 @@ public class CauchyDistribution extends AbstractRealDistribution { this(new Well19937c(), median, scale, inverseCumAccuracy); } + /** + * Creates a Cauchy distribution. + * + * @param rng Random number generator. + * @param median Median for this distribution. + * @param scale Scale parameter for this distribution. + * @throws NotStrictlyPositiveException if {@code scale <= 0}. + * @since 3.3 + */ + public CauchyDistribution(RandomGenerator rng, double median, double scale) { + this(rng, median, scale, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates a Cauchy distribution. * diff --git a/src/main/java/org/apache/commons/math3/distribution/ChiSquaredDistribution.java b/src/main/java/org/apache/commons/math3/distribution/ChiSquaredDistribution.java index 85bdb3c05..c38d50134 100644 --- a/src/main/java/org/apache/commons/math3/distribution/ChiSquaredDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/ChiSquaredDistribution.java @@ -63,6 +63,17 @@ public class ChiSquaredDistribution extends AbstractRealDistribution { this(new Well19937c(), degreesOfFreedom, inverseCumAccuracy); } + /** + * Create a Chi-Squared distribution with the given degrees of freedom. + * + * @param rng Random number generator. + * @param degreesOfFreedom Degrees of freedom. + * @since 3.3 + */ + public ChiSquaredDistribution(RandomGenerator rng, double degreesOfFreedom) { + this(rng, degreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Create a Chi-Squared distribution with the given degrees of freedom and * inverse cumulative probability accuracy. diff --git a/src/main/java/org/apache/commons/math3/distribution/ExponentialDistribution.java b/src/main/java/org/apache/commons/math3/distribution/ExponentialDistribution.java index 22b32e1b2..25f4a34ab 100644 --- a/src/main/java/org/apache/commons/math3/distribution/ExponentialDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/ExponentialDistribution.java @@ -110,6 +110,19 @@ public class ExponentialDistribution extends AbstractRealDistribution { this(new Well19937c(), mean, inverseCumAccuracy); } + /** + * Creates an exponential distribution. + * + * @param rng Random number generator. + * @param mean Mean of this distribution. + * @throws NotStrictlyPositiveException if {@code mean <= 0}. + * @since 3.3 + */ + public ExponentialDistribution(RandomGenerator rng, double mean) + throws NotStrictlyPositiveException { + this(rng, mean, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates an exponential distribution. * diff --git a/src/main/java/org/apache/commons/math3/distribution/FDistribution.java b/src/main/java/org/apache/commons/math3/distribution/FDistribution.java index e301e2ef5..aed2d3402 100644 --- a/src/main/java/org/apache/commons/math3/distribution/FDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/FDistribution.java @@ -87,6 +87,23 @@ public class FDistribution extends AbstractRealDistribution { denominatorDegreesOfFreedom, inverseCumAccuracy); } + /** + * Creates an F distribution. + * + * @param rng Random number generator. + * @param numeratorDegreesOfFreedom Numerator degrees of freedom. + * @param denominatorDegreesOfFreedom Denominator degrees of freedom. + * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0} or + * {@code denominatorDegreesOfFreedom <= 0}. + * @since 3.3 + */ + public FDistribution(RandomGenerator rng, + double numeratorDegreesOfFreedom, + double denominatorDegreesOfFreedom) + throws NotStrictlyPositiveException { + this(rng, numeratorDegreesOfFreedom, denominatorDegreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates an F distribution. * @@ -95,8 +112,7 @@ public class FDistribution extends AbstractRealDistribution { * @param denominatorDegreesOfFreedom Denominator degrees of freedom. * @param inverseCumAccuracy the maximum absolute error in inverse * cumulative probability estimates. - * @throws NotStrictlyPositiveException if - * {@code numeratorDegreesOfFreedom <= 0} or + * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0} or * {@code denominatorDegreesOfFreedom <= 0}. * @since 3.1 */ diff --git a/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java b/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java index 1f7a2b348..e08e34490 100644 --- a/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/GammaDistribution.java @@ -111,6 +111,21 @@ public class GammaDistribution extends AbstractRealDistribution { this(new Well19937c(), shape, scale, inverseCumAccuracy); } + /** + * Creates a Gamma distribution. + * + * @param rng Random number generator. + * @param shape the shape parameter + * @param scale the scale parameter + * @throws NotStrictlyPositiveException if {@code shape <= 0} or + * {@code scale <= 0}. + * @since 3.3 + */ + public GammaDistribution(RandomGenerator rng, double shape, double scale) + throws NotStrictlyPositiveException { + this(rng, shape, scale, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates a Gamma distribution. * diff --git a/src/main/java/org/apache/commons/math3/distribution/LogNormalDistribution.java b/src/main/java/org/apache/commons/math3/distribution/LogNormalDistribution.java index 3b3c61ba2..e68feac8c 100644 --- a/src/main/java/org/apache/commons/math3/distribution/LogNormalDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/LogNormalDistribution.java @@ -112,6 +112,20 @@ public class LogNormalDistribution extends AbstractRealDistribution { this(new Well19937c(), scale, shape, inverseCumAccuracy); } + /** + * Creates a log-normal distribution. + * + * @param rng Random number generator. + * @param scale Scale parameter of this distribution. + * @param shape Shape parameter of this distribution. + * @throws NotStrictlyPositiveException if {@code shape <= 0}. + * @since 3.3 + */ + public LogNormalDistribution(RandomGenerator rng, double scale, double shape) + throws NotStrictlyPositiveException { + this(rng, scale, shape, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates a log-normal distribution. * diff --git a/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java b/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java index 9fe201a52..a38c231eb 100644 --- a/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/NormalDistribution.java @@ -87,6 +87,20 @@ public class NormalDistribution extends AbstractRealDistribution { this(new Well19937c(), mean, sd, inverseCumAccuracy); } + /** + * Creates a normal distribution. + * + * @param rng Random number generator. + * @param mean Mean for this distribution. + * @param sd Standard deviation for this distribution. + * @throws NotStrictlyPositiveException if {@code sd <= 0}. + * @since 3.3 + */ + public NormalDistribution(RandomGenerator rng, double mean, double sd) + throws NotStrictlyPositiveException { + this(rng, mean, sd, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates a normal distribution. * diff --git a/src/main/java/org/apache/commons/math3/distribution/ParetoDistribution.java b/src/main/java/org/apache/commons/math3/distribution/ParetoDistribution.java index 8a98fc504..8b0a7157c 100644 --- a/src/main/java/org/apache/commons/math3/distribution/ParetoDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/ParetoDistribution.java @@ -97,6 +97,19 @@ public class ParetoDistribution extends AbstractRealDistribution { this(new Well19937c(), scale, shape, inverseCumAccuracy); } + /** + * Creates a log-normal distribution. + * + * @param rng Random number generator. + * @param scale Scale parameter of this distribution. + * @param shape Shape parameter of this distribution. + * @throws NotStrictlyPositiveException if {@code scale <= 0} or {@code shape <= 0}. + */ + public ParetoDistribution(RandomGenerator rng, double scale, double shape) + throws NotStrictlyPositiveException { + this(rng, scale, shape, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates a log-normal distribution. * diff --git a/src/main/java/org/apache/commons/math3/distribution/TDistribution.java b/src/main/java/org/apache/commons/math3/distribution/TDistribution.java index 098e7c80d..9a65d336c 100644 --- a/src/main/java/org/apache/commons/math3/distribution/TDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/TDistribution.java @@ -71,6 +71,19 @@ public class TDistribution extends AbstractRealDistribution { this(new Well19937c(), degreesOfFreedom, inverseCumAccuracy); } + /** + * Creates a t distribution. + * + * @param rng Random number generator. + * @param degreesOfFreedom Degrees of freedom. + * @throws NotStrictlyPositiveException if {@code degreesOfFreedom <= 0} + * @since 3.3 + */ + public TDistribution(RandomGenerator rng, double degreesOfFreedom) + throws NotStrictlyPositiveException { + this(rng, degreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates a t distribution. * diff --git a/src/main/java/org/apache/commons/math3/distribution/WeibullDistribution.java b/src/main/java/org/apache/commons/math3/distribution/WeibullDistribution.java index 9e2430357..58478e91c 100644 --- a/src/main/java/org/apache/commons/math3/distribution/WeibullDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/WeibullDistribution.java @@ -91,6 +91,20 @@ public class WeibullDistribution extends AbstractRealDistribution { this(new Well19937c(), alpha, beta, inverseCumAccuracy); } + /** + * Creates a Weibull distribution. + * + * @param rng Random number generator. + * @param alpha Shape parameter. + * @param beta Scale parameter. + * @throws NotStrictlyPositiveException if {@code alpha <= 0} or {@code beta <= 0}. + * @since 3.3 + */ + public WeibullDistribution(RandomGenerator rng, double alpha, double beta) + throws NotStrictlyPositiveException { + this(rng, alpha, beta, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); + } + /** * Creates a Weibull distribution. * @@ -100,8 +114,7 @@ public class WeibullDistribution extends AbstractRealDistribution { * @param inverseCumAccuracy Maximum absolute error in inverse * cumulative probability estimates * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}). - * @throws NotStrictlyPositiveException if {@code alpha <= 0} or - * {@code beta <= 0}. + * @throws NotStrictlyPositiveException if {@code alpha <= 0} or {@code beta <= 0}. * @since 3.1 */ public WeibullDistribution(RandomGenerator rng,