parent
9867d9f281
commit
77c24aa926
|
@ -20,11 +20,9 @@ import java.io.Serializable;
|
|||
|
||||
import org.apache.commons.math4.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math4.analysis.solvers.UnivariateSolverUtils;
|
||||
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.rng.UniformRandomProvider;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
||||
|
@ -50,14 +48,6 @@ public abstract class AbstractRealDistribution
|
|||
/** Serializable version identifier */
|
||||
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 = new org.apache.commons.math4.random.Well19937c();
|
||||
|
||||
/**
|
||||
* For a random variable {@code X} whose values are distributed according
|
||||
* to this distribution, this method returns {@code P(x0 < X <= x1)}.
|
||||
|
@ -211,47 +201,6 @@ public abstract class AbstractRealDistribution
|
|||
return SOLVER_DEFAULT_ABSOLUTE_ACCURACY;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Deprecated
|
||||
public void reseedRandomGenerator(long seed) {
|
||||
random.setSeed(seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* The default implementation uses the
|
||||
* <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling">
|
||||
* inversion method.
|
||||
* </a>
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
return inverseCumulativeProbability(random.nextDouble());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* The default implementation generates the sample by calling
|
||||
* {@link #sample()} in a loop.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public double[] sample(int sampleSize) {
|
||||
if (sampleSize <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,
|
||||
sampleSize);
|
||||
}
|
||||
double[] out = new double[sampleSize];
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
out[i] = sample();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
|
|
@ -254,7 +254,7 @@ public class BetaDistribution extends AbstractRealDistribution {
|
|||
* @since 3.6
|
||||
*/
|
||||
private static class ChengBetaSampler implements RealDistribution.Sampler {
|
||||
/** RNG (uniform distribution. */
|
||||
/** RNG (uniform distribution). */
|
||||
private final UniformRandomProvider rng;
|
||||
/** First shape parameter. */
|
||||
private final double alphaShape;
|
||||
|
@ -264,7 +264,7 @@ public class BetaDistribution extends AbstractRealDistribution {
|
|||
/**
|
||||
* Creates a sampler instance.
|
||||
*
|
||||
* @param rng Generator.
|
||||
* @param generator RNG.
|
||||
* @param alpha Distribution first shape parameter.
|
||||
* @param beta Distribution second shape parameter.
|
||||
*/
|
||||
|
|
|
@ -104,21 +104,6 @@ public class ConstantRealDistribution extends AbstractRealDistribution {
|
|||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override with no-op (there is no generator).
|
||||
* @param seed (ignored)
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void reseedRandomGenerator(long seed) {}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
|
|
@ -310,6 +310,7 @@ public class EnumeratedDistribution<T> implements Serializable {
|
|||
* Creates a {@link Sampler}.
|
||||
*
|
||||
* @param rng Random number generator.
|
||||
* @return a new sampler instance.
|
||||
*/
|
||||
public Sampler createSampler(final UniformRandomProvider rng) {
|
||||
return new Sampler(rng);
|
||||
|
|
|
@ -273,15 +273,6 @@ public class EnumeratedRealDistribution extends AbstractRealDistribution {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
return innerDistribution.sample();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
|
||||
|
|
|
@ -186,58 +186,6 @@ public class ExponentialDistribution extends AbstractRealDistribution {
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p><strong>Algorithm Description</strong>: this implementation uses the
|
||||
* <a href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html">
|
||||
* Inversion Method</a> to generate exponentially distributed random values
|
||||
* from uniform deviates.</p>
|
||||
*
|
||||
* @return a random value.
|
||||
* @since 2.2
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
// Step 1:
|
||||
double a = 0;
|
||||
double u = random.nextDouble();
|
||||
|
||||
// Step 2 and 3:
|
||||
while (u < 0.5) {
|
||||
a += EXPONENTIAL_SA_QI[0];
|
||||
u *= 2;
|
||||
}
|
||||
|
||||
// Step 4 (now u >= 0.5):
|
||||
u += u - 1;
|
||||
|
||||
// Step 5:
|
||||
if (u <= EXPONENTIAL_SA_QI[0]) {
|
||||
return mean * (a + u);
|
||||
}
|
||||
|
||||
// Step 6:
|
||||
int i = 0; // Should be 1, be we iterate before it in while using 0
|
||||
double u2 = random.nextDouble();
|
||||
double umin = u2;
|
||||
|
||||
// Step 7 and 8:
|
||||
do {
|
||||
++i;
|
||||
u2 = random.nextDouble();
|
||||
|
||||
if (u2 < umin) {
|
||||
umin = u2;
|
||||
}
|
||||
|
||||
// Step 8:
|
||||
} while (u > EXPONENTIAL_SA_QI[i]); // Ensured to exit since EXPONENTIAL_SA_QI[MAX] = 1
|
||||
|
||||
return mean * (a + umin * EXPONENTIAL_SA_QI[0]);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected double getSolverAbsoluteAccuracy() {
|
||||
|
|
|
@ -350,88 +350,6 @@ public class GammaDistribution extends AbstractRealDistribution {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>This implementation uses the following algorithms: </p>
|
||||
*
|
||||
* <p>For 0 < shape < 1: <br/>
|
||||
* Ahrens, J. H. and Dieter, U., <i>Computer methods for
|
||||
* sampling from gamma, beta, Poisson and binomial distributions.</i>
|
||||
* Computing, 12, 223-246, 1974.</p>
|
||||
*
|
||||
* <p>For shape >= 1: <br/>
|
||||
* Marsaglia and Tsang, <i>A Simple Method for Generating
|
||||
* Gamma Variables.</i> ACM Transactions on Mathematical Software,
|
||||
* Volume 26 Issue 3, September, 2000.</p>
|
||||
*
|
||||
* @return random value sampled from the Gamma(shape, scale) distribution
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
if (shape < 1) {
|
||||
// [1]: p. 228, Algorithm GS
|
||||
|
||||
while (true) {
|
||||
// Step 1:
|
||||
final double u = random.nextDouble();
|
||||
final double bGS = 1 + shape / FastMath.E;
|
||||
final double p = bGS * u;
|
||||
|
||||
if (p <= 1) {
|
||||
// Step 2:
|
||||
|
||||
final double x = FastMath.pow(p, 1 / shape);
|
||||
final double u2 = random.nextDouble();
|
||||
|
||||
if (u2 > FastMath.exp(-x)) {
|
||||
// Reject
|
||||
continue;
|
||||
} else {
|
||||
return scale * x;
|
||||
}
|
||||
} else {
|
||||
// Step 3:
|
||||
|
||||
final double x = -1 * FastMath.log((bGS - p) / shape);
|
||||
final double u2 = random.nextDouble();
|
||||
|
||||
if (u2 > FastMath.pow(x, shape - 1)) {
|
||||
// Reject
|
||||
continue;
|
||||
} else {
|
||||
return scale * x;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now shape >= 1
|
||||
|
||||
final double d = shape - 0.333333333333333333;
|
||||
final double c = 1 / (3 * FastMath.sqrt(d));
|
||||
|
||||
while (true) {
|
||||
final double x = random.nextGaussian();
|
||||
final double v = (1 + c * x) * (1 + c * x) * (1 + c * x);
|
||||
|
||||
if (v <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final double x2 = x * x;
|
||||
final double u = random.nextDouble();
|
||||
|
||||
// Squeeze
|
||||
if (u < 1 - 0.0331 * x2 * x2) {
|
||||
return scale * d * v;
|
||||
}
|
||||
|
||||
if (FastMath.log(u) < 0.5 * x2 + d * (1 - v + FastMath.log(v))) {
|
||||
return scale * d * v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
@ -461,7 +379,7 @@ public class GammaDistribution extends AbstractRealDistribution {
|
|||
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
|
||||
return new RealDistribution.Sampler() {
|
||||
/** Gaussian sampling. */
|
||||
final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
|
||||
private final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
|
|
|
@ -288,25 +288,17 @@ public class LogNormalDistribution extends AbstractRealDistribution {
|
|||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
final double n = random.nextGaussian();
|
||||
return FastMath.exp(scale + shape * n);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
|
||||
return new RealDistribution.Sampler() {
|
||||
/** Gaussian sampling. */
|
||||
final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
|
||||
private final RealDistribution.Sampler gaussian = new NormalDistribution().createSampler(rng);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public double sample() {
|
||||
final double n = random.nextGaussian();
|
||||
final double n = gaussian.sample();
|
||||
return FastMath.exp(scale + shape * n);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -235,13 +235,6 @@ public class NormalDistribution extends AbstractRealDistribution {
|
|||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
return standardDeviation * random.nextGaussian() + mean;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
|
||||
|
|
|
@ -248,14 +248,6 @@ public class ParetoDistribution extends AbstractRealDistribution {
|
|||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
final double n = random.nextDouble();
|
||||
return scale / FastMath.pow(n, 1 / shape);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
|
||||
|
|
|
@ -160,33 +160,6 @@ public interface RealDistribution {
|
|||
*/
|
||||
boolean isSupportConnected();
|
||||
|
||||
/**
|
||||
* Reseed the random generator used to generate samples.
|
||||
*
|
||||
* @param seed the new seed
|
||||
*/
|
||||
@Deprecated
|
||||
void reseedRandomGenerator(long seed);
|
||||
|
||||
/**
|
||||
* Generate a random value sampled from this distribution.
|
||||
*
|
||||
* @return a random value.
|
||||
*/
|
||||
@Deprecated
|
||||
double sample();
|
||||
|
||||
/**
|
||||
* Generate a random sample from the distribution.
|
||||
*
|
||||
* @param sampleSize the number of random values to generate
|
||||
* @return an array representing the random sample
|
||||
* @throws org.apache.commons.math4.exception.NotStrictlyPositiveException
|
||||
* if {@code sampleSize} is not positive
|
||||
*/
|
||||
@Deprecated
|
||||
double[] sample(int sampleSize);
|
||||
|
||||
/**
|
||||
* Creates a sampler.
|
||||
*
|
||||
|
|
|
@ -158,14 +158,6 @@ public class UniformRealDistribution extends AbstractRealDistribution {
|
|||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
@Deprecated
|
||||
public double sample() {
|
||||
final double u = random.nextDouble();
|
||||
return u * upper + (1 - u) * lower;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
|
||||
|
|
|
@ -42,7 +42,6 @@ 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;
|
||||
|
||||
|
@ -113,10 +112,6 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
/** Serializable version identifier */
|
||||
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 */
|
||||
private final List<SummaryStatistics> binStats;
|
||||
|
||||
|
@ -160,54 +155,8 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
}
|
||||
this.binCount = binCount;
|
||||
binStats = new ArrayList<SummaryStatistics>();
|
||||
randomData = null; // XXX remove
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EmpiricalDistribution with the specified bin count using the
|
||||
* provided {@link RandomGenerator} as the source of random data.
|
||||
*
|
||||
* @param binCount number of bins. Must be strictly positive.
|
||||
* @param generator random data generator (may be null, resulting in default JDK generator)
|
||||
* @throws NotStrictlyPositiveException if {@code binCount <= 0}.
|
||||
* @since 3.0
|
||||
*/
|
||||
@Deprecated
|
||||
public EmpiricalDistribution(int binCount, RandomGenerator generator) {
|
||||
this(binCount, new RandomDataGenerator(generator));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EmpiricalDistribution with default bin count using the
|
||||
* provided {@link RandomGenerator} as the source of random data.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor to allow lazy initialisation of the RNG contained
|
||||
* in the {@link #randomData} instance variable.
|
||||
*
|
||||
* @param binCount number of bins. Must be strictly positive.
|
||||
* @param randomData Random data generator.
|
||||
* @throws NotStrictlyPositiveException if {@code binCount <= 0}.
|
||||
*/
|
||||
@Deprecated
|
||||
private EmpiricalDistribution(int binCount,
|
||||
RandomDataGenerator randomData) {
|
||||
if (binCount <= 0) {
|
||||
throw new NotStrictlyPositiveException(binCount);
|
||||
}
|
||||
this.binCount = binCount;
|
||||
this.randomData = randomData;
|
||||
binStats = new ArrayList<SummaryStatistics>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the empirical distribution from the provided
|
||||
* array of numbers.
|
||||
|
@ -455,21 +404,6 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
binCount - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random value from this distribution.
|
||||
* <strong>Preconditions:</strong><ul>
|
||||
* <li>the distribution must be loaded before invoking this method</li></ul>
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link StatisticalSummary} describing this distribution.
|
||||
* <strong>Preconditions:</strong><ul>
|
||||
|
@ -556,18 +490,6 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
return loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reseeds the random number generator used by {@link #getNextValue()}.
|
||||
*
|
||||
* @param seed random generator seed
|
||||
* @since 3.0
|
||||
* XXX REMOVE
|
||||
*/
|
||||
@Deprecated
|
||||
public void reSeed(long seed) {
|
||||
randomData.reSeed(seed);
|
||||
}
|
||||
|
||||
// Distribution methods ---------------------------
|
||||
|
||||
/**
|
||||
|
@ -742,16 +664,6 @@ public class EmpiricalDistribution extends AbstractRealDistribution {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 3.1
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void reseedRandomGenerator(long seed) {
|
||||
randomData.reSeed(seed);
|
||||
}
|
||||
|
||||
/**{@inheritDoc} */
|
||||
@Override
|
||||
public RealDistribution.Sampler createSampler(final UniformRandomProvider rng) {
|
||||
|
|
|
@ -160,7 +160,8 @@ public class KolmogorovSmirnovTest {
|
|||
* The #monteCarloP(double, int, int, boolean, int) that uses the generator supplied to this
|
||||
* constructor is deprecated as of version 3.6.
|
||||
*
|
||||
* @param rng random data generator used by {@link #monteCarloP(double, int, int, boolean, int)}
|
||||
* @param source random data generator used by {@link #monteCarloP(double, int, int, boolean, int)}
|
||||
* @param seed Seed.
|
||||
*/
|
||||
@Deprecated
|
||||
public KolmogorovSmirnovTest(RandomSource source,
|
||||
|
@ -1209,10 +1210,8 @@ public class KolmogorovSmirnovTest {
|
|||
private static void jitter(double[] data, RealDistribution.Sampler sampler) {
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
final double d = sampler.sample();
|
||||
System.out.println("d=" + d); // XXX
|
||||
data[i] += d;
|
||||
}
|
||||
System.out.println(); // XXX
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.commons.math4.exception.ConvergenceException;
|
|||
import org.apache.commons.math4.fitting.PolynomialCurveFitter;
|
||||
import org.apache.commons.math4.fitting.WeightedObservedPoints;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -35,9 +36,9 @@ import org.junit.Test;
|
|||
public class PolynomialCurveFitterTest {
|
||||
@Test
|
||||
public void testFit() {
|
||||
final RealDistribution rng = new UniformRealDistribution(-100, 100);
|
||||
rng.reseedRandomGenerator(64925784252L);
|
||||
|
||||
final RealDistribution.Sampler rng
|
||||
= new UniformRealDistribution(-100, 100).createSampler(RandomSource.create(RandomSource.WELL_512_A,
|
||||
64925784252L));
|
||||
final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
|
||||
final PolynomialFunction f = new PolynomialFunction(coeff);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.commons.math4.distribution.RealDistribution;
|
|||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.fitting.SimpleCurveFitter;
|
||||
import org.apache.commons.math4.fitting.WeightedObservedPoints;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -34,8 +35,9 @@ public class SimpleCurveFitterTest {
|
|||
@Test
|
||||
public void testPolynomialFit() {
|
||||
final Random randomizer = new Random(53882150042L);
|
||||
final RealDistribution rng = new UniformRealDistribution(-100, 100);
|
||||
rng.reseedRandomGenerator(64925784252L);
|
||||
final RealDistribution.Sampler rng
|
||||
= new UniformRealDistribution(-100, 100).createSampler(RandomSource.create(RandomSource.WELL_512_A,
|
||||
64925784253L));
|
||||
|
||||
final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
|
||||
final PolynomialFunction f = new PolynomialFunction(coeff);
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.commons.math4.linear;
|
|||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.exception.MathUnsupportedOperationException;
|
||||
import org.apache.commons.math4.linear.ArrayRealVector;
|
||||
|
@ -32,6 +33,7 @@ import org.apache.commons.math4.linear.TriDiagonalTransformer;
|
|||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathArrays;
|
||||
import org.apache.commons.math4.util.Precision;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -468,7 +470,9 @@ public class EigenDecompositionTest {
|
|||
public void testNormalDistributionUnsymmetricMatrix() {
|
||||
for (int run = 0; run < 100; run++) {
|
||||
Random r = new Random(System.currentTimeMillis());
|
||||
NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);
|
||||
RealDistribution.Sampler dist
|
||||
= new NormalDistribution(0.0, r.nextDouble() * 5).createSampler(RandomSource.create(RandomSource.WELL_512_A,
|
||||
64925784252L));
|
||||
|
||||
// matrix size
|
||||
int size = r.nextInt(20) + 4;
|
||||
|
|
|
@ -19,11 +19,13 @@ package org.apache.commons.math4.linear;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.linear.HessenbergTransformer;
|
||||
import org.apache.commons.math4.linear.MatrixUtils;
|
||||
import org.apache.commons.math4.linear.NonSquareMatrixException;
|
||||
import org.apache.commons.math4.linear.RealMatrix;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
|
||||
|
@ -112,7 +114,9 @@ public class HessenbergTransformerTest {
|
|||
public void testRandomDataNormalDistribution() {
|
||||
for (int run = 0; run < 100; run++) {
|
||||
Random r = new Random(System.currentTimeMillis());
|
||||
NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);
|
||||
RealDistribution.Sampler dist
|
||||
= new NormalDistribution(0.0, r.nextDouble() * 5).createSampler(RandomSource.create(RandomSource.WELL_512_A,
|
||||
64925784252L));
|
||||
|
||||
// matrix size
|
||||
int size = r.nextInt(20) + 4;
|
||||
|
|
|
@ -19,11 +19,13 @@ package org.apache.commons.math4.linear;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.linear.MatrixUtils;
|
||||
import org.apache.commons.math4.linear.NonSquareMatrixException;
|
||||
import org.apache.commons.math4.linear.RealMatrix;
|
||||
import org.apache.commons.math4.linear.SchurTransformer;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
|
||||
|
@ -116,7 +118,9 @@ public class SchurTransformerTest {
|
|||
public void testRandomDataNormalDistribution() {
|
||||
for (int run = 0; run < 100; run++) {
|
||||
Random r = new Random(System.currentTimeMillis());
|
||||
NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);
|
||||
RealDistribution.Sampler dist
|
||||
= new NormalDistribution(0.0, r.nextDouble() * 5).createSampler(RandomSource.create(RandomSource.WELL_512_A,
|
||||
64925784252L));
|
||||
|
||||
// matrix size
|
||||
int size = r.nextInt(20) + 4;
|
||||
|
|
|
@ -23,9 +23,11 @@ import java.util.Collection;
|
|||
import org.apache.commons.math4.TestUtils;
|
||||
import org.apache.commons.math4.distribution.IntegerDistribution;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.AbstractRealDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformIntegerDistribution;
|
||||
import org.apache.commons.math4.distribution.UniformRealDistribution;
|
||||
import org.apache.commons.math4.util.Precision;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -281,9 +283,11 @@ public class AggregateSummaryStatisticsTest {
|
|||
*/
|
||||
private double[] generateSample() {
|
||||
final IntegerDistribution size = new UniformIntegerDistribution(10, 100);
|
||||
final RealDistribution randomData = new UniformRealDistribution(-100, 100);
|
||||
final RealDistribution.Sampler randomData
|
||||
= new UniformRealDistribution(-100, 100).createSampler(RandomSource.create(RandomSource.WELL_512_A,
|
||||
64925784252L));;
|
||||
final int sampleSize = size.sample();
|
||||
final double[] out = randomData.sample(sampleSize);
|
||||
final double[] out = AbstractRealDistribution.sample(sampleSize, randomData);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.commons.math4.distribution.UniformIntegerDistribution;
|
|||
import org.apache.commons.math4.stat.descriptive.UnivariateStatistic;
|
||||
import org.apache.commons.math4.stat.descriptive.WeightedEvaluation;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -187,7 +188,9 @@ public abstract class UnivariateStatisticAbstractTest {
|
|||
// Fill values array with random data from N(mu, sigma)
|
||||
// and fill valuesList with values from values array with
|
||||
// values[i] repeated weights[i] times, each i
|
||||
final RealDistribution valueDist = new NormalDistribution(mu, sigma);
|
||||
final RealDistribution.Sampler valueDist
|
||||
= new NormalDistribution(mu, sigma).createSampler(RandomSource.create(RandomSource.WELL_512_A,
|
||||
64925784252L));
|
||||
List<Double> valuesList = new ArrayList<Double>();
|
||||
for (int i = 0; i < len; i++) {
|
||||
double value = valueDist.sample();
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Set;
|
|||
import org.apache.commons.math4.distribution.LogNormalDistribution;
|
||||
import org.apache.commons.math4.distribution.NormalDistribution;
|
||||
import org.apache.commons.math4.distribution.RealDistribution;
|
||||
import org.apache.commons.math4.distribution.AbstractRealDistribution;
|
||||
import org.apache.commons.math4.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.OutOfRangeException;
|
||||
|
@ -714,39 +715,39 @@ public class PSquarePercentileTest extends
|
|||
distribution.createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
|
||||
double data[];
|
||||
|
||||
data = distribution.sample(VERY_LARGE);
|
||||
data = AbstractRealDistribution.sample(VERY_LARGE, sampler);
|
||||
doCalculatePercentile(50, data, 0.0001);
|
||||
doCalculatePercentile(95, data, 0.0001);
|
||||
|
||||
data = distribution.sample(LARGE);
|
||||
data = AbstractRealDistribution.sample(LARGE, sampler);
|
||||
doCalculatePercentile(50, data, 0.001);
|
||||
doCalculatePercentile(95, data, 0.001);
|
||||
|
||||
data = distribution.sample(VERY_BIG);
|
||||
data = AbstractRealDistribution.sample(VERY_BIG, sampler);
|
||||
doCalculatePercentile(50, data, 0.001);
|
||||
doCalculatePercentile(95, data, 0.001);
|
||||
|
||||
data = distribution.sample(BIG);
|
||||
data = AbstractRealDistribution.sample(BIG, sampler);
|
||||
doCalculatePercentile(50, data, 0.001);
|
||||
doCalculatePercentile(95, data, 0.001);
|
||||
|
||||
data = distribution.sample(STANDARD);
|
||||
data = AbstractRealDistribution.sample(STANDARD, sampler);
|
||||
doCalculatePercentile(50, data, 0.005);
|
||||
doCalculatePercentile(95, data, 0.005);
|
||||
|
||||
data = distribution.sample(MEDIUM);
|
||||
data = AbstractRealDistribution.sample(MEDIUM, sampler);
|
||||
doCalculatePercentile(50, data, 0.005);
|
||||
doCalculatePercentile(95, data, 0.005);
|
||||
|
||||
data = distribution.sample(NOMINAL);
|
||||
data = AbstractRealDistribution.sample(NOMINAL, sampler);
|
||||
doCalculatePercentile(50, data, 0.01);
|
||||
doCalculatePercentile(95, data, 0.01);
|
||||
|
||||
data = distribution.sample(SMALL);
|
||||
data = AbstractRealDistribution.sample(SMALL, sampler);
|
||||
doCalculatePercentile(50, data, 0.01);
|
||||
doCalculatePercentile(95, data, 0.01);
|
||||
|
||||
data = distribution.sample(TINY);
|
||||
data = AbstractRealDistribution.sample(TINY, sampler);
|
||||
doCalculatePercentile(50, data, 0.05);
|
||||
doCalculatePercentile(95, data, 0.05);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.apache.commons.math4.exception.NotFiniteNumberException;
|
|||
import org.apache.commons.math4.exception.NullArgumentException;
|
||||
import org.apache.commons.math4.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math4.random.RandomDataGenerator;
|
||||
import org.apache.commons.math4.rng.RandomSource;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
import org.apache.commons.math4.util.MathUtils;
|
||||
import org.junit.Assert;
|
||||
|
@ -100,7 +101,9 @@ public final class MathUtilsTest {
|
|||
|
||||
// Generate 10 distinct random values
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final RealDistribution u = new UniformRealDistribution(i + 0.5, i + 0.75);
|
||||
final RealDistribution.Sampler u
|
||||
= new UniformRealDistribution(i + 0.5, i + 0.75).createSampler(RandomSource.create(RandomSource.WELL_512_A,
|
||||
64925784252L));
|
||||
original[i] = u.sample();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue