Changed inference classes to pass null RandomGenerators to distribution constructors. JIRA: MATH-1154.
This commit is contained in:
parent
69273dca61
commit
a3fdeb4da9
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue