MATH-1158
Using the new sampler API. Deprecate old API (including the now obsolete constructors). Apart from the main focus of the issue (distribution classes), this change also had an impact on: * some of test classes that use random numbers (where the tolerance may have its value updated when it is highly sensitive on the RNG seed) * statistical inference tests that use a distribution but not the RNG (cf. MATH-1124) which now deprecated code passed to its contructor. * classes in package "o.a.c.m.random" that depend on some of the distributions
This commit is contained in:
parent
26d668f6d5
commit
9867d9f281
|
@ -48,23 +48,15 @@ public abstract class AbstractRealDistribution
|
|||
/** Default absolute accuracy for inverse cumulative computation. */
|
||||
public static final double SOLVER_DEFAULT_ABSOLUTE_ACCURACY = 1e-6;
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = -38038050983108802L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
|
||||
/**
|
||||
* RNG instance used to generate samples from the distribution.
|
||||
* @since 3.1
|
||||
* XXX: hard-coded value to prevent "NullPointerException".
|
||||
*/
|
||||
@Deprecated
|
||||
protected final RandomGenerator random;
|
||||
|
||||
/**
|
||||
* @param rng Random number generator.
|
||||
* @since 3.1
|
||||
*/
|
||||
@Deprecated
|
||||
protected AbstractRealDistribution(RandomGenerator rng) {
|
||||
random = rng;
|
||||
}
|
||||
protected final RandomGenerator random = new org.apache.commons.math4.random.Well19937c();
|
||||
|
||||
/**
|
||||
* For a random variable {@code X} whose values are distributed according
|
||||
|
|
|
@ -18,8 +18,6 @@ package org.apache.commons.math4.distribution;
|
|||
|
||||
import org.apache.commons.math4.exception.NumberIsTooSmallException;
|
||||
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.Beta;
|
||||
import org.apache.commons.math4.special.Gamma;
|
||||
|
@ -39,7 +37,7 @@ public class BetaDistribution extends AbstractRealDistribution {
|
|||
*/
|
||||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = -1221965979403477668L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/** First shape parameter. */
|
||||
private final double alpha;
|
||||
/** Second shape parameter. */
|
||||
|
@ -52,14 +50,7 @@ public class BetaDistribution extends AbstractRealDistribution {
|
|||
private final double solverAbsoluteAccuracy;
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param alpha First shape parameter (must be positive).
|
||||
* @param beta Second shape parameter (must be positive).
|
||||
|
@ -69,57 +60,19 @@ public class BetaDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param alpha First shape parameter (must be positive).
|
||||
* @param beta Second shape parameter (must be positive).
|
||||
* @param inverseCumAccuracy Maximum absolute error in inverse
|
||||
* cumulative probability estimates (defaults to
|
||||
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @since 2.1
|
||||
*/
|
||||
public BetaDistribution(double alpha, double beta, double inverseCumAccuracy) {
|
||||
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
|
||||
*/
|
||||
@Deprecated
|
||||
public BetaDistribution(RandomGenerator rng, double alpha, double beta) {
|
||||
this(rng, alpha, beta, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a β distribution.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param alpha First shape parameter (must be positive).
|
||||
* @param beta Second shape parameter (must be positive).
|
||||
* @param inverseCumAccuracy Maximum absolute error in inverse
|
||||
* cumulative probability estimates (defaults to
|
||||
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @since 3.1
|
||||
*/
|
||||
@Deprecated
|
||||
public BetaDistribution(RandomGenerator rng,
|
||||
double alpha,
|
||||
public BetaDistribution(double alpha,
|
||||
double beta,
|
||||
double inverseCumAccuracy) {
|
||||
super(rng);
|
||||
|
||||
this.alpha = alpha;
|
||||
this.beta = beta;
|
||||
z = Double.NaN;
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.util.FastMath;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +35,7 @@ public class CauchyDistribution extends AbstractRealDistribution {
|
|||
*/
|
||||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = 8589540077390120676L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/** The median of this distribution. */
|
||||
private final double median;
|
||||
/** The scale of this distribution. */
|
||||
|
@ -54,31 +52,19 @@ public class CauchyDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a Cauchy distribution using the given median and scale.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param median Median for this distribution.
|
||||
* @param scale Scale parameter for this distribution.
|
||||
* @throws NotStrictlyPositiveException if {@code scale <= 0}.
|
||||
*/
|
||||
public CauchyDistribution(double median, double scale) {
|
||||
public CauchyDistribution(double median,
|
||||
double scale) {
|
||||
this(median, scale, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Cauchy distribution using the given median and scale.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param median Median for this distribution.
|
||||
* @param scale Scale parameter for this distribution.
|
||||
|
@ -86,43 +72,10 @@ public class CauchyDistribution extends AbstractRealDistribution {
|
|||
* cumulative probability estimates
|
||||
* (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NotStrictlyPositiveException if {@code scale <= 0}.
|
||||
* @since 2.1
|
||||
*/
|
||||
public CauchyDistribution(double median, double scale,
|
||||
double inverseCumAccuracy) {
|
||||
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.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param median Median for this distribution.
|
||||
* @param scale Scale parameter for this distribution.
|
||||
* @param inverseCumAccuracy Maximum absolute error in inverse
|
||||
* cumulative probability estimates
|
||||
* (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NotStrictlyPositiveException if {@code scale <= 0}.
|
||||
* @since 3.1
|
||||
*/
|
||||
public CauchyDistribution(RandomGenerator rng,
|
||||
double median,
|
||||
public CauchyDistribution(double median,
|
||||
double scale,
|
||||
double inverseCumAccuracy) {
|
||||
super(rng);
|
||||
if (scale <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
*/
|
||||
package org.apache.commons.math4.distribution;
|
||||
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well19937c;
|
||||
|
||||
/**
|
||||
* Implementation of the chi-squared distribution.
|
||||
*
|
||||
|
@ -32,14 +29,14 @@ public class ChiSquaredDistribution extends AbstractRealDistribution {
|
|||
*/
|
||||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = -8352658048349159782L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/** Internal Gamma distribution. */
|
||||
private final GammaDistribution gamma;
|
||||
/** Inverse cumulative probability accuracy */
|
||||
private final double solverAbsoluteAccuracy;
|
||||
|
||||
/**
|
||||
* Create a Chi-Squared distribution with the given degrees of freedom.
|
||||
* Creates distribution with the given degrees of freedom.
|
||||
*
|
||||
* @param degreesOfFreedom Degrees of freedom.
|
||||
*/
|
||||
|
@ -48,54 +45,18 @@ public class ChiSquaredDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a Chi-Squared distribution with the given degrees of freedom and
|
||||
* Creates a distribution with the given degrees of freedom and
|
||||
* inverse cumulative probability accuracy.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*
|
||||
* @param degreesOfFreedom Degrees of freedom.
|
||||
* @param inverseCumAccuracy the maximum absolute error in inverse
|
||||
* cumulative probability estimates (defaults to
|
||||
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public ChiSquaredDistribution(double degreesOfFreedom,
|
||||
double inverseCumAccuracy) {
|
||||
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.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param degreesOfFreedom Degrees of freedom.
|
||||
* @param inverseCumAccuracy the maximum absolute error in inverse
|
||||
* cumulative probability estimates (defaults to
|
||||
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @since 3.1
|
||||
*/
|
||||
public ChiSquaredDistribution(RandomGenerator rng,
|
||||
double degreesOfFreedom,
|
||||
double inverseCumAccuracy) {
|
||||
super(rng);
|
||||
|
||||
gamma = new GammaDistribution(degreesOfFreedom / 2, 2);
|
||||
solverAbsoluteAccuracy = inverseCumAccuracy;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,6 @@ public class ConstantRealDistribution extends AbstractRealDistribution {
|
|||
* @param value the constant value of this distribution
|
||||
*/
|
||||
public ConstantRealDistribution(double value) {
|
||||
super(null); // Avoid creating RandomGenerator
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
|||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
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.util.MathArrays;
|
||||
import org.apache.commons.math4.util.Pair;
|
||||
|
@ -61,7 +60,7 @@ public class EnumeratedDistribution<T> implements Serializable {
|
|||
* RNG instance used to generate samples from the distribution.
|
||||
*/
|
||||
@Deprecated
|
||||
protected final RandomGenerator random;
|
||||
protected RandomGenerator random = null;
|
||||
|
||||
/**
|
||||
* List of random variable values.
|
||||
|
@ -81,45 +80,57 @@ public class EnumeratedDistribution<T> implements Serializable {
|
|||
private final double[] cumulativeProbabilities;
|
||||
|
||||
/**
|
||||
* Create an enumerated distribution using the given probability mass function
|
||||
* enumeration.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*
|
||||
* @param pmf probability mass function enumerated as a list of <T, probability>
|
||||
* pairs.
|
||||
* @throws NotPositiveException if any of the probabilities are negative.
|
||||
* @throws NotFiniteNumberException if any of the probabilities are infinite.
|
||||
* @throws NotANumberException if any of the probabilities are NaN.
|
||||
* @throws MathArithmeticException all of the probabilities are 0.
|
||||
* XXX TODO: remove once "EnumeratedIntegerDistribution" has been changed.
|
||||
*/
|
||||
public EnumeratedDistribution(final List<Pair<T, Double>> pmf)
|
||||
@Deprecated
|
||||
public EnumeratedDistribution(final RandomGenerator rng, final List<Pair<T, Double>> pmf)
|
||||
throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException {
|
||||
this(new Well19937c(), pmf);
|
||||
random = rng;
|
||||
singletons = new ArrayList<T>(pmf.size());
|
||||
final double[] probs = new double[pmf.size()];
|
||||
|
||||
for (int i = 0; i < pmf.size(); i++) {
|
||||
final Pair<T, Double> sample = pmf.get(i);
|
||||
singletons.add(sample.getKey());
|
||||
final double p = sample.getValue();
|
||||
if (p < 0) {
|
||||
throw new NotPositiveException(sample.getValue());
|
||||
}
|
||||
if (Double.isInfinite(p)) {
|
||||
throw new NotFiniteNumberException(p);
|
||||
}
|
||||
if (Double.isNaN(p)) {
|
||||
throw new NotANumberException();
|
||||
}
|
||||
probs[i] = p;
|
||||
}
|
||||
|
||||
probabilities = MathArrays.normalizeArray(probs, 1.0);
|
||||
|
||||
cumulativeProbabilities = new double[probabilities.length];
|
||||
double sum = 0;
|
||||
for (int i = 0; i < probabilities.length; i++) {
|
||||
sum += probabilities[i];
|
||||
cumulativeProbabilities[i] = sum;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an enumerated distribution using the given random number generator
|
||||
* and probability mass function enumeration.
|
||||
*
|
||||
* @param rng random number generator.
|
||||
* @param pmf probability mass function enumerated as a list of <T, probability>
|
||||
* pairs.
|
||||
* @param pmf probability mass function enumerated as a list of
|
||||
* {@code <T, probability>} pairs.
|
||||
* @throws NotPositiveException if any of the probabilities are negative.
|
||||
* @throws NotFiniteNumberException if any of the probabilities are infinite.
|
||||
* @throws NotANumberException if any of the probabilities are NaN.
|
||||
* @throws MathArithmeticException all of the probabilities are 0.
|
||||
*/
|
||||
@Deprecated
|
||||
public EnumeratedDistribution(final RandomGenerator rng, final List<Pair<T, Double>> pmf)
|
||||
throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException {
|
||||
random = rng;
|
||||
|
||||
public EnumeratedDistribution(final List<Pair<T, Double>> pmf)
|
||||
throws NotPositiveException,
|
||||
MathArithmeticException,
|
||||
NotFiniteNumberException,
|
||||
NotANumberException {
|
||||
singletons = new ArrayList<T>(pmf.size());
|
||||
final double[] probs = new double[pmf.size()];
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@ import org.apache.commons.math4.exception.NotANumberException;
|
|||
import org.apache.commons.math4.exception.NotFiniteNumberException;
|
||||
import org.apache.commons.math4.exception.NotPositiveException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.util.Pair;
|
||||
|
||||
|
@ -37,7 +35,7 @@ import org.apache.commons.math4.util.Pair;
|
|||
* <p>Implementation of a real-valued {@link EnumeratedDistribution}.
|
||||
*
|
||||
* <p>Values with zero-probability are allowed but they do not extend the
|
||||
* support.<br/>
|
||||
* support.<br>
|
||||
* Duplicate values are allowed. Probabilities of duplicate values are combined
|
||||
* when computing cumulative probabilities and statistics.</p>
|
||||
*
|
||||
|
@ -46,7 +44,7 @@ import org.apache.commons.math4.util.Pair;
|
|||
public class EnumeratedRealDistribution extends AbstractRealDistribution {
|
||||
|
||||
/** Serializable UID. */
|
||||
private static final long serialVersionUID = 20130308L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
|
||||
/**
|
||||
* {@link EnumeratedDistribution} (using the {@link Double} wrapper)
|
||||
|
@ -54,37 +52,10 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution {
|
|||
*/
|
||||
protected final EnumeratedDistribution<Double> innerDistribution;
|
||||
|
||||
/**
|
||||
* Create a discrete real-valued distribution using the given probability mass function
|
||||
* enumeration.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*
|
||||
* @param singletons array of random variable values.
|
||||
* @param probabilities array of probabilities.
|
||||
* @throws DimensionMismatchException if
|
||||
* {@code singletons.length != probabilities.length}
|
||||
* @throws NotPositiveException if any of the probabilities are negative.
|
||||
* @throws NotFiniteNumberException if any of the probabilities are infinite.
|
||||
* @throws NotANumberException if any of the probabilities are NaN.
|
||||
* @throws MathArithmeticException all of the probabilities are 0.
|
||||
*/
|
||||
public EnumeratedRealDistribution(final double[] singletons, final double[] probabilities)
|
||||
throws DimensionMismatchException, NotPositiveException, MathArithmeticException,
|
||||
NotFiniteNumberException, NotANumberException {
|
||||
this(new Well19937c(), singletons, probabilities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a discrete real-valued distribution using the given random number generator
|
||||
* and probability mass function enumeration.
|
||||
*
|
||||
* @param rng random number generator.
|
||||
* @param singletons array of random variable values.
|
||||
* @param probabilities array of probabilities.
|
||||
* @throws DimensionMismatchException if
|
||||
|
@ -94,28 +65,23 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution {
|
|||
* @throws NotANumberException if any of the probabilities are NaN.
|
||||
* @throws MathArithmeticException all of the probabilities are 0.
|
||||
*/
|
||||
@Deprecated
|
||||
public EnumeratedRealDistribution(final RandomGenerator rng,
|
||||
final double[] singletons, final double[] probabilities)
|
||||
throws DimensionMismatchException, NotPositiveException, MathArithmeticException,
|
||||
NotFiniteNumberException, NotANumberException {
|
||||
super(rng);
|
||||
|
||||
innerDistribution = new EnumeratedDistribution<Double>(
|
||||
rng, createDistribution(singletons, probabilities));
|
||||
public EnumeratedRealDistribution(final double[] singletons,
|
||||
final double[] probabilities)
|
||||
throws DimensionMismatchException,
|
||||
NotPositiveException,
|
||||
MathArithmeticException,
|
||||
NotFiniteNumberException,
|
||||
NotANumberException {
|
||||
innerDistribution = new EnumeratedDistribution<Double>(createDistribution(singletons, probabilities));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a discrete real-valued distribution from the input data. Values are assigned
|
||||
* mass based on their frequency.
|
||||
* Creates a discrete real-valued distribution from the input data.
|
||||
* Values are assigned mass based on their frequency.
|
||||
*
|
||||
* @param rng random number generator used for sampling
|
||||
* @param data input dataset
|
||||
* @since 3.6
|
||||
*/
|
||||
@Deprecated
|
||||
public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data) {
|
||||
super(rng);
|
||||
public EnumeratedRealDistribution(final double[] data) {
|
||||
final Map<Double, Integer> dataMap = new HashMap<Double, Integer>();
|
||||
for (double value : data) {
|
||||
Integer count = dataMap.get(value);
|
||||
|
@ -134,20 +100,9 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution {
|
|||
probabilities[index] = entry.getValue().intValue() / denom;
|
||||
index++;
|
||||
}
|
||||
innerDistribution = new EnumeratedDistribution<Double>(rng, createDistribution(values, probabilities));
|
||||
innerDistribution = new EnumeratedDistribution<Double>(createDistribution(values, probabilities));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a discrete real-valued distribution from the input data. Values are assigned
|
||||
* mass based on their frequency. For example, [0,1,1,2] as input creates a distribution
|
||||
* with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively,
|
||||
*
|
||||
* @param data input dataset
|
||||
* @since 3.6
|
||||
*/
|
||||
public EnumeratedRealDistribution(final double[] data) {
|
||||
this(new Well19937c(), data);
|
||||
}
|
||||
/**
|
||||
* Create the list of Pairs representing the distribution from singletons and probabilities.
|
||||
*
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.util.CombinatoricsUtils;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
@ -39,7 +37,7 @@ public class ExponentialDistribution extends AbstractRealDistribution {
|
|||
*/
|
||||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = 2401296428283614780L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/**
|
||||
* Used when generating Exponential samples.
|
||||
* Table containing the constants
|
||||
|
@ -91,14 +89,7 @@ public class ExponentialDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create an exponential distribution with the given mean.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mean mean of this distribution.
|
||||
*/
|
||||
|
@ -107,58 +98,19 @@ public class ExponentialDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create an exponential distribution with the given mean.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mean Mean of this distribution.
|
||||
* @param inverseCumAccuracy Maximum absolute error in inverse
|
||||
* cumulative probability estimates (defaults to
|
||||
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NotStrictlyPositiveException if {@code mean <= 0}.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public ExponentialDistribution(double mean, double inverseCumAccuracy) {
|
||||
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
|
||||
*/
|
||||
@Deprecated
|
||||
public ExponentialDistribution(RandomGenerator rng, double mean)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(rng, mean, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an exponential distribution.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param mean Mean of this distribution.
|
||||
* @param inverseCumAccuracy Maximum absolute error in inverse
|
||||
* cumulative probability estimates (defaults to
|
||||
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NotStrictlyPositiveException if {@code mean <= 0}.
|
||||
* @since 3.1
|
||||
*/
|
||||
@Deprecated
|
||||
public ExponentialDistribution(RandomGenerator rng,
|
||||
double mean,
|
||||
public ExponentialDistribution(double mean,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
super(rng);
|
||||
|
||||
if (mean <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.math4.distribution;
|
|||
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
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.special.Beta;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
|
@ -50,14 +48,7 @@ public class FDistribution extends AbstractRealDistribution {
|
|||
private boolean numericalVarianceIsCalculated = false;
|
||||
|
||||
/**
|
||||
* Creates an F distribution using the given degrees of freedom.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a using the given degrees of freedom.
|
||||
*
|
||||
* @param numeratorDegreesOfFreedom Numerator degrees of freedom.
|
||||
* @param denominatorDegreesOfFreedom Denominator degrees of freedom.
|
||||
|
@ -73,69 +64,19 @@ public class FDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates an F distribution using the given degrees of freedom
|
||||
* and inverse cumulative probability accuracy.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param numeratorDegreesOfFreedom Numerator degrees of freedom.
|
||||
* @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 2.1
|
||||
*/
|
||||
public FDistribution(double numeratorDegreesOfFreedom,
|
||||
double denominatorDegreesOfFreedom,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(new Well19937c(), numeratorDegreesOfFreedom,
|
||||
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.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param numeratorDegreesOfFreedom Numerator degrees of freedom.
|
||||
* @param denominatorDegreesOfFreedom Denominator degrees of freedom.
|
||||
* @param inverseCumAccuracy the maximum absolute error in inverse
|
||||
* cumulative probability estimates.
|
||||
* @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0} or
|
||||
* {@code denominatorDegreesOfFreedom <= 0}.
|
||||
* @since 3.1
|
||||
*/
|
||||
public FDistribution(RandomGenerator rng,
|
||||
double numeratorDegreesOfFreedom,
|
||||
double denominatorDegreesOfFreedom,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
super(rng);
|
||||
|
||||
if (numeratorDegreesOfFreedom <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
|
||||
numeratorDegreesOfFreedom);
|
||||
|
|
|
@ -18,8 +18,6 @@ package org.apache.commons.math4.distribution;
|
|||
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
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.Gamma;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
@ -37,7 +35,7 @@ public class GammaDistribution extends AbstractRealDistribution {
|
|||
*/
|
||||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20120524L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/** The shape parameter. */
|
||||
private final double shape;
|
||||
/** The scale parameter. */
|
||||
|
@ -99,35 +97,20 @@ public class GammaDistribution extends AbstractRealDistribution {
|
|||
private final double solverAbsoluteAccuracy;
|
||||
|
||||
/**
|
||||
* Creates a new gamma distribution with specified values of the shape and
|
||||
* scale parameters.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param shape the shape parameter
|
||||
* @param scale the scale parameter
|
||||
* @throws NotStrictlyPositiveException if {@code shape <= 0} or
|
||||
* {@code scale <= 0}.
|
||||
*/
|
||||
public GammaDistribution(double shape, double scale) throws NotStrictlyPositiveException {
|
||||
public GammaDistribution(double shape, double scale)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(shape, scale, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new gamma distribution with specified values of the shape and
|
||||
* scale parameters.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param shape the shape parameter
|
||||
* @param scale the scale parameter
|
||||
|
@ -136,50 +119,11 @@ public class GammaDistribution extends AbstractRealDistribution {
|
|||
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NotStrictlyPositiveException if {@code shape <= 0} or
|
||||
* {@code scale <= 0}.
|
||||
* @since 2.1
|
||||
*/
|
||||
public GammaDistribution(double shape, double scale, double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
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
|
||||
*/
|
||||
@Deprecated
|
||||
public GammaDistribution(RandomGenerator rng, double shape, double scale)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(rng, shape, scale, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Gamma distribution.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param shape the shape parameter
|
||||
* @param scale the scale parameter
|
||||
* @param inverseCumAccuracy the maximum absolute error in inverse
|
||||
* cumulative probability estimates (defaults to
|
||||
* {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NotStrictlyPositiveException if {@code shape <= 0} or
|
||||
* {@code scale <= 0}.
|
||||
* @since 3.1
|
||||
*/
|
||||
@Deprecated
|
||||
public GammaDistribution(RandomGenerator rng,
|
||||
double shape,
|
||||
public GammaDistribution(double shape,
|
||||
double scale,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
super(rng);
|
||||
|
||||
if (shape <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathUtils;
|
||||
|
||||
|
@ -35,7 +33,7 @@ import org.apache.commons.math4.util.MathUtils;
|
|||
public class GumbelDistribution extends AbstractRealDistribution {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20141003;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
|
||||
/**
|
||||
* Approximation of Euler's constant
|
||||
|
@ -49,34 +47,13 @@ public class GumbelDistribution extends AbstractRealDistribution {
|
|||
private final double beta;
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mu location parameter
|
||||
* @param beta scale parameter (must be positive)
|
||||
* @throws NotStrictlyPositiveException if {@code beta <= 0}
|
||||
*/
|
||||
public GumbelDistribution(double mu, double beta) {
|
||||
this(new Well19937c(), mu, beta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
*
|
||||
* @param rng Random number generator
|
||||
* @param mu location parameter
|
||||
* @param beta scale parameter (must be positive)
|
||||
* @throws NotStrictlyPositiveException if {@code beta <= 0}
|
||||
*/
|
||||
public GumbelDistribution(RandomGenerator rng, double mu, double beta) {
|
||||
super(rng);
|
||||
|
||||
if (beta <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, beta);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.util.FastMath;
|
||||
|
||||
/**
|
||||
|
@ -33,7 +31,7 @@ import org.apache.commons.math4.util.FastMath;
|
|||
public class LaplaceDistribution extends AbstractRealDistribution {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20141003;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
|
||||
/** The location parameter. */
|
||||
private final double mu;
|
||||
|
@ -41,34 +39,13 @@ public class LaplaceDistribution extends AbstractRealDistribution {
|
|||
private final double beta;
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mu location parameter
|
||||
* @param beta scale parameter (must be positive)
|
||||
* @throws NotStrictlyPositiveException if {@code beta <= 0}
|
||||
*/
|
||||
public LaplaceDistribution(double mu, double beta) {
|
||||
this(new Well19937c(), mu, beta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
*
|
||||
* @param rng Random number generator
|
||||
* @param mu location parameter
|
||||
* @param beta scale parameter (must be positive)
|
||||
* @throws NotStrictlyPositiveException if {@code beta <= 0}
|
||||
*/
|
||||
public LaplaceDistribution(RandomGenerator rng, double mu, double beta) {
|
||||
super(rng);
|
||||
|
||||
if (beta <= 0.0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.NOT_POSITIVE_SCALE, beta);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
package org.apache.commons.math4.distribution;
|
||||
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well19937c;
|
||||
import org.apache.commons.math4.special.Erf;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
|
@ -31,7 +29,7 @@ import org.apache.commons.math4.util.FastMath;
|
|||
public class LevyDistribution extends AbstractRealDistribution {
|
||||
|
||||
/** Serializable UID. */
|
||||
private static final long serialVersionUID = 20130314L;
|
||||
private static final long serialVersionUID = 20630311L;
|
||||
|
||||
/** Location parameter. */
|
||||
private final double mu;
|
||||
|
@ -43,31 +41,12 @@ public class LevyDistribution extends AbstractRealDistribution {
|
|||
private final double halfC;
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mu location parameter
|
||||
* @param c scale parameter
|
||||
* @since 3.4
|
||||
*/
|
||||
public LevyDistribution(final double mu, final double c) {
|
||||
this(new Well19937c(), mu, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a LevyDistribution.
|
||||
* @param rng random generator to be used for sampling
|
||||
* @param mu location
|
||||
* @param c scale parameter
|
||||
*/
|
||||
public LevyDistribution(final RandomGenerator rng, final double mu, final double c) {
|
||||
super(rng);
|
||||
public LevyDistribution(final double mu, final double c) {
|
||||
this.mu = mu;
|
||||
this.c = c;
|
||||
this.halfC = 0.5 * c;
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
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;
|
||||
|
@ -78,35 +76,21 @@ public class LogNormalDistribution extends AbstractRealDistribution {
|
|||
private final double solverAbsoluteAccuracy;
|
||||
|
||||
/**
|
||||
* Create a log-normal distribution, where the mean and standard deviation
|
||||
* Creates a log-normal distribution, where the mean and standard deviation
|
||||
* of the {@link NormalDistribution normally distributed} natural
|
||||
* logarithm of the log-normal distribution are equal to zero and one
|
||||
* respectively. In other words, the scale of the returned distribution is
|
||||
* {@code 0}, while its shape is {@code 1}.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*/
|
||||
public LogNormalDistribution() {
|
||||
this(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a log-normal distribution using the specified scale and shape.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a log-normal distribution.
|
||||
*
|
||||
* @param scale the scale parameter of this distribution
|
||||
* @param shape the shape parameter of this distribution
|
||||
* @param scale Scale parameter of this distribution.
|
||||
* @param shape Shape parameter of this distribution.
|
||||
* @throws NotStrictlyPositiveException if {@code shape <= 0}.
|
||||
*/
|
||||
public LogNormalDistribution(double scale, double shape)
|
||||
|
@ -114,60 +98,18 @@ public class LogNormalDistribution extends AbstractRealDistribution {
|
|||
this(scale, shape, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a log-normal distribution using the specified scale, shape and
|
||||
* inverse cumulative distribution accuracy.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*
|
||||
* @param scale the scale parameter of this distribution
|
||||
* @param shape the shape parameter of this distribution
|
||||
* @param inverseCumAccuracy Inverse cumulative probability accuracy.
|
||||
* @throws NotStrictlyPositiveException if {@code shape <= 0}.
|
||||
*/
|
||||
public LogNormalDistribution(double scale, double shape, double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
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
|
||||
*/
|
||||
@Deprecated
|
||||
public LogNormalDistribution(RandomGenerator rng, double scale, double shape)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(rng, scale, shape, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a log-normal distribution.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param scale Scale parameter of this distribution.
|
||||
* @param shape Shape parameter of this distribution.
|
||||
* @param inverseCumAccuracy Inverse cumulative probability accuracy.
|
||||
* @throws NotStrictlyPositiveException if {@code shape <= 0}.
|
||||
* @since 3.1
|
||||
*/
|
||||
@Deprecated
|
||||
public LogNormalDistribution(RandomGenerator rng,
|
||||
double scale,
|
||||
public LogNormalDistribution(double scale,
|
||||
double shape,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
super(rng);
|
||||
|
||||
if (shape <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathUtils;
|
||||
|
||||
|
@ -35,7 +33,7 @@ import org.apache.commons.math4.util.MathUtils;
|
|||
public class LogisticDistribution extends AbstractRealDistribution {
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20141003;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
|
||||
/** The location parameter. */
|
||||
private final double mu;
|
||||
|
@ -43,34 +41,14 @@ public class LogisticDistribution extends AbstractRealDistribution {
|
|||
private final double s;
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mu location parameter
|
||||
* @param s scale parameter (must be positive)
|
||||
* @throws NotStrictlyPositiveException if {@code beta <= 0}
|
||||
*/
|
||||
public LogisticDistribution(double mu, double s) {
|
||||
this(new Well19937c(), mu, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
*
|
||||
* @param rng Random number generator
|
||||
* @param mu location parameter
|
||||
* @param s scale parameter (must be positive)
|
||||
* @throws NotStrictlyPositiveException if {@code beta <= 0}
|
||||
*/
|
||||
public LogisticDistribution(RandomGenerator rng, double mu, double s) {
|
||||
super(rng);
|
||||
|
||||
public LogisticDistribution(double mu,
|
||||
double s) {
|
||||
if (s <= 0.0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.NOT_POSITIVE_SCALE, s);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.exception.NumberIsTooSmallException;
|
||||
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.special.Gamma;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
|
@ -37,7 +35,7 @@ public class NakagamiDistribution extends AbstractRealDistribution {
|
|||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20141003;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
|
||||
/** The shape parameter. */
|
||||
private final double mu;
|
||||
|
@ -47,33 +45,20 @@ public class NakagamiDistribution extends AbstractRealDistribution {
|
|||
private final double inverseAbsoluteAccuracy;
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mu shape parameter
|
||||
* @param omega scale parameter (must be positive)
|
||||
* @throws NumberIsTooSmallException if {@code mu < 0.5}
|
||||
* @throws NotStrictlyPositiveException if {@code omega <= 0}
|
||||
*/
|
||||
public NakagamiDistribution(double mu, double omega) {
|
||||
public NakagamiDistribution(double mu,
|
||||
double omega) {
|
||||
this(mu, omega, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mu shape parameter
|
||||
* @param omega scale parameter (must be positive)
|
||||
|
@ -82,24 +67,9 @@ public class NakagamiDistribution extends AbstractRealDistribution {
|
|||
* @throws NumberIsTooSmallException if {@code mu < 0.5}
|
||||
* @throws NotStrictlyPositiveException if {@code omega <= 0}
|
||||
*/
|
||||
public NakagamiDistribution(double mu, double omega, double inverseAbsoluteAccuracy) {
|
||||
this(new Well19937c(), mu, omega, inverseAbsoluteAccuracy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new instance.
|
||||
*
|
||||
* @param rng Random number generator
|
||||
* @param mu shape parameter
|
||||
* @param omega scale parameter (must be positive)
|
||||
* @param inverseAbsoluteAccuracy the maximum absolute error in inverse
|
||||
* cumulative probability estimates (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NumberIsTooSmallException if {@code mu < 0.5}
|
||||
* @throws NotStrictlyPositiveException if {@code omega <= 0}
|
||||
*/
|
||||
public NakagamiDistribution(RandomGenerator rng, double mu, double omega, double inverseAbsoluteAccuracy) {
|
||||
super(rng);
|
||||
|
||||
public NakagamiDistribution(double mu,
|
||||
double omega,
|
||||
double inverseAbsoluteAccuracy) {
|
||||
if (mu < 0.5) {
|
||||
throw new NumberIsTooSmallException(mu, 0.5, true);
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
|||
import org.apache.commons.math4.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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;
|
||||
|
@ -55,92 +53,37 @@ public class NormalDistribution extends AbstractRealDistribution {
|
|||
/**
|
||||
* Create a normal distribution with mean equal to zero and standard
|
||||
* deviation equal to one.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*/
|
||||
public NormalDistribution() {
|
||||
this(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a normal distribution using the given mean and standard deviation.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mean Mean for this distribution.
|
||||
* @param sd Standard deviation for this distribution.
|
||||
* @throws NotStrictlyPositiveException if {@code sd <= 0}.
|
||||
*/
|
||||
public NormalDistribution(double mean, double sd)
|
||||
public NormalDistribution(double mean,
|
||||
double sd)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(mean, sd, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a normal distribution using the given mean, standard deviation and
|
||||
* inverse cumulative distribution accuracy.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param mean Mean for this distribution.
|
||||
* @param sd Standard deviation for this distribution.
|
||||
* @param inverseCumAccuracy Inverse cumulative probability accuracy.
|
||||
* @throws NotStrictlyPositiveException if {@code sd <= 0}.
|
||||
* @since 2.1
|
||||
*/
|
||||
public NormalDistribution(double mean, double sd, double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
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
|
||||
*/
|
||||
@Deprecated
|
||||
public NormalDistribution(RandomGenerator rng, double mean, double sd)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(rng, mean, sd, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a normal distribution.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param mean Mean for this distribution.
|
||||
* @param sd Standard deviation for this distribution.
|
||||
* @param inverseCumAccuracy Inverse cumulative probability accuracy.
|
||||
* @throws NotStrictlyPositiveException if {@code sd <= 0}.
|
||||
* @since 3.1
|
||||
*/
|
||||
@Deprecated
|
||||
public NormalDistribution(RandomGenerator rng,
|
||||
double mean,
|
||||
public NormalDistribution(double mean,
|
||||
double sd,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
super(rng);
|
||||
|
||||
if (sd <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.STANDARD_DEVIATION, sd);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.commons.math4.distribution;
|
|||
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
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.util.FastMath;
|
||||
|
||||
|
@ -52,7 +50,7 @@ public class ParetoDistribution extends AbstractRealDistribution {
|
|||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20130424;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
|
||||
/** The scale parameter of this distribution. */
|
||||
private final double scale;
|
||||
|
@ -64,83 +62,37 @@ public class ParetoDistribution extends AbstractRealDistribution {
|
|||
private final double solverAbsoluteAccuracy;
|
||||
|
||||
/**
|
||||
* Create a Pareto distribution with a scale of {@code 1} and a shape of {@code 1}.
|
||||
* Creates a Pareto distribution with a scale of {@code 1} and a shape of {@code 1}.
|
||||
*/
|
||||
public ParetoDistribution() {
|
||||
this(1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Pareto distribution using the specified scale and shape.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a Pareto distribution.
|
||||
*
|
||||
* @param scale the scale parameter of this distribution
|
||||
* @param shape the shape parameter of this distribution
|
||||
* @throws NotStrictlyPositiveException if {@code scale <= 0} or {@code shape <= 0}.
|
||||
*/
|
||||
public ParetoDistribution(double scale, double shape)
|
||||
public ParetoDistribution(double scale,
|
||||
double shape)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(scale, shape, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Pareto distribution using the specified scale, shape and
|
||||
* inverse cumulative distribution accuracy.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*
|
||||
* @param scale the scale parameter of this distribution
|
||||
* @param shape the shape parameter of this distribution
|
||||
* @param inverseCumAccuracy Inverse cumulative probability accuracy.
|
||||
* @throws NotStrictlyPositiveException if {@code scale <= 0} or {@code shape <= 0}.
|
||||
*/
|
||||
public ParetoDistribution(double scale, double shape, double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(new Well19937c(), scale, shape, inverseCumAccuracy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Pareto 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}.
|
||||
*/
|
||||
@Deprecated
|
||||
public ParetoDistribution(RandomGenerator rng, double scale, double shape)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(rng, scale, shape, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Pareto distribution.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param scale Scale parameter of this distribution.
|
||||
* @param shape Shape parameter of this distribution.
|
||||
* @param inverseCumAccuracy Inverse cumulative probability accuracy.
|
||||
* @throws NotStrictlyPositiveException if {@code scale <= 0} or {@code shape <= 0}.
|
||||
*/
|
||||
@Deprecated
|
||||
public ParetoDistribution(RandomGenerator rng,
|
||||
double scale,
|
||||
public ParetoDistribution(double scale,
|
||||
double shape,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
super(rng);
|
||||
|
||||
if (scale <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.commons.math4.special.Gamma;
|
|||
import org.apache.commons.math4.util.CombinatoricsUtils;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathUtils;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
|
||||
/**
|
||||
* Implementation of the Poisson distribution.
|
||||
|
@ -47,7 +48,7 @@ public class PoissonDistribution extends AbstractIntegerDistribution {
|
|||
/** Distribution used to compute normal approximation. */
|
||||
private final NormalDistribution normal;
|
||||
/** Distribution needed for the {@link #sample()} method. */
|
||||
private final ExponentialDistribution exponential;
|
||||
private final RealDistribution.Sampler exponentialSampler;
|
||||
/** Mean of the distribution. */
|
||||
private final double mean;
|
||||
|
||||
|
@ -130,10 +131,11 @@ public class PoissonDistribution extends AbstractIntegerDistribution {
|
|||
this.maxIterations = maxIterations;
|
||||
|
||||
// Use the same RNG instance as the parent class.
|
||||
normal = new NormalDistribution(rng, p, FastMath.sqrt(p),
|
||||
normal = new NormalDistribution(p, FastMath.sqrt(p),
|
||||
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
exponential = new ExponentialDistribution(rng, 1,
|
||||
ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
|
||||
// XXX TODO: RNG source should not be hard-coded.
|
||||
exponentialSampler = new ExponentialDistribution(1).createSampler(RandomSource.create(RandomSource.WELL_19937_C));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,16 +366,16 @@ public class PoissonDistribution extends AbstractIntegerDistribution {
|
|||
continue;
|
||||
}
|
||||
y = x < 0 ? FastMath.floor(x) : FastMath.ceil(x);
|
||||
final double e = exponential.sample();
|
||||
final double e = exponentialSampler.sample();
|
||||
v = -e - (n * n / 2) + c1;
|
||||
} else {
|
||||
if (u > p1 + p2) {
|
||||
y = lambda;
|
||||
break;
|
||||
} else {
|
||||
x = delta + (twolpd / delta) * exponential.sample();
|
||||
x = delta + (twolpd / delta) * exponentialSampler.sample();
|
||||
y = FastMath.ceil(x);
|
||||
v = -exponential.sample() - delta * (x + 1) / twolpd;
|
||||
v = -exponentialSampler.sample() - delta * (x + 1) / twolpd;
|
||||
}
|
||||
}
|
||||
a = x < 0 ? 1 : 0;
|
||||
|
|
|
@ -18,8 +18,6 @@ package org.apache.commons.math4.distribution;
|
|||
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
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.special.Beta;
|
||||
import org.apache.commons.math4.special.Gamma;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
@ -37,7 +35,7 @@ public class TDistribution extends AbstractRealDistribution {
|
|||
*/
|
||||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = -5852615386664158222L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/** The degrees of freedom. */
|
||||
private final double degreesOfFreedom;
|
||||
/** Inverse cumulative probability accuracy. */
|
||||
|
@ -46,14 +44,7 @@ public class TDistribution extends AbstractRealDistribution {
|
|||
private final double factor;
|
||||
|
||||
/**
|
||||
* Create a t distribution using the given degrees of freedom.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param degreesOfFreedom Degrees of freedom.
|
||||
* @throws NotStrictlyPositiveException if {@code degreesOfFreedom <= 0}
|
||||
|
@ -64,58 +55,17 @@ public class TDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a t distribution using the given degrees of freedom and the
|
||||
* specified inverse cumulative probability absolute accuracy.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param degreesOfFreedom Degrees of freedom.
|
||||
* @param inverseCumAccuracy the maximum absolute error in inverse
|
||||
* cumulative probability estimates
|
||||
* (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NotStrictlyPositiveException if {@code degreesOfFreedom <= 0}
|
||||
* @since 2.1
|
||||
*/
|
||||
public TDistribution(double degreesOfFreedom, double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
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.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param degreesOfFreedom Degrees of freedom.
|
||||
* @param inverseCumAccuracy the maximum absolute error in inverse
|
||||
* cumulative probability estimates
|
||||
* (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
|
||||
* @throws NotStrictlyPositiveException if {@code degreesOfFreedom <= 0}
|
||||
* @since 3.1
|
||||
*/
|
||||
public TDistribution(RandomGenerator rng,
|
||||
double degreesOfFreedom,
|
||||
public TDistribution(double degreesOfFreedom,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
super(rng);
|
||||
|
||||
if (degreesOfFreedom <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM,
|
||||
degreesOfFreedom);
|
||||
|
|
|
@ -21,8 +21,6 @@ import org.apache.commons.math4.exception.NumberIsTooLargeException;
|
|||
import org.apache.commons.math4.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.util.FastMath;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +33,7 @@ import org.apache.commons.math4.util.FastMath;
|
|||
*/
|
||||
public class TriangularDistribution extends AbstractRealDistribution {
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20120112L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/** Lower limit of this distribution (inclusive). */
|
||||
private final double a;
|
||||
/** Upper limit of this distribution (inclusive). */
|
||||
|
@ -46,45 +44,20 @@ public class TriangularDistribution extends AbstractRealDistribution {
|
|||
private final double solverAbsoluteAccuracy;
|
||||
|
||||
/**
|
||||
* Creates a triangular real distribution using the given lower limit,
|
||||
* upper limit, and mode.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param a Lower limit of this distribution (inclusive).
|
||||
* @param b Upper limit of this distribution (inclusive).
|
||||
* @param c Mode of this distribution.
|
||||
* @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
|
||||
* @throws NumberIsTooSmallException if {@code c < a}.
|
||||
*/
|
||||
public TriangularDistribution(double a, double c, double b)
|
||||
throws NumberIsTooLargeException, NumberIsTooSmallException {
|
||||
this(new Well19937c(), a, c, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a triangular distribution.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param a Lower limit of this distribution (inclusive).
|
||||
* @param b Upper limit of this distribution (inclusive).
|
||||
* @param c Mode of this distribution.
|
||||
* @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
|
||||
* @throws NumberIsTooSmallException if {@code c < a}.
|
||||
* @since 3.1
|
||||
*/
|
||||
public TriangularDistribution(RandomGenerator rng,
|
||||
double a,
|
||||
public TriangularDistribution(double a,
|
||||
double c,
|
||||
double b)
|
||||
throws NumberIsTooLargeException, NumberIsTooSmallException {
|
||||
super(rng);
|
||||
|
||||
throws NumberIsTooLargeException,
|
||||
NumberIsTooSmallException {
|
||||
if (a >= b) {
|
||||
throw new NumberIsTooLargeException(
|
||||
LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -34,7 +32,7 @@ import org.apache.commons.math4.rng.UniformRandomProvider;
|
|||
*/
|
||||
public class UniformRealDistribution extends AbstractRealDistribution {
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 20120109L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/** Lower bound of this distribution (inclusive). */
|
||||
private final double lower;
|
||||
/** Upper bound of this distribution (exclusive). */
|
||||
|
@ -43,53 +41,21 @@ public class UniformRealDistribution extends AbstractRealDistribution {
|
|||
/**
|
||||
* Create a standard uniform real distribution with lower bound (inclusive)
|
||||
* equal to zero and upper bound (exclusive) equal to one.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*/
|
||||
public UniformRealDistribution() {
|
||||
this(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a uniform real distribution using the given lower and upper
|
||||
* bounds.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
*
|
||||
* @param lower Lower bound of this distribution (inclusive).
|
||||
* @param upper Upper bound of this distribution (exclusive).
|
||||
* @throws NumberIsTooLargeException if {@code lower >= upper}.
|
||||
*/
|
||||
public UniformRealDistribution(double lower, double upper)
|
||||
throws NumberIsTooLargeException {
|
||||
this(new Well19937c(), lower, upper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a uniform distribution.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param lower Lower bound of this distribution (inclusive).
|
||||
* @param upper Upper bound of this distribution (exclusive).
|
||||
* @throws NumberIsTooLargeException if {@code lower >= upper}.
|
||||
* @since 3.1
|
||||
*/
|
||||
@Deprecated
|
||||
public UniformRealDistribution(RandomGenerator rng,
|
||||
double lower,
|
||||
public UniformRealDistribution(double lower,
|
||||
double upper)
|
||||
throws NumberIsTooLargeException {
|
||||
super(rng);
|
||||
if (lower >= upper) {
|
||||
throw new NumberIsTooLargeException(
|
||||
LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
|
||||
|
@ -207,7 +173,7 @@ public class UniformRealDistribution extends AbstractRealDistribution {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double sample() {
|
||||
final double u = random.nextDouble();
|
||||
final double u = rng.nextDouble();
|
||||
return u * upper + (1 - u) * lower;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -20,8 +20,6 @@ package org.apache.commons.math4.distribution;
|
|||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.special.Gamma;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
|
@ -33,7 +31,8 @@ import org.apache.commons.math4.util.FastMath;
|
|||
*
|
||||
* @see <a href="http://en.wikipedia.org/wiki/Weibull_distribution">Weibull distribution (Wikipedia)</a>
|
||||
* @see <a href="http://mathworld.wolfram.com/WeibullDistribution.html">Weibull distribution (MathWorld)</a>
|
||||
* @since 1.1 (changed to concrete class in 3.0)
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public class WeibullDistribution extends AbstractRealDistribution {
|
||||
/**
|
||||
|
@ -42,7 +41,7 @@ public class WeibullDistribution extends AbstractRealDistribution {
|
|||
*/
|
||||
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = 8589540077390120676L;
|
||||
private static final long serialVersionUID = 20160311L;
|
||||
/** The shape parameter. */
|
||||
private final double shape;
|
||||
/** The scale parameter. */
|
||||
|
@ -59,15 +58,7 @@ public class WeibullDistribution extends AbstractRealDistribution {
|
|||
private boolean numericalVarianceIsCalculated = false;
|
||||
|
||||
/**
|
||||
* Create a Weibull distribution with the given shape and scale and a
|
||||
* location equal to zero.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param alpha Shape parameter.
|
||||
* @param beta Scale parameter.
|
||||
|
@ -80,63 +71,19 @@ public class WeibullDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a Weibull distribution with the given shape, scale and inverse
|
||||
* cumulative probability accuracy and a location equal to zero.
|
||||
* <p>
|
||||
* <b>Note:</b> this constructor will implicitly create an instance of
|
||||
* {@link Well19937c} as random generator to be used for sampling only (see
|
||||
* {@link #sample()} and {@link #sample(int)}). In case no sampling is
|
||||
* needed for the created distribution, it is advised to pass {@code null}
|
||||
* as random generator via the appropriate constructors to avoid the
|
||||
* additional initialisation overhead.
|
||||
* Creates a distribution.
|
||||
*
|
||||
* @param alpha Shape parameter.
|
||||
* @param beta Scale parameter.
|
||||
* @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}.
|
||||
* @since 2.1
|
||||
*/
|
||||
public WeibullDistribution(double alpha, double beta,
|
||||
double inverseCumAccuracy) {
|
||||
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.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @param alpha Shape parameter.
|
||||
* @param beta Scale parameter.
|
||||
* @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}.
|
||||
* @since 3.1
|
||||
*/
|
||||
public WeibullDistribution(RandomGenerator rng,
|
||||
double alpha,
|
||||
public WeibullDistribution(double alpha,
|
||||
double beta,
|
||||
double inverseCumAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
super(rng);
|
||||
|
||||
if (alpha <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE,
|
||||
alpha);
|
||||
|
|
|
@ -41,6 +41,8 @@ import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
|||
import org.apache.commons.math4.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math4.stat.descriptive.StatisticalSummary;
|
||||
import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathUtils;
|
||||
|
||||
|
@ -112,6 +114,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
private static final long serialVersionUID = 5729073523949762654L;
|
||||
|
||||
/** RandomDataGenerator instance to use in repeated calls to getNext() */
|
||||
@Deprecated
|
||||
protected final RandomDataGenerator randomData;
|
||||
|
||||
/** List of SummaryStatistics objects characterizing the bins */
|
||||
|
@ -152,7 +155,12 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
* @throws NotStrictlyPositiveException if {@code binCount <= 0}.
|
||||
*/
|
||||
public EmpiricalDistribution(int binCount) {
|
||||
this(binCount, new RandomDataGenerator());
|
||||
if (binCount <= 0) {
|
||||
throw new NotStrictlyPositiveException(binCount);
|
||||
}
|
||||
this.binCount = binCount;
|
||||
binStats = new ArrayList<SummaryStatistics>();
|
||||
randomData = null; // XXX remove
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -164,6 +172,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
* @throws NotStrictlyPositiveException if {@code binCount <= 0}.
|
||||
* @since 3.0
|
||||
*/
|
||||
@Deprecated
|
||||
public EmpiricalDistribution(int binCount, RandomGenerator generator) {
|
||||
this(binCount, new RandomDataGenerator(generator));
|
||||
}
|
||||
|
@ -175,6 +184,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
* @param generator random data generator (may be null, resulting in default JDK generator)
|
||||
* @since 3.0
|
||||
*/
|
||||
@Deprecated
|
||||
public EmpiricalDistribution(RandomGenerator generator) {
|
||||
this(DEFAULT_BIN_COUNT, generator);
|
||||
}
|
||||
|
@ -187,9 +197,9 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
* @param randomData Random data generator.
|
||||
* @throws NotStrictlyPositiveException if {@code binCount <= 0}.
|
||||
*/
|
||||
@Deprecated
|
||||
private EmpiricalDistribution(int binCount,
|
||||
RandomDataGenerator randomData) {
|
||||
super(randomData.getRandomGenerator());
|
||||
if (binCount <= 0) {
|
||||
throw new NotStrictlyPositiveException(binCount);
|
||||
}
|
||||
|
@ -452,12 +462,11 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
* @return the random value.
|
||||
* @throws MathIllegalStateException if the distribution has not been loaded
|
||||
*/
|
||||
@Deprecated
|
||||
public double getNextValue() throws MathIllegalStateException {
|
||||
|
||||
if (!loaded) {
|
||||
throw new MathIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED);
|
||||
}
|
||||
|
||||
return sample();
|
||||
}
|
||||
|
||||
|
@ -552,7 +561,9 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
*
|
||||
* @param seed random generator seed
|
||||
* @since 3.0
|
||||
* XXX REMOVE
|
||||
*/
|
||||
@Deprecated
|
||||
public void reSeed(long seed) {
|
||||
randomData.reSeed(seed);
|
||||
}
|
||||
|
@ -736,10 +747,20 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
* @since 3.1
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void reseedRandomGenerator(long seed) {
|
||||
randomData.reSeed(seed);
|
||||
}
|
||||
|
||||
/**{@inheritDoc} */
|
||||
@Override
|
||||
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
|
||||
if (!loaded) {
|
||||
throw new MathIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED);
|
||||
}
|
||||
return super.createSampler(rng);
|
||||
}
|
||||
|
||||
/**
|
||||
* The probability of bin i.
|
||||
*
|
||||
|
@ -808,8 +829,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
if (bStats.getN() == 1 || bStats.getVariance() == 0) {
|
||||
return new ConstantRealDistribution(bStats.getMean());
|
||||
} else {
|
||||
return new NormalDistribution(randomData.getRandomGenerator(),
|
||||
bStats.getMean(), bStats.getStandardDeviation(),
|
||||
return new NormalDistribution(bStats.getMean(), bStats.getStandardDeviation(),
|
||||
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
package org.apache.commons.math4.random;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
|
@ -46,6 +49,8 @@ import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
|||
import org.apache.commons.math4.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
import org.apache.commons.math4.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.util.MathArrays;
|
||||
|
||||
/**
|
||||
|
@ -115,8 +120,14 @@ public class RandomDataGenerator implements Serializable {
|
|||
private static final long serialVersionUID = -626730818244969716L;
|
||||
|
||||
/** underlying random number generator */
|
||||
@Deprecated
|
||||
private RandomGenerator rand = null;
|
||||
|
||||
/** Underlying random number generator. */
|
||||
private transient UniformRandomProvider randomProvider = null;
|
||||
/** Underlying source of randomness. */
|
||||
private final RandomSource randomSource;
|
||||
|
||||
/** underlying secure random number generator */
|
||||
private RandomGenerator secRand = null;
|
||||
|
||||
|
@ -129,6 +140,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* The generator is initialized and seeded on first use.</p>
|
||||
*/
|
||||
public RandomDataGenerator() {
|
||||
randomSource = RandomSource.WELL_19937_C;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,8 +150,20 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @param rand the source of (non-secure) random data
|
||||
* (may be null, resulting in the default generator)
|
||||
*/
|
||||
@Deprecated
|
||||
public RandomDataGenerator(RandomGenerator rand) {
|
||||
this.rand = rand;
|
||||
randomSource = RandomSource.WELL_19937_C;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*
|
||||
* @param source Source of (non-secure) random data.
|
||||
* If {@code null}, {@link RandomSource#WELL_19937_C} will be used.
|
||||
*/
|
||||
public RandomDataGenerator(RandomSource source) {
|
||||
randomSource = source == null ? RandomSource.WELL_19937_C : source;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -491,8 +515,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @throws NotStrictlyPositiveException if {@code mean <= 0}.
|
||||
*/
|
||||
public double nextExponential(double mean) throws NotStrictlyPositiveException {
|
||||
return new ExponentialDistribution(getRandomGenerator(), mean,
|
||||
ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
|
||||
return new ExponentialDistribution(mean, ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).createSampler(getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -518,8 +541,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* {@code scale <= 0}.
|
||||
*/
|
||||
public double nextGamma(double shape, double scale) throws NotStrictlyPositiveException {
|
||||
return new GammaDistribution(getRandomGenerator(),shape, scale,
|
||||
GammaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
|
||||
return new GammaDistribution(shape, scale, GammaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).createSampler(getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -535,8 +557,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @throws NotPositiveException if {@code numberOfSuccesses < 0}.
|
||||
*/
|
||||
public int nextHypergeometric(int populationSize, int numberOfSuccesses, int sampleSize) throws NotPositiveException, NotStrictlyPositiveException, NumberIsTooLargeException {
|
||||
return new HypergeometricDistribution(getRandomGenerator(),populationSize,
|
||||
numberOfSuccesses, sampleSize).sample();
|
||||
return new HypergeometricDistribution(getRandomGenerator(), populationSize, numberOfSuccesses, sampleSize).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -561,8 +582,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @throws NotStrictlyPositiveException if {@code df <= 0}
|
||||
*/
|
||||
public double nextT(double df) throws NotStrictlyPositiveException {
|
||||
return new TDistribution(getRandomGenerator(), df,
|
||||
TDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
|
||||
return new TDistribution(df, TDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).createSampler(getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -575,8 +595,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* {@code scale <= 0}.
|
||||
*/
|
||||
public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException {
|
||||
return new WeibullDistribution(getRandomGenerator(), shape, scale,
|
||||
WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
|
||||
return new WeibullDistribution(shape, scale, WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).createSampler(getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -600,8 +619,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @return random value sampled from the beta(alpha, beta) distribution
|
||||
*/
|
||||
public double nextBeta(double alpha, double beta) {
|
||||
return new BetaDistribution(getRandomGenerator(), alpha, beta,
|
||||
BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
|
||||
return new BetaDistribution(alpha, beta, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).createSampler(getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -623,8 +641,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @return random value sampled from the Cauchy(median, scale) distribution
|
||||
*/
|
||||
public double nextCauchy(double median, double scale) {
|
||||
return new CauchyDistribution(getRandomGenerator(), median, scale,
|
||||
CauchyDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
|
||||
return new CauchyDistribution(median, scale, CauchyDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).createSampler(getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -634,8 +651,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @return random value sampled from the ChiSquare(df) distribution
|
||||
*/
|
||||
public double nextChiSquare(double df) {
|
||||
return new ChiSquaredDistribution(getRandomGenerator(), df,
|
||||
ChiSquaredDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
|
||||
return new ChiSquaredDistribution(df, ChiSquaredDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).createSampler(getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -648,8 +664,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* {@code numeratorDf <= 0} or {@code denominatorDf <= 0}.
|
||||
*/
|
||||
public double nextF(double numeratorDf, double denominatorDf) throws NotStrictlyPositiveException {
|
||||
return new FDistribution(getRandomGenerator(), numeratorDf, denominatorDf,
|
||||
FDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
|
||||
return new FDistribution(numeratorDf, denominatorDf, FDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).createSampler(getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -830,6 +845,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @param seed the seed value to use
|
||||
*/
|
||||
public void reSeed(long seed) {
|
||||
randomProvider = RandomSource.create(randomSource, seed);
|
||||
getRandomGenerator().setSeed(seed);
|
||||
}
|
||||
|
||||
|
@ -861,7 +877,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* {@code System.currentTimeMillis() + System.identityHashCode(this))}.
|
||||
*/
|
||||
public void reSeed() {
|
||||
getRandomGenerator().setSeed(System.currentTimeMillis() + System.identityHashCode(this));
|
||||
reSeed(System.currentTimeMillis() + System.identityHashCode(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -896,6 +912,7 @@ public class RandomDataGenerator implements Serializable {
|
|||
* @return the Random used to generate random data
|
||||
* @since 3.2
|
||||
*/
|
||||
@Deprecated
|
||||
public RandomGenerator getRandomGenerator() {
|
||||
if (rand == null) {
|
||||
initRan();
|
||||
|
@ -903,10 +920,24 @@ public class RandomDataGenerator implements Serializable {
|
|||
return rand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the generator used to generate non-secure random data.
|
||||
*
|
||||
* XXX TODO: method cannot be "private" because of its use in "ValueServer" in "DIGEST_MODE".
|
||||
* "ValueServer" should be fixed to not use the internals of another class!
|
||||
*/
|
||||
UniformRandomProvider getRandomProvider() {
|
||||
if (randomProvider == null) {
|
||||
randomProvider = RandomSource.create(randomSource);
|
||||
}
|
||||
return randomProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default generator to a {@link Well19937c} generator seeded with
|
||||
* {@code System.currentTimeMillis() + System.identityHashCode(this))}.
|
||||
*/
|
||||
@Deprecated
|
||||
private void initRan() {
|
||||
rand = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
|
||||
}
|
||||
|
@ -928,4 +959,42 @@ public class RandomDataGenerator implements Serializable {
|
|||
}
|
||||
return secRand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param out Output stream.
|
||||
* @throws IOException if an error occurs.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
// Write non-transient fields.
|
||||
out.defaultWriteObject();
|
||||
|
||||
if (randomProvider != null) {
|
||||
// Save state of "randomProvider".
|
||||
out.writeObject(RandomSource.saveState(randomProvider));
|
||||
} else {
|
||||
out.writeObject(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param in Input stream.
|
||||
* @throws IOException if an error occurs.
|
||||
* @throws ClassNotFoundException if an error occurs.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException,
|
||||
ClassNotFoundException {
|
||||
// Read non-transient fields.
|
||||
in.defaultReadObject();
|
||||
|
||||
// Read "randomProvider" state (can be null).
|
||||
final Object state = in.readObject();
|
||||
if (state != null) {
|
||||
// Recreate "randomProvider" from serialized info.
|
||||
randomProvider = RandomSource.create(randomSource);
|
||||
// And restore its state.
|
||||
RandomSource.restoreState(randomProvider, (RandomSource.State) state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ public class ValueServer {
|
|||
* @throws ZeroException if URL contains no data
|
||||
*/
|
||||
public void computeDistribution(int binCount) throws NullArgumentException, IOException, ZeroException {
|
||||
empiricalDistribution = new EmpiricalDistribution(binCount, randomData.getRandomGenerator());
|
||||
empiricalDistribution = new EmpiricalDistribution(binCount);
|
||||
empiricalDistribution.load(valuesFileURL);
|
||||
mu = empiricalDistribution.getSampleStats().getMean();
|
||||
sigma = empiricalDistribution.getSampleStats().getStandardDeviation();
|
||||
|
@ -372,7 +372,7 @@ public class ValueServer {
|
|||
(empiricalDistribution.getBinStats().size() == 0)) {
|
||||
throw new MathIllegalStateException(LocalizedFormats.DIGEST_NOT_INITIALIZED);
|
||||
}
|
||||
return empiricalDistribution.getNextValue();
|
||||
return empiricalDistribution.createSampler(randomData.getRandomProvider()).sample();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -157,7 +157,7 @@ public class ChiSquareTest {
|
|||
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final ChiSquaredDistribution distribution =
|
||||
new ChiSquaredDistribution(null, expected.length - 1.0);
|
||||
new ChiSquaredDistribution(expected.length - 1.0);
|
||||
return 1.0 - distribution.cumulativeProbability(chiSquare(expected, observed));
|
||||
}
|
||||
|
||||
|
@ -510,7 +510,7 @@ public class ChiSquareTest {
|
|||
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final ChiSquaredDistribution distribution =
|
||||
new ChiSquaredDistribution(null, (double) observed1.length - 1);
|
||||
new ChiSquaredDistribution((double) observed1.length - 1);
|
||||
return 1 - distribution.cumulativeProbability(
|
||||
chiSquareDataSetsComparison(observed1, observed2));
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ public class GTest {
|
|||
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final ChiSquaredDistribution distribution =
|
||||
new ChiSquaredDistribution(null, expected.length - 1.0);
|
||||
new ChiSquaredDistribution(expected.length - 1.0);
|
||||
return 1.0 - distribution.cumulativeProbability(g(expected, observed));
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ public class GTest {
|
|||
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final ChiSquaredDistribution distribution =
|
||||
new ChiSquaredDistribution(null, expected.length - 2.0);
|
||||
new ChiSquaredDistribution(expected.length - 2.0);
|
||||
return 1.0 - distribution.cumulativeProbability(g(expected, observed));
|
||||
}
|
||||
|
||||
|
@ -475,7 +475,7 @@ public class GTest {
|
|||
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final ChiSquaredDistribution distribution =
|
||||
new ChiSquaredDistribution(null, (double) observed1.length - 1);
|
||||
new ChiSquaredDistribution((double) observed1.length - 1);
|
||||
return 1 - distribution.cumulativeProbability(
|
||||
gDataSetsComparison(observed1, observed2));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.HashSet;
|
|||
|
||||
import org.apache.commons.math4.distribution.EnumeratedRealDistribution;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.AbstractRealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.InsufficientDataException;
|
||||
import org.apache.commons.math4.exception.MathArithmeticException;
|
||||
|
@ -39,9 +40,8 @@ import org.apache.commons.math4.linear.Array2DRowFieldMatrix;
|
|||
import org.apache.commons.math4.linear.FieldMatrix;
|
||||
import org.apache.commons.math4.linear.MatrixUtils;
|
||||
import org.apache.commons.math4.linear.RealMatrix;
|
||||
import org.apache.commons.math4.random.JDKRandomGenerator;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well19937c;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.util.CombinatoricsUtils;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathArrays;
|
||||
|
@ -145,14 +145,14 @@ public class KolmogorovSmirnovTest {
|
|||
@Deprecated
|
||||
protected static final int MONTE_CARLO_ITERATIONS = 1000000;
|
||||
|
||||
/** Random data generator used by {@link #monteCarloP(double, int, int, boolean, int)} */
|
||||
private final RandomGenerator rng;
|
||||
@Deprecated
|
||||
private final UniformRandomProvider rng;
|
||||
|
||||
/**
|
||||
* Construct a KolmogorovSmirnovTest instance with a default random data generator.
|
||||
*/
|
||||
public KolmogorovSmirnovTest() {
|
||||
rng = new Well19937c();
|
||||
rng = RandomSource.create(RandomSource.WELL_19937_C);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,8 +163,9 @@ public class KolmogorovSmirnovTest {
|
|||
* @param rng random data generator used by {@link #monteCarloP(double, int, int, boolean, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public KolmogorovSmirnovTest(RandomGenerator rng) {
|
||||
this.rng = rng;
|
||||
public KolmogorovSmirnovTest(RandomSource source,
|
||||
long seed) {
|
||||
rng = RandomSource.create(source, seed);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -419,7 +420,7 @@ public class KolmogorovSmirnovTest {
|
|||
final double[] combined = new double[xLength + yLength];
|
||||
System.arraycopy(x, 0, combined, 0, xLength);
|
||||
System.arraycopy(y, 0, combined, xLength, yLength);
|
||||
final EnumeratedRealDistribution dist = new EnumeratedRealDistribution(rng, combined);
|
||||
final RealDistribution.Sampler sampler = new EnumeratedRealDistribution(combined).createSampler(rng);
|
||||
final long d = integralKolmogorovSmirnovStatistic(x, y);
|
||||
int greaterCount = 0;
|
||||
int equalCount = 0;
|
||||
|
@ -427,8 +428,8 @@ public class KolmogorovSmirnovTest {
|
|||
double[] curY;
|
||||
long curD;
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
curX = dist.sample(xLength);
|
||||
curY = dist.sample(yLength);
|
||||
curX = AbstractRealDistribution.sample(xLength, sampler);
|
||||
curY = AbstractRealDistribution.sample(yLength, sampler);
|
||||
curD = integralKolmogorovSmirnovStatistic(curX, curY);
|
||||
if (curD > d) {
|
||||
greaterCount++;
|
||||
|
@ -1041,7 +1042,7 @@ public class KolmogorovSmirnovTest {
|
|||
* @param numberOfTrueValues number of {@code true} values the boolean array should finally have
|
||||
* @param rng random data generator
|
||||
*/
|
||||
static void fillBooleanArrayRandomlyWithFixedNumberTrueValues(final boolean[] b, final int numberOfTrueValues, final RandomGenerator rng) {
|
||||
private static void fillBooleanArrayRandomlyWithFixedNumberTrueValues(final boolean[] b, final int numberOfTrueValues, final UniformRandomProvider rng) {
|
||||
Arrays.fill(b, true);
|
||||
for (int k = numberOfTrueValues; k < b.length; k++) {
|
||||
final int r = rng.nextInt(k + 1);
|
||||
|
@ -1154,16 +1155,16 @@ public class KolmogorovSmirnovTest {
|
|||
|
||||
// Add jitter using a fixed seed (so same arguments always give same results),
|
||||
// low-initialization-overhead generator
|
||||
final RealDistribution dist =
|
||||
new UniformRealDistribution(new JDKRandomGenerator(100), -minDelta, minDelta);
|
||||
final RealDistribution.Sampler sampler =
|
||||
new UniformRealDistribution(-minDelta, minDelta).createSampler(RandomSource.create(RandomSource.JDK, 100));
|
||||
|
||||
// It is theoretically possible that jitter does not break ties, so repeat
|
||||
// until all ties are gone. Bound the loop and throw MIE if bound is exceeded.
|
||||
int ct = 0;
|
||||
boolean ties = true;
|
||||
do {
|
||||
jitter(x, dist);
|
||||
jitter(y, dist);
|
||||
jitter(x, sampler);
|
||||
jitter(y, sampler);
|
||||
ties = hasTies(x, y);
|
||||
ct++;
|
||||
} while (ties && ct < 1000);
|
||||
|
@ -1202,13 +1203,16 @@ public class KolmogorovSmirnovTest {
|
|||
* values are overwritten with the result of applying jitter.</p>
|
||||
*
|
||||
* @param data input/output data array - entries overwritten by the method
|
||||
* @param dist probability distribution to sample for jitter values
|
||||
* @param sampler probability distribution to sample for jitter values
|
||||
* @throws NullPointerException if either of the parameters is null
|
||||
*/
|
||||
private static void jitter(double[] data, RealDistribution dist) {
|
||||
private static void jitter(double[] data, RealDistribution.Sampler sampler) {
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
data[i] += dist.sample();
|
||||
final double d = sampler.sample();
|
||||
System.out.println("d=" + d); // XXX
|
||||
data[i] += d;
|
||||
}
|
||||
System.out.println(); // XXX
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -182,7 +182,7 @@ public class MannWhitneyUTest {
|
|||
|
||||
// No try-catch or advertised exception because args are valid
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final NormalDistribution standardNormal = new NormalDistribution(null, 0, 1);
|
||||
final NormalDistribution standardNormal = new NormalDistribution(0, 1);
|
||||
|
||||
return 2 * standardNormal.cumulativeProbability(z);
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public class OneWayAnova {
|
|||
final AnovaStats a = anovaStats(categoryData);
|
||||
// No try-catch or advertised exception because args are valid
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final FDistribution fdist = new FDistribution(null, a.dfbg, a.dfwg);
|
||||
final FDistribution fdist = new FDistribution(a.dfbg, a.dfwg);
|
||||
return 1.0 - fdist.cumulativeProbability(a.F);
|
||||
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ public class OneWayAnova {
|
|||
|
||||
final AnovaStats a = anovaStats(categoryData, allowOneElementData);
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final FDistribution fdist = new FDistribution(null, a.dfbg, a.dfwg);
|
||||
final FDistribution fdist = new FDistribution(a.dfbg, a.dfwg);
|
||||
return 1.0 - fdist.cumulativeProbability(a.F);
|
||||
|
||||
}
|
||||
|
|
|
@ -1058,7 +1058,7 @@ public class TTest {
|
|||
|
||||
final double t = FastMath.abs(t(m, mu, v, n));
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final TDistribution distribution = new TDistribution(null, n - 1);
|
||||
final TDistribution distribution = new TDistribution(n - 1);
|
||||
return 2.0 * distribution.cumulativeProbability(-t);
|
||||
|
||||
}
|
||||
|
@ -1088,7 +1088,7 @@ public class TTest {
|
|||
final double t = FastMath.abs(t(m1, m2, v1, v2, n1, n2));
|
||||
final double degreesOfFreedom = df(v1, v2, n1, n2);
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final TDistribution distribution = new TDistribution(null, degreesOfFreedom);
|
||||
final TDistribution distribution = new TDistribution(degreesOfFreedom);
|
||||
return 2.0 * distribution.cumulativeProbability(-t);
|
||||
|
||||
}
|
||||
|
@ -1118,7 +1118,7 @@ public class TTest {
|
|||
final double t = FastMath.abs(homoscedasticT(m1, m2, v1, v2, n1, n2));
|
||||
final double degreesOfFreedom = n1 + n2 - 2;
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final TDistribution distribution = new TDistribution(null, degreesOfFreedom);
|
||||
final TDistribution distribution = new TDistribution(degreesOfFreedom);
|
||||
return 2.0 * distribution.cumulativeProbability(-t);
|
||||
|
||||
}
|
||||
|
|
|
@ -254,7 +254,7 @@ public class WilcoxonSignedRankTest {
|
|||
|
||||
// No try-catch or advertised exception because args are valid
|
||||
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
|
||||
final NormalDistribution standardNormal = new NormalDistribution(null, 0, 1);
|
||||
final NormalDistribution standardNormal = new NormalDistribution(0, 1);
|
||||
|
||||
return 2*standardNormal.cumulativeProbability(z);
|
||||
}
|
||||
|
|
|
@ -20,13 +20,14 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.math4.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.NumberIsTooSmallException;
|
||||
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.rng.RandomSource;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.Precision;
|
||||
import org.junit.Assert;
|
||||
|
@ -212,9 +213,9 @@ public class AkimaSplineInterpolatorTest
|
|||
assertTrue( Precision.equals( expected, actual ) );
|
||||
}
|
||||
|
||||
final RandomGenerator rng = new Well19937c( 1234567L ); // "tol" depends on the seed.
|
||||
final UniformRealDistribution distX =
|
||||
new UniformRealDistribution( rng, xValues[0], xValues[xValues.length - 1] );
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1234567L); // "tol" depends on the seed.
|
||||
final RealDistribution.Sampler distX =
|
||||
new UniformRealDistribution(xValues[0], xValues[xValues.length - 1]).createSampler(rng);
|
||||
|
||||
double sumError = 0;
|
||||
for ( int i = 0; i < numberOfSamples; i++ )
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
package org.apache.commons.math4.analysis.interpolation;
|
||||
|
||||
import org.apache.commons.math4.analysis.BivariateFunction;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
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.rng.RandomSource;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.Precision;
|
||||
import org.junit.Assert;
|
||||
|
@ -360,9 +361,9 @@ public final class BicubicInterpolatingFunctionTest {
|
|||
}
|
||||
}
|
||||
|
||||
final RandomGenerator rng = new Well19937c(1234567L);
|
||||
final UniformRealDistribution distX = new UniformRealDistribution(rng, xValues[0], xValues[xValues.length - 1]);
|
||||
final UniformRealDistribution distY = new UniformRealDistribution(rng, yValues[0], yValues[yValues.length - 1]);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1234567L);
|
||||
final RealDistribution.Sampler distX = new UniformRealDistribution(xValues[0], xValues[xValues.length - 1]).createSampler(rng);
|
||||
final RealDistribution.Sampler distY = new UniformRealDistribution(yValues[0], yValues[yValues.length - 1]).createSampler(rng);
|
||||
|
||||
double sumError = 0;
|
||||
for (int i = 0; i < numberOfSamples; i++) {
|
||||
|
|
|
@ -17,11 +17,12 @@
|
|||
package org.apache.commons.math4.analysis.interpolation;
|
||||
|
||||
import org.apache.commons.math4.analysis.BivariateFunction;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.exception.MathIllegalArgumentException;
|
||||
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.rng.RandomSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -146,9 +147,9 @@ public final class BicubicInterpolatorTest {
|
|||
final BicubicInterpolatingFunction p = interpolator.interpolate(xval, yval, zval);
|
||||
double x, y;
|
||||
|
||||
final RandomGenerator rng = new Well19937c();
|
||||
final UniformRealDistribution distX = new UniformRealDistribution(rng, xval[0], xval[xval.length - 1]);
|
||||
final UniformRealDistribution distY = new UniformRealDistribution(rng, yval[0], yval[yval.length - 1]);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C);
|
||||
final RealDistribution.Sampler distX = new UniformRealDistribution(xval[0], xval[xval.length - 1]).createSampler(rng);
|
||||
final RealDistribution.Sampler distY = new UniformRealDistribution(yval[0], yval[yval.length - 1]).createSampler(rng);
|
||||
|
||||
int count = 0;
|
||||
while (true) {
|
||||
|
|
|
@ -17,13 +17,14 @@
|
|||
package org.apache.commons.math4.analysis.interpolation;
|
||||
|
||||
import org.apache.commons.math4.analysis.BivariateFunction;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.exception.InsufficientDataException;
|
||||
import org.apache.commons.math4.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
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.rng.RandomSource;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.Precision;
|
||||
import org.junit.Assert;
|
||||
|
@ -175,7 +176,7 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
final double maximumY = 10;
|
||||
final int numberOfSamples = 100;
|
||||
|
||||
final double interpolationTolerance = 2e-14;
|
||||
final double interpolationTolerance = 1e-13;
|
||||
final double maxTolerance = 6e-14;
|
||||
|
||||
// Function values
|
||||
|
@ -250,9 +251,9 @@ public final class PiecewiseBicubicSplineInterpolatingFunctionTest {
|
|||
}
|
||||
}
|
||||
|
||||
final RandomGenerator rng = new Well19937c(1234567L);
|
||||
final UniformRealDistribution distX = new UniformRealDistribution(rng, xValues[0], xValues[xValues.length - 1]);
|
||||
final UniformRealDistribution distY = new UniformRealDistribution(rng, yValues[0], yValues[yValues.length - 1]);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1234567L);
|
||||
final RealDistribution.Sampler distX = new UniformRealDistribution(xValues[0], xValues[xValues.length - 1]).createSampler(rng);
|
||||
final RealDistribution.Sampler distY = new UniformRealDistribution(yValues[0], yValues[yValues.length - 1]).createSampler(rng);
|
||||
|
||||
double sumError = 0;
|
||||
for (int i = 0; i < numberOfSamples; i++) {
|
||||
|
|
|
@ -17,13 +17,14 @@
|
|||
package org.apache.commons.math4.analysis.interpolation;
|
||||
|
||||
import org.apache.commons.math4.analysis.BivariateFunction;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.exception.InsufficientDataException;
|
||||
import org.apache.commons.math4.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
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.rng.RandomSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -157,9 +158,9 @@ public final class PiecewiseBicubicSplineInterpolatorTest {
|
|||
BivariateFunction p = interpolator.interpolate(xval, yval, zval);
|
||||
double x, y;
|
||||
|
||||
final RandomGenerator rng = new Well19937c(1234567L); // "tol" depends on the seed.
|
||||
final UniformRealDistribution distX = new UniformRealDistribution( rng, xval[0], xval[xval.length - 1] );
|
||||
final UniformRealDistribution distY = new UniformRealDistribution( rng, yval[0], yval[yval.length - 1] );
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1234567L);
|
||||
final RealDistribution.Sampler distX = new UniformRealDistribution(xval[0], xval[xval.length - 1]).createSampler(rng);
|
||||
final RealDistribution.Sampler distY = new UniformRealDistribution(yval[0], yval[yval.length - 1]).createSampler(rng);
|
||||
|
||||
final int numSamples = 50;
|
||||
final double tol = 2e-14;
|
||||
|
@ -209,9 +210,9 @@ public final class PiecewiseBicubicSplineInterpolatorTest {
|
|||
BivariateFunction p = interpolator.interpolate(xval, yval, zval);
|
||||
double x, y;
|
||||
|
||||
final RandomGenerator rng = new Well19937c(1234567L); // "tol" depends on the seed.
|
||||
final UniformRealDistribution distX = new UniformRealDistribution( rng, xval[0], xval[xval.length - 1] );
|
||||
final UniformRealDistribution distY = new UniformRealDistribution( rng, yval[0], yval[yval.length - 1] );
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1234567L);
|
||||
final RealDistribution.Sampler distX = new UniformRealDistribution(xval[0], xval[xval.length - 1]).createSampler(rng);
|
||||
final RealDistribution.Sampler distY = new UniformRealDistribution(yval[0], yval[yval.length - 1]).createSampler(rng);
|
||||
|
||||
final int numSamples = 50;
|
||||
final double tol = 5e-13;
|
||||
|
|
|
@ -17,11 +17,12 @@
|
|||
package org.apache.commons.math4.analysis.interpolation;
|
||||
|
||||
import org.apache.commons.math4.analysis.TrivariateFunction;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math4.exception.MathIllegalArgumentException;
|
||||
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.rng.RandomSource;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.Precision;
|
||||
import org.junit.Assert;
|
||||
|
@ -379,10 +380,10 @@ public final class TricubicInterpolatingFunctionTest {
|
|||
}
|
||||
}
|
||||
|
||||
final RandomGenerator rng = new Well19937c(1234567L);
|
||||
final UniformRealDistribution distX = new UniformRealDistribution(rng, xValues[0], xValues[xValues.length - 1]);
|
||||
final UniformRealDistribution distY = new UniformRealDistribution(rng, yValues[0], yValues[yValues.length - 1]);
|
||||
final UniformRealDistribution distZ = new UniformRealDistribution(rng, zValues[0], zValues[zValues.length - 1]);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1234568L);
|
||||
final RealDistribution.Sampler distX = new UniformRealDistribution(xValues[0], xValues[xValues.length - 1]).createSampler(rng);
|
||||
final RealDistribution.Sampler distY = new UniformRealDistribution(yValues[0], yValues[yValues.length - 1]).createSampler(rng);
|
||||
final RealDistribution.Sampler distZ = new UniformRealDistribution(zValues[0], zValues[zValues.length - 1]).createSampler(rng);
|
||||
|
||||
double sumError = 0;
|
||||
for (int i = 0; i < numberOfSamples; i++) {
|
||||
|
|
|
@ -35,7 +35,7 @@ public class AbstractRealDistributionTest {
|
|||
final double x3 = 3.0;
|
||||
final double p12 = 0.5;
|
||||
final AbstractRealDistribution distribution;
|
||||
distribution = new AbstractRealDistribution(null) {
|
||||
distribution = new AbstractRealDistribution() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
|
@ -119,7 +119,7 @@ public class AbstractRealDistributionTest {
|
|||
final double p12 = 1.0 / 3.0;
|
||||
final double p23 = 2.0 / 3.0;
|
||||
final AbstractRealDistribution distribution;
|
||||
distribution = new AbstractRealDistribution(null) {
|
||||
distribution = new AbstractRealDistribution() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -346,8 +346,6 @@ public class BetaDistributionTest {
|
|||
public void testGoodnessOfFit() {
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_A,
|
||||
123456789L);
|
||||
final RandomGenerator random = new Well19937a(0x237db1db907b089fL);
|
||||
|
||||
final int numSamples = 1000;
|
||||
final double level = 0.01;
|
||||
for (final double alpha : alphaBetas) {
|
||||
|
@ -360,7 +358,7 @@ public class BetaDistributionTest {
|
|||
Assert.assertFalse("G goodness-of-fit test rejected null at alpha = " + level,
|
||||
gTest(betaDistribution, observed) < level);
|
||||
Assert.assertFalse("KS goodness-of-fit test rejected null at alpha = " + level,
|
||||
new KolmogorovSmirnovTest(random).kolmogorovSmirnovTest(betaDistribution, observed) < level);
|
||||
new KolmogorovSmirnovTest(RandomSource.JDK, 3448845623L).kolmogorovSmirnovTest(betaDistribution, observed) < level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,15 +82,6 @@ public class ConstantRealDistributionTest extends RealDistributionAbstractTest {
|
|||
Assert.assertEquals(dist.getNumericalVariance(), 0, 0d);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSampling() {
|
||||
ConstantRealDistribution dist = new ConstantRealDistribution(0);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Assert.assertEquals(0, dist.sample(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testSampler() {
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.commons.math4.exception.NotFiniteNumberException;
|
|||
import org.apache.commons.math4.exception.NotPositiveException;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.Pair;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -197,7 +198,8 @@ public class EnumeratedRealDistributionTest {
|
|||
List<Pair<Object,Double>> list = new ArrayList<Pair<Object, Double>>();
|
||||
list.add(new Pair<Object, Double>(new Object() {}, new Double(0)));
|
||||
list.add(new Pair<Object, Double>(new Object() {}, new Double(1)));
|
||||
Assert.assertEquals(1, new EnumeratedDistribution<Object>(list).sample(1).length);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_512_A);
|
||||
Assert.assertEquals(1, new EnumeratedDistribution<Object>(list).createSampler(rng).sample(1).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.commons.math4.distribution;
|
||||
|
||||
import org.apache.commons.math4.distribution.LevyDistribution;
|
||||
import org.apache.commons.math4.random.Well19937a;
|
||||
import org.apache.commons.math4.util.Precision;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -41,7 +40,7 @@ public class LevyDistributionTest extends RealDistributionAbstractTest {
|
|||
|
||||
@Override
|
||||
public LevyDistribution makeDistribution() {
|
||||
return new LevyDistribution(new Well19937a(0xc5a5506bbb17e57al), 1.2, 0.4);
|
||||
return new LevyDistribution(1.2, 0.4);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -327,22 +327,6 @@ public abstract class RealDistributionAbstractTest {
|
|||
* Test sampling
|
||||
*/
|
||||
@Test
|
||||
public void testSampling() {
|
||||
final int sampleSize = 1000;
|
||||
distribution.reseedRandomGenerator(1000); // Use fixed seed
|
||||
double[] sample = distribution.sample(sampleSize);
|
||||
double[] quartiles = TestUtils.getDistributionQuartiles(distribution);
|
||||
double[] expected = {250, 250, 250, 250};
|
||||
long[] counts = new long[4];
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
TestUtils.updateCounts(sample[i], counts, quartiles);
|
||||
}
|
||||
TestUtils.assertChiSquareAccept(expected, counts, 0.001);
|
||||
}
|
||||
|
||||
|
||||
// New design
|
||||
@Test
|
||||
public void testSampler() {
|
||||
final int sampleSize = 1000;
|
||||
final RealDistribution.Sampler sampler =
|
||||
|
@ -403,16 +387,18 @@ public abstract class RealDistributionAbstractTest {
|
|||
ClassNotFoundException {
|
||||
// Construct a distribution and initialize its internal random
|
||||
// generator, using a fixed seed for deterministic results.
|
||||
distribution.reseedRandomGenerator(123);
|
||||
distribution.sample();
|
||||
final long seed = 123;
|
||||
RandomSource source = RandomSource.WELL_512_A;
|
||||
RealDistribution.Sampler origSampler = distribution.createSampler(RandomSource.create(source, seed));
|
||||
|
||||
// Clone the distribution.
|
||||
final RealDistribution cloned = deepClone();
|
||||
RealDistribution.Sampler clonedSampler = cloned.createSampler(RandomSource.create(source, seed));
|
||||
|
||||
// Make sure they still produce the same samples.
|
||||
final double s1 = distribution.sample();
|
||||
final double s2 = cloned.sample();
|
||||
Assert.assertEquals(s1, s2, 0d);
|
||||
Assert.assertEquals(origSampler.sample(),
|
||||
clonedSampler.sample(),
|
||||
0d);
|
||||
}
|
||||
|
||||
//------------------ Getters / Setters for test instance data -----------
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
package org.apache.commons.math4.filter;
|
||||
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.filter.DefaultMeasurementModel;
|
||||
import org.apache.commons.math4.filter.DefaultProcessModel;
|
||||
|
@ -26,9 +27,10 @@ import org.apache.commons.math4.linear.MatrixDimensionMismatchException;
|
|||
import org.apache.commons.math4.linear.MatrixUtils;
|
||||
import org.apache.commons.math4.linear.RealMatrix;
|
||||
import org.apache.commons.math4.linear.RealVector;
|
||||
import org.apache.commons.math4.random.JDKRandomGenerator;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well19937c;
|
||||
import org.apache.commons.math4.random.JDKRandomGenerator;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.Precision;
|
||||
import org.junit.Assert;
|
||||
|
@ -392,8 +394,8 @@ public class KalmanFilterTest {
|
|||
final MeasurementModel mm = new DefaultMeasurementModel(H, R);
|
||||
final KalmanFilter filter = new KalmanFilter(pm, mm);
|
||||
|
||||
final RandomGenerator rng = new Well19937c(1000);
|
||||
final NormalDistribution dist = new NormalDistribution(rng, 0, measurementNoise);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1000);
|
||||
final RealDistribution.Sampler dist = new NormalDistribution(0, measurementNoise).createSampler(rng);
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
// get the "real" cannonball position
|
||||
|
|
|
@ -262,7 +262,7 @@ public class LevenbergMarquardtOptimizerTest
|
|||
final double ySigma = 15;
|
||||
final double radius = 111.111;
|
||||
// The test is extremely sensitive to the seed.
|
||||
final long seed = 59421061L;
|
||||
final long seed = 59321761412L;
|
||||
final RandomCirclePointGenerator factory
|
||||
= new RandomCirclePointGenerator(xCenter, yCenter, radius,
|
||||
xSigma, ySigma,
|
||||
|
|
|
@ -20,8 +20,8 @@ import org.apache.commons.math4.distribution.NormalDistribution;
|
|||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well44497b;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathUtils;
|
||||
|
||||
|
@ -30,11 +30,11 @@ import org.apache.commons.math4.util.MathUtils;
|
|||
*/
|
||||
public class RandomCirclePointGenerator {
|
||||
/** RNG for the x-coordinate of the center. */
|
||||
private final RealDistribution cX;
|
||||
private final RealDistribution.Sampler cX;
|
||||
/** RNG for the y-coordinate of the center. */
|
||||
private final RealDistribution cY;
|
||||
private final RealDistribution.Sampler cY;
|
||||
/** RNG for the parametric position of the point. */
|
||||
private final RealDistribution tP;
|
||||
private final RealDistribution.Sampler tP;
|
||||
/** Radius of the circle. */
|
||||
private final double radius;
|
||||
|
||||
|
@ -52,13 +52,11 @@ public class RandomCirclePointGenerator {
|
|||
double xSigma,
|
||||
double ySigma,
|
||||
long seed) {
|
||||
final RandomGenerator rng = new Well44497b(seed);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_44497_B, seed);
|
||||
this.radius = radius;
|
||||
cX = new NormalDistribution(rng, x, xSigma,
|
||||
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
cY = new NormalDistribution(rng, y, ySigma,
|
||||
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
tP = new UniformRealDistribution(rng, 0, MathUtils.TWO_PI);
|
||||
cX = new NormalDistribution(x, xSigma).createSampler(rng);
|
||||
cY = new NormalDistribution(y, ySigma).createSampler(rng);
|
||||
tP = new UniformRealDistribution(0, MathUtils.TWO_PI).createSampler(rng);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,8 +22,8 @@ import java.awt.geom.Point2D;
|
|||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well44497b;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
|
||||
/**
|
||||
* Factory for generating a cloud of points that approximate a straight line.
|
||||
|
@ -34,9 +34,9 @@ public class RandomStraightLinePointGenerator {
|
|||
/** Intercept. */
|
||||
private final double intercept;
|
||||
/** RNG for the x-coordinate. */
|
||||
private final RealDistribution x;
|
||||
private final RealDistribution.Sampler x;
|
||||
/** RNG for the error on the y-coordinate. */
|
||||
private final RealDistribution error;
|
||||
private final RealDistribution.Sampler error;
|
||||
|
||||
/**
|
||||
* The generator will create a cloud of points whose x-coordinates
|
||||
|
@ -61,12 +61,11 @@ public class RandomStraightLinePointGenerator {
|
|||
double lo,
|
||||
double hi,
|
||||
long seed) {
|
||||
final RandomGenerator rng = new Well44497b(seed);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_44497_B, seed);
|
||||
slope = a;
|
||||
intercept = b;
|
||||
error = new NormalDistribution(rng, 0, sigma,
|
||||
NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
|
||||
x = new UniformRealDistribution(rng, lo, hi);
|
||||
error = new NormalDistribution(0, sigma).createSampler(rng);
|
||||
x = new UniformRealDistribution(lo, hi).createSampler(rng);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,8 +36,7 @@ import org.apache.commons.math4.distribution.UniformRealDistribution;
|
|||
import org.apache.commons.math4.exception.MathIllegalStateException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math4.random.EmpiricalDistribution;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.stat.descriptive.SummaryStatistics;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.junit.Assert;
|
||||
|
@ -156,14 +155,27 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
}
|
||||
|
||||
/**
|
||||
* Make sure exception thrown if digest getNext is attempted
|
||||
* Make sure exception thrown if sampling is attempted
|
||||
* before loading empiricalDistribution.
|
||||
*/
|
||||
@Test
|
||||
public void testNexFail() {
|
||||
public void testNextFail1() {
|
||||
try {
|
||||
empiricalDistribution.getNextValue();
|
||||
empiricalDistribution2.getNextValue();
|
||||
empiricalDistribution.createSampler(RandomSource.create(RandomSource.JDK)).sample();
|
||||
Assert.fail("Expecting MathIllegalStateException");
|
||||
} catch (MathIllegalStateException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure exception thrown if sampling is attempted
|
||||
* before loading empiricalDistribution.
|
||||
*/
|
||||
@Test
|
||||
public void testNextFail2() {
|
||||
try {
|
||||
empiricalDistribution2.createSampler(RandomSource.create(RandomSource.JDK)).sample();
|
||||
Assert.fail("Expecting MathIllegalStateException");
|
||||
} catch (MathIllegalStateException ex) {
|
||||
// expected
|
||||
|
@ -245,36 +257,38 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
TestUtils.assertEquals(expectedGeneratorUpperBounds, dist.getGeneratorUpperBounds(), tol);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneratorConfig() {
|
||||
double[] testData = {0, 1, 2, 3, 4};
|
||||
RandomGenerator generator = new RandomAdaptorTest.ConstantGenerator(0.5);
|
||||
// XXX REMOVE (test "embedded RNG" which is to be removed)
|
||||
// @Test
|
||||
// public void testGeneratorConfig() {
|
||||
// double[] testData = {0, 1, 2, 3, 4};
|
||||
// RandomGenerator generator = new RandomAdaptorTest.ConstantGenerator(0.5);
|
||||
|
||||
EmpiricalDistribution dist = new EmpiricalDistribution(5, generator);
|
||||
dist.load(testData);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Assert.assertEquals(2.0, dist.getNextValue(), 0d);
|
||||
}
|
||||
// EmpiricalDistribution dist = new EmpiricalDistribution(5, generator);
|
||||
// dist.load(testData);
|
||||
// for (int i = 0; i < 5; i++) {
|
||||
// Assert.assertEquals(2.0, dist.getNextValue(), 0d);
|
||||
// }
|
||||
|
||||
// Verify no NPE with null generator argument
|
||||
dist = new EmpiricalDistribution(5, (RandomGenerator) null);
|
||||
dist.load(testData);
|
||||
dist.getNextValue();
|
||||
}
|
||||
// // Verify no NPE with null generator argument
|
||||
// dist = new EmpiricalDistribution(5, (RandomGenerator) null);
|
||||
// dist.load(testData);
|
||||
// dist.getNextValue();
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testReSeed() throws Exception {
|
||||
empiricalDistribution.load(url);
|
||||
empiricalDistribution.reSeed(100);
|
||||
final double [] values = new double[10];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
values[i] = empiricalDistribution.getNextValue();
|
||||
}
|
||||
empiricalDistribution.reSeed(100);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Assert.assertEquals(values[i],empiricalDistribution.getNextValue(), 0d);
|
||||
}
|
||||
}
|
||||
// XXX REMOVE (test "embedded RNG" which is to be removed)
|
||||
// @Test
|
||||
// public void testReSeed() throws Exception {
|
||||
// empiricalDistribution.load(url);
|
||||
// empiricalDistribution.reSeed(100);
|
||||
// final double [] values = new double[10];
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// values[i] = empiricalDistribution.getNextValue();
|
||||
// }
|
||||
// empiricalDistribution.reSeed(100);
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// Assert.assertEquals(values[i],empiricalDistribution.getNextValue(), 0d);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void verifySame(EmpiricalDistribution d1, EmpiricalDistribution d2) {
|
||||
Assert.assertEquals(d1.isLoaded(), d2.isLoaded());
|
||||
|
@ -290,10 +304,11 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
|
||||
private void tstGen(double tolerance)throws Exception {
|
||||
empiricalDistribution.load(url);
|
||||
empiricalDistribution.reSeed(1000);
|
||||
RealDistribution.Sampler sampler
|
||||
= empiricalDistribution.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
|
||||
SummaryStatistics stats = new SummaryStatistics();
|
||||
for (int i = 1; i < 1000; i++) {
|
||||
stats.addValue(empiricalDistribution.getNextValue());
|
||||
stats.addValue(sampler.sample());
|
||||
}
|
||||
Assert.assertEquals("mean", 5.069831575018909, stats.getMean(),tolerance);
|
||||
Assert.assertEquals("std dev", 1.0173699343977738, stats.getStandardDeviation(),tolerance);
|
||||
|
@ -301,10 +316,11 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
|
||||
private void tstDoubleGen(double tolerance)throws Exception {
|
||||
empiricalDistribution2.load(dataArray);
|
||||
empiricalDistribution2.reSeed(1000);
|
||||
RealDistribution.Sampler sampler
|
||||
= empiricalDistribution2.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
|
||||
SummaryStatistics stats = new SummaryStatistics();
|
||||
for (int i = 1; i < 1000; i++) {
|
||||
stats.addValue(empiricalDistribution2.getNextValue());
|
||||
stats.addValue(sampler.sample());
|
||||
}
|
||||
Assert.assertEquals("mean", 5.069831575018909, stats.getMean(), tolerance);
|
||||
Assert.assertEquals("std dev", 1.0173699343977738, stats.getStandardDeviation(), tolerance);
|
||||
|
@ -431,9 +447,10 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
}
|
||||
EmpiricalDistribution dist = new EmpiricalDistribution(10);
|
||||
dist.load(data);
|
||||
dist.reseedRandomGenerator(1000);
|
||||
RealDistribution.Sampler sampler
|
||||
= dist.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
final double dev = dist.sample();
|
||||
final double dev = sampler.sample();
|
||||
Assert.assertTrue(dev < 1);
|
||||
Assert.assertTrue(dev > 0);
|
||||
}
|
||||
|
@ -447,9 +464,10 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
final double[] data = {0, 0, 1, 1};
|
||||
EmpiricalDistribution dist = new EmpiricalDistribution(2);
|
||||
dist.load(data);
|
||||
dist.reseedRandomGenerator(1000);
|
||||
RealDistribution.Sampler sampler
|
||||
= dist.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
final double dev = dist.sample();
|
||||
final double dev = sampler.sample();
|
||||
Assert.assertTrue(dev == 0 || dev == 1);
|
||||
}
|
||||
Assert.assertEquals(0.5, dist.cumulativeProbability(0), Double.MIN_VALUE);
|
||||
|
@ -489,10 +507,12 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
final EmpiricalDistribution dist = new ConstantKernelEmpiricalDistribution(5);
|
||||
final double[] data = {1d,2d,3d, 4d,5d,6d, 7d,8d,9d, 10d,11d,12d, 13d,14d,15d};
|
||||
dist.load(data);
|
||||
RealDistribution.Sampler sampler
|
||||
= dist.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
|
||||
// Bin masses concentrated on 2, 5, 8, 11, 14 <- effectively discrete uniform distribution over these
|
||||
double[] values = {2d, 5d, 8d, 11d, 14d};
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Assert.assertTrue(Arrays.binarySearch(values, dist.sample()) >= 0);
|
||||
Assert.assertTrue(Arrays.binarySearch(values, sampler.sample()) >= 0);
|
||||
}
|
||||
final double tol = 10E-12;
|
||||
Assert.assertEquals(0.0, dist.cumulativeProbability(1), tol);
|
||||
|
@ -515,11 +535,13 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
final EmpiricalDistribution dist = new UniformKernelEmpiricalDistribution(5);
|
||||
final double[] data = {1d,2d,3d, 4d,5d,6d, 7d,8d,9d, 10d,11d,12d, 13d,14d,15d};
|
||||
dist.load(data);
|
||||
RealDistribution.Sampler sampler
|
||||
= dist.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
|
||||
// Kernels are uniform distributions on [1,3], [4,6], [7,9], [10,12], [13,15]
|
||||
final double bounds[] = {3d, 6d, 9d, 12d};
|
||||
final double tol = 10E-12;
|
||||
for (int i = 0; i < 20; i++) {
|
||||
final double v = dist.sample();
|
||||
final double v = sampler.sample();
|
||||
// Make sure v is not in the excluded range between bins - that is (bounds[i], bounds[i] + 1)
|
||||
for (int j = 0; j < bounds.length; j++) {
|
||||
Assert.assertFalse(v > bounds[j] + tol && v < bounds[j] + 1 - tol);
|
||||
|
@ -566,7 +588,7 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes
|
|||
}
|
||||
@Override
|
||||
protected RealDistribution getKernel(SummaryStatistics bStats) {
|
||||
return new UniformRealDistribution(randomData.getRandomGenerator(), bStats.getMin(), bStats.getMax());
|
||||
return new UniformRealDistribution(bStats.getMin(), bStats.getMax());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.apache.commons.math4.exception.NullArgumentException;
|
|||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well19937c;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.stat.descriptive.StorelessUnivariateStatistic;
|
||||
import org.apache.commons.math4.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
|
||||
import org.apache.commons.math4.stat.descriptive.UnivariateStatistic;
|
||||
|
@ -709,6 +710,8 @@ public class PSquarePercentileTest extends
|
|||
VERY_LARGE = 10000000;
|
||||
|
||||
private void doDistributionTest(RealDistribution distribution) {
|
||||
final RealDistribution.Sampler sampler =
|
||||
distribution.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
|
||||
double data[];
|
||||
|
||||
data = distribution.sample(VERY_LARGE);
|
||||
|
@ -754,8 +757,8 @@ public class PSquarePercentileTest extends
|
|||
*/
|
||||
@Test
|
||||
public void testDistribution() {
|
||||
doDistributionTest(new NormalDistribution(randomGenerator, 4000, 50));
|
||||
doDistributionTest(new LogNormalDistribution(randomGenerator,4000, 50));
|
||||
doDistributionTest(new NormalDistribution(4000, 50));
|
||||
doDistributionTest(new LogNormalDistribution(4000, 50));
|
||||
// doDistributionTest((new ExponentialDistribution(4000));
|
||||
// doDistributionTest(new GammaDistribution(5d,1d),0.1);
|
||||
}
|
||||
|
|
|
@ -18,14 +18,16 @@ package org.apache.commons.math4.stat.descriptive.rank;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.AbstractRealDistribution;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math4.exception.NotANumberException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
import org.apache.commons.math4.random.JDKRandomGenerator;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well1024a;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.stat.descriptive.UnivariateStatistic;
|
||||
import org.apache.commons.math4.stat.descriptive.UnivariateStatisticAbstractTest;
|
||||
import org.apache.commons.math4.stat.descriptive.rank.Percentile.EstimationType;
|
||||
|
@ -587,11 +589,12 @@ public class PercentileTest extends UnivariateStatisticAbstractTest{
|
|||
|
||||
@Test
|
||||
public void testStoredVsDirect() {
|
||||
final RandomGenerator rand= new JDKRandomGenerator();
|
||||
rand.setSeed(Long.MAX_VALUE);
|
||||
final RealDistribution.Sampler sampler =
|
||||
new NormalDistribution(4000, 50).createSampler(RandomSource.create(RandomSource.JDK,
|
||||
Long.MAX_VALUE));
|
||||
|
||||
for (final int sampleSize : sampleSizes) {
|
||||
final double[] data = new NormalDistribution(rand,4000, 50)
|
||||
.sample(sampleSize);
|
||||
final double[] data = AbstractRealDistribution.sample(sampleSize, sampler);
|
||||
for (final double p : new double[] { 50d, 95d }) {
|
||||
for (final Percentile.EstimationType e : Percentile.EstimationType.values()) {
|
||||
reset(p, e);
|
||||
|
|
|
@ -23,8 +23,8 @@ import java.util.Arrays;
|
|||
import org.apache.commons.math4.TestUtils;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.random.RandomGenerator;
|
||||
import org.apache.commons.math4.random.Well19937c;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.util.CombinatoricsUtils;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathArrays;
|
||||
|
@ -318,7 +318,7 @@ public class KolmogorovSmirnovTestTest {
|
|||
*/
|
||||
@Test
|
||||
public void testTwoSampleMonteCarlo() {
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(new Well19937c(1000));
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(RandomSource.WELL_19937_C, 1000);
|
||||
final int sampleSize = 14;
|
||||
final double tol = .001;
|
||||
final double[] shortUniform = new double[sampleSize];
|
||||
|
@ -345,7 +345,7 @@ public class KolmogorovSmirnovTestTest {
|
|||
|
||||
@Test
|
||||
public void testTwoSampleMonteCarloDifferentSampleSizes() {
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(new Well19937c(1000));
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(RandomSource.WELL_19937_C, 1000);
|
||||
final int sampleSize1 = 14;
|
||||
final int sampleSize2 = 7;
|
||||
final double d = 0.3;
|
||||
|
@ -364,7 +364,7 @@ public class KolmogorovSmirnovTestTest {
|
|||
public void testTwoSampleMonteCarloPerformance() {
|
||||
int numIterations = 100_000;
|
||||
int N = (int)Math.sqrt(KolmogorovSmirnovTest.LARGE_SAMPLE_PRODUCT);
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(new Well19937c(1000));
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(RandomSource.WELL_19937_C, 1000);
|
||||
for (int n = 2; n <= N; ++n) {
|
||||
long startMillis = System.currentTimeMillis();
|
||||
int m = KolmogorovSmirnovTest.LARGE_SAMPLE_PRODUCT/n;
|
||||
|
@ -500,7 +500,7 @@ public class KolmogorovSmirnovTestTest {
|
|||
public void testDRoundingMonteCarlo() {
|
||||
final double tol = 1e-2;
|
||||
final int iterations = 1000000;
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(new Well19937c(1000));
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(RandomSource.WELL_19937_C, 1000);
|
||||
|
||||
final double[] x = {0, 2, 3, 4, 5, 6, 7, 8, 9, 12};
|
||||
final double[] y = {1, 10, 11, 13, 14, 15, 16, 17, 18};
|
||||
|
@ -519,14 +519,17 @@ public class KolmogorovSmirnovTestTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFillBooleanArrayRandomlyWithFixedNumberTrueValues() {
|
||||
public void testFillBooleanArrayRandomlyWithFixedNumberTrueValues() throws Exception {
|
||||
Method method = KolmogorovSmirnovTest.class.getDeclaredMethod("fillBooleanArrayRandomlyWithFixedNumberTrueValues",
|
||||
boolean[].class, Integer.TYPE, UniformRandomProvider.class);
|
||||
method.setAccessible(true);
|
||||
|
||||
final int[][] parameters = {{5, 1}, {5, 2}, {5, 3}, {5, 4}, {8, 1}, {8, 2}, {8, 3}, {8, 4}, {8, 5}, {8, 6}, {8, 7}};
|
||||
|
||||
final double alpha = 0.001;
|
||||
final int numIterations = 1000000;
|
||||
|
||||
final RandomGenerator rng = new Well19937c(0);
|
||||
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 0);
|
||||
|
||||
for (final int[] parameter : parameters) {
|
||||
|
||||
|
@ -537,7 +540,7 @@ public class KolmogorovSmirnovTestTest {
|
|||
final long[] counts = new long[1 << arraySize];
|
||||
|
||||
for (int i = 0; i < numIterations; ++i) {
|
||||
KolmogorovSmirnovTest.fillBooleanArrayRandomlyWithFixedNumberTrueValues(b, numberOfTrueValues, rng);
|
||||
method.invoke(KolmogorovSmirnovTest.class, b, numberOfTrueValues, rng);
|
||||
int x = 0;
|
||||
for (int j = 0; j < arraySize; ++j) {
|
||||
x = ((x << 1) | ((b[j])?1:0));
|
||||
|
@ -576,7 +579,7 @@ public class KolmogorovSmirnovTestTest {
|
|||
public void testBootstrapSmallSamplesWithTies() {
|
||||
final double[] x = {0, 2, 4, 6, 8, 8, 10, 15, 22, 30, 33, 36, 38};
|
||||
final double[] y = {9, 17, 20, 33, 40, 51, 60, 60, 72, 90, 101};
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(new Well19937c(2000));
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(RandomSource.WELL_19937_C, 2000);
|
||||
Assert.assertEquals(0.0059, test.bootstrap(x, y, 10000, false), 1E-3);
|
||||
}
|
||||
|
||||
|
@ -586,7 +589,7 @@ public class KolmogorovSmirnovTestTest {
|
|||
*/
|
||||
@Test
|
||||
public void testBootstrapLargeSamples() {
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(new Well19937c(1000));
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(RandomSource.WELL_19937_C, 1000);
|
||||
Assert.assertEquals(0.0237, test.bootstrap(gaussian, gaussian2, 10000), 1E-2);
|
||||
}
|
||||
|
||||
|
@ -599,7 +602,7 @@ public class KolmogorovSmirnovTestTest {
|
|||
public void testBootstrapRounding() {
|
||||
final double[] x = {2,4,6,8,9,10,11,12,13};
|
||||
final double[] y = {0,1,3,5,7};
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(new Well19937c(1000));
|
||||
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(RandomSource.WELL_19937_C, 1000);
|
||||
Assert.assertEquals(0.06303, test.bootstrap(x, y, 10000, false), 1E-2);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue