You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2014/10/13 17:54:22 UTC
git commit: Changed inference classes to pass null RandomGenerators
to distribution constructors. JIRA: MATH-1154.
Repository: commons-math
Updated Branches:
refs/heads/master 69273dca6 -> a3fdeb4da
Changed inference classes to pass null RandomGenerators to distribution constructors. JIRA: MATH-1154.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a3fdeb4d
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a3fdeb4d
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a3fdeb4d
Branch: refs/heads/master
Commit: a3fdeb4da91d8aef50f40a3f9906494593ce2eca
Parents: 69273dc
Author: Phil Steitz <ph...@gmail.com>
Authored: Mon Oct 13 06:31:45 2014 -0700
Committer: Phil Steitz <ph...@gmail.com>
Committed: Mon Oct 13 06:31:45 2014 -0700
----------------------------------------------------------------------
src/changes/changes.xml | 5 +++++
.../math3/stat/inference/BinomialTest.java | 3 ++-
.../math3/stat/inference/ChiSquareTest.java | 14 ++++++++------
.../commons/math3/stat/inference/GTest.java | 18 ++++++++++--------
.../math3/stat/inference/MannWhitneyUTest.java | 3 ++-
.../commons/math3/stat/inference/OneWayAnova.java | 8 +++++---
.../commons/math3/stat/inference/TTest.java | 11 +++++++----
.../stat/inference/WilcoxonSignedRankTest.java | 3 ++-
8 files changed, 41 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fdeb4d/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7ea96c9..7762b80 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -73,6 +73,11 @@ Users are encouraged to upgrade to this version as this release not
2. A few methods in the FastMath class are in fact slower that their
counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
">
+ <action dev="psteitz" type="add" issue="MATH-1154" >
+ Changed classes in the inference package that instantiate distributions to
+ pass null RandomGenerators to avoid initialization overhead for the default
+ generator.
+ </action>
<action dev="luc" type="add" issue="MATH-1156" >
Added all Java 8 StrictMath methods to FastMath, so FastMath remains compatible
with newer Java versions.
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fdeb4d/src/main/java/org/apache/commons/math3/stat/inference/BinomialTest.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/stat/inference/BinomialTest.java b/src/main/java/org/apache/commons/math3/stat/inference/BinomialTest.java
index 8b914cb..2efe091 100644
--- a/src/main/java/org/apache/commons/math3/stat/inference/BinomialTest.java
+++ b/src/main/java/org/apache/commons/math3/stat/inference/BinomialTest.java
@@ -119,7 +119,8 @@ public class BinomialTest {
throw new NullArgumentException();
}
- final BinomialDistribution distribution = new BinomialDistribution(numberOfTrials, probability);
+ // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
+ final BinomialDistribution distribution = new BinomialDistribution(null, numberOfTrials, probability);
switch (alternativeHypothesis) {
case GREATER_THAN:
return 1 - distribution.cumulativeProbability(numberOfSuccesses - 1);
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fdeb4d/src/main/java/org/apache/commons/math3/stat/inference/ChiSquareTest.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/stat/inference/ChiSquareTest.java b/src/main/java/org/apache/commons/math3/stat/inference/ChiSquareTest.java
index 09f55bf..7e97ac1 100644
--- a/src/main/java/org/apache/commons/math3/stat/inference/ChiSquareTest.java
+++ b/src/main/java/org/apache/commons/math3/stat/inference/ChiSquareTest.java
@@ -155,8 +155,9 @@ public class ChiSquareTest {
throws NotPositiveException, NotStrictlyPositiveException,
DimensionMismatchException, MaxCountExceededException {
- ChiSquaredDistribution distribution =
- new ChiSquaredDistribution(expected.length - 1.0);
+ // 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);
return 1.0 - distribution.cumulativeProbability(chiSquare(expected, observed));
}
@@ -311,8 +312,8 @@ public class ChiSquareTest {
checkArray(counts);
double df = ((double) counts.length -1) * ((double) counts[0].length - 1);
- ChiSquaredDistribution distribution;
- distribution = new ChiSquaredDistribution(df);
+ // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
+ final ChiSquaredDistribution distribution = new ChiSquaredDistribution(df);
return 1 - distribution.cumulativeProbability(chiSquare(counts));
}
@@ -507,8 +508,9 @@ public class ChiSquareTest {
throws DimensionMismatchException, NotPositiveException, ZeroException,
MaxCountExceededException {
- ChiSquaredDistribution distribution;
- distribution = new ChiSquaredDistribution((double) observed1.length - 1);
+ // 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);
return 1 - distribution.cumulativeProbability(
chiSquareDataSetsComparison(observed1, observed2));
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fdeb4d/src/main/java/org/apache/commons/math3/stat/inference/GTest.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/stat/inference/GTest.java b/src/main/java/org/apache/commons/math3/stat/inference/GTest.java
index a193644..de1fbe3 100644
--- a/src/main/java/org/apache/commons/math3/stat/inference/GTest.java
+++ b/src/main/java/org/apache/commons/math3/stat/inference/GTest.java
@@ -152,10 +152,10 @@ public class GTest {
throws NotPositiveException, NotStrictlyPositiveException,
DimensionMismatchException, MaxCountExceededException {
+ // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final ChiSquaredDistribution distribution =
- new ChiSquaredDistribution(expected.length - 1.0);
- return 1.0 - distribution.cumulativeProbability(
- g(expected, observed));
+ new ChiSquaredDistribution(null, expected.length - 1.0);
+ return 1.0 - distribution.cumulativeProbability(g(expected, observed));
}
/**
@@ -183,10 +183,10 @@ public class GTest {
throws NotPositiveException, NotStrictlyPositiveException,
DimensionMismatchException, MaxCountExceededException {
+ // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final ChiSquaredDistribution distribution =
- new ChiSquaredDistribution(expected.length - 2.0);
- return 1.0 - distribution.cumulativeProbability(
- g(expected, observed));
+ new ChiSquaredDistribution(null, expected.length - 2.0);
+ return 1.0 - distribution.cumulativeProbability(g(expected, observed));
}
/**
@@ -472,8 +472,10 @@ public class GTest {
final long[] observed2)
throws DimensionMismatchException, NotPositiveException, ZeroException,
MaxCountExceededException {
- final ChiSquaredDistribution distribution = new ChiSquaredDistribution(
- (double) observed1.length - 1);
+
+ // 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);
return 1 - distribution.cumulativeProbability(
gDataSetsComparison(observed1, observed2));
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fdeb4d/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java b/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
index 0bb16d5..82fddb3 100644
--- a/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
+++ b/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
@@ -181,7 +181,8 @@ public class MannWhitneyUTest {
final double z = (Umin - EU) / FastMath.sqrt(VarU);
// No try-catch or advertised exception because args are valid
- final NormalDistribution standardNormal = new NormalDistribution(0, 1);
+ // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
+ final NormalDistribution standardNormal = new NormalDistribution(null, 0, 1);
return 2 * standardNormal.cumulativeProbability(z);
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fdeb4d/src/main/java/org/apache/commons/math3/stat/inference/OneWayAnova.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/stat/inference/OneWayAnova.java b/src/main/java/org/apache/commons/math3/stat/inference/OneWayAnova.java
index e82731f..d0c5fc1 100644
--- a/src/main/java/org/apache/commons/math3/stat/inference/OneWayAnova.java
+++ b/src/main/java/org/apache/commons/math3/stat/inference/OneWayAnova.java
@@ -124,9 +124,10 @@ public class OneWayAnova {
throws NullArgumentException, DimensionMismatchException,
ConvergenceException, MaxCountExceededException {
- AnovaStats a = anovaStats(categoryData);
+ final AnovaStats a = anovaStats(categoryData);
// No try-catch or advertised exception because args are valid
- FDistribution fdist = new FDistribution(a.dfbg, a.dfwg);
+ // 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);
return 1.0 - fdist.cumulativeProbability(a.F);
}
@@ -167,7 +168,8 @@ public class OneWayAnova {
ConvergenceException, MaxCountExceededException {
final AnovaStats a = anovaStats(categoryData, allowOneElementData);
- final FDistribution fdist = new FDistribution(a.dfbg, a.dfwg);
+ // 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);
return 1.0 - fdist.cumulativeProbability(a.F);
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fdeb4d/src/main/java/org/apache/commons/math3/stat/inference/TTest.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/stat/inference/TTest.java b/src/main/java/org/apache/commons/math3/stat/inference/TTest.java
index 9c1946a..b0f76f6 100644
--- a/src/main/java/org/apache/commons/math3/stat/inference/TTest.java
+++ b/src/main/java/org/apache/commons/math3/stat/inference/TTest.java
@@ -1056,8 +1056,9 @@ public class TTest {
final double v, final double n)
throws MaxCountExceededException, MathIllegalArgumentException {
- double t = FastMath.abs(t(m, mu, v, n));
- TDistribution distribution = new TDistribution(n - 1);
+ 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);
return 2.0 * distribution.cumulativeProbability(-t);
}
@@ -1086,7 +1087,8 @@ public class TTest {
final double t = FastMath.abs(t(m1, m2, v1, v2, n1, n2));
final double degreesOfFreedom = df(v1, v2, n1, n2);
- TDistribution distribution = new TDistribution(degreesOfFreedom);
+ // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
+ final TDistribution distribution = new TDistribution(null, degreesOfFreedom);
return 2.0 * distribution.cumulativeProbability(-t);
}
@@ -1115,7 +1117,8 @@ public class TTest {
final double t = FastMath.abs(homoscedasticT(m1, m2, v1, v2, n1, n2));
final double degreesOfFreedom = n1 + n2 - 2;
- TDistribution distribution = new TDistribution(degreesOfFreedom);
+ // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
+ final TDistribution distribution = new TDistribution(null, degreesOfFreedom);
return 2.0 * distribution.cumulativeProbability(-t);
}
http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fdeb4d/src/main/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTest.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTest.java b/src/main/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTest.java
index 3b2a5d0..bd4d7e2 100644
--- a/src/main/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTest.java
+++ b/src/main/java/org/apache/commons/math3/stat/inference/WilcoxonSignedRankTest.java
@@ -253,7 +253,8 @@ public class WilcoxonSignedRankTest {
final double z = (Wmin - ES - 0.5) / FastMath.sqrt(VarS);
// No try-catch or advertised exception because args are valid
- final NormalDistribution standardNormal = new NormalDistribution(0, 1);
+ // pass a null rng to avoid unneeded overhead as we will not sample from this distribution
+ final NormalDistribution standardNormal = new NormalDistribution(null, 0, 1);
return 2*standardNormal.cumulativeProbability(z);
}