Made class fields "private".

This commit is contained in:
Gilles 2017-05-10 15:23:07 +02:00
parent 6568bb2543
commit d71ead41fb
2 changed files with 11 additions and 12 deletions

View File

@ -115,23 +115,20 @@ import org.apache.commons.math4.util.MathUtils;
* @since 3.3 * @since 3.3
*/ */
public class KolmogorovSmirnovTest { public class KolmogorovSmirnovTest {
/** /**
* Bound on the number of partial sums in {@link #ksSum(double, double, int)} * Bound on the number of partial sums in {@link #ksSum(double, double, int)}
*/ */
protected static final int MAXIMUM_PARTIAL_SUM_COUNT = 100000; private static final int MAXIMUM_PARTIAL_SUM_COUNT = 100000;
/** Convergence criterion for {@link #ksSum(double, double, int)} */ /** Convergence criterion for {@link #ksSum(double, double, int)} */
protected static final double KS_SUM_CAUCHY_CRITERION = 1E-20; private static final double KS_SUM_CAUCHY_CRITERION = 1e-20;
/** Convergence criterion for the sums in #pelzGood(double, double, int)} */ /** Convergence criterion for the sums in #pelzGood(double, double, int)} */
protected static final double PG_SUM_RELATIVE_ERROR = 1.0e-10; private static final double PG_SUM_RELATIVE_ERROR = 1e-10;
/** /**
* When product of sample sizes exceeds this value, 2-sample K-S test uses asymptotic * When product of sample sizes exceeds this value, 2-sample K-S test uses asymptotic
* distribution to compute the p-value. * distribution to compute the p-value.
*/ */
protected static final int LARGE_SAMPLE_PRODUCT = 10000; private static final int LARGE_SAMPLE_PRODUCT = 10000;
/** /**
* Computes the <i>p-value</i>, or <i>observed significance level</i>, of a one-sample <a * Computes the <i>p-value</i>, or <i>observed significance level</i>, of a one-sample <a

View File

@ -40,6 +40,8 @@ import org.junit.Test;
public class KolmogorovSmirnovTestTest { public class KolmogorovSmirnovTestTest {
protected static final double TOLERANCE = 10e-10; protected static final double TOLERANCE = 10e-10;
private static final int MONTE_CARLO_ITERATIONS = 1000000;
private static final int LARGE_SAMPLE_PRODUCT = 10000;
// Random N(0,1) values generated using R rnorm // Random N(0,1) values generated using R rnorm
protected static final double[] gaussian = { protected static final double[] gaussian = {
@ -337,9 +339,9 @@ public class KolmogorovSmirnovTestTest {
double exactPStrict = test.exactP(dv, sampleSize, sampleSize, true); double exactPStrict = test.exactP(dv, sampleSize, sampleSize, true);
double exactPNonStrict = test.exactP(dv, sampleSize, sampleSize, false); double exactPNonStrict = test.exactP(dv, sampleSize, sampleSize, false);
double montePStrict = test.monteCarloP(dv, sampleSize, sampleSize, true, double montePStrict = test.monteCarloP(dv, sampleSize, sampleSize, true,
KolmogorovSmirnovTest.MONTE_CARLO_ITERATIONS, rng); MONTE_CARLO_ITERATIONS, rng);
double montePNonStrict = test.monteCarloP(dv, sampleSize, sampleSize, false, double montePNonStrict = test.monteCarloP(dv, sampleSize, sampleSize, false,
KolmogorovSmirnovTest.MONTE_CARLO_ITERATIONS, rng); MONTE_CARLO_ITERATIONS, rng);
Assert.assertEquals(exactPStrict, montePStrict, tol); Assert.assertEquals(exactPStrict, montePStrict, tol);
Assert.assertEquals(exactPNonStrict, montePNonStrict, tol); Assert.assertEquals(exactPNonStrict, montePNonStrict, tol);
} }
@ -356,7 +358,7 @@ public class KolmogorovSmirnovTestTest {
final double tol = 1e-2; final double tol = 1e-2;
Assert.assertEquals(test.exactP(d, sampleSize1, sampleSize2, strict), Assert.assertEquals(test.exactP(d, sampleSize1, sampleSize2, strict),
test.monteCarloP(d, sampleSize1, sampleSize2, strict, test.monteCarloP(d, sampleSize1, sampleSize2, strict,
KolmogorovSmirnovTest.MONTE_CARLO_ITERATIONS, rng), MONTE_CARLO_ITERATIONS, rng),
tol); tol);
} }
@ -366,12 +368,12 @@ public class KolmogorovSmirnovTestTest {
// @Test // @Test
public void testTwoSampleMonteCarloPerformance() { public void testTwoSampleMonteCarloPerformance() {
int numIterations = 100_000; int numIterations = 100_000;
int N = (int)Math.sqrt(KolmogorovSmirnovTest.LARGE_SAMPLE_PRODUCT); int N = (int)Math.sqrt(LARGE_SAMPLE_PRODUCT);
final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest(); final KolmogorovSmirnovTest test = new KolmogorovSmirnovTest();
final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1000); final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1000);
for (int n = 2; n <= N; ++n) { for (int n = 2; n <= N; ++n) {
long startMillis = System.currentTimeMillis(); long startMillis = System.currentTimeMillis();
int m = KolmogorovSmirnovTest.LARGE_SAMPLE_PRODUCT/n; int m = LARGE_SAMPLE_PRODUCT/n;
Assert.assertEquals(0d, test.monteCarloP(Double.POSITIVE_INFINITY, n, m, true, numIterations, rng), 0d); Assert.assertEquals(0d, test.monteCarloP(Double.POSITIVE_INFINITY, n, m, true, numIterations, rng), 0d);
long endMillis = System.currentTimeMillis(); long endMillis = System.currentTimeMillis();
System.out.println("n=" + n + ", m=" + m + ", time=" + (endMillis-startMillis)/1000d + "s"); System.out.println("n=" + n + ", m=" + m + ", time=" + (endMillis-startMillis)/1000d + "s");