Eliminated pluggability of ChiSquaredDistribution used by ChiSquaredDistributionTest. JIRA: MATH-506.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1159916 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2011-08-20 21:08:34 +00:00
parent 1f0c4c9451
commit 7ec9cd0d12
2 changed files with 9 additions and 28 deletions

View File

@ -35,26 +35,13 @@ import org.apache.commons.math.util.MathUtils;
*/ */
public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
/** Distribution used to compute inference statistics. */
private ChiSquaredDistribution distribution;
/** /**
* Construct a ChiSquareTestImpl * Construct a ChiSquareTestImpl
*/ */
public ChiSquareTestImpl() { public ChiSquareTestImpl() {
this(new ChiSquaredDistributionImpl(1.0)); super();
} }
/**
* Create a test instance using the given distribution for computing
* inference statistics.
* @param x distribution used to compute inference statistics.
* @since 1.2
*/
public ChiSquareTestImpl(ChiSquaredDistribution x) {
super();
setDistribution(x);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* <p><strong>Note: </strong>This implementation rescales the * <p><strong>Note: </strong>This implementation rescales the
@ -114,7 +101,8 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
*/ */
public double chiSquareTest(double[] expected, long[] observed) public double chiSquareTest(double[] expected, long[] observed)
throws MathException { throws MathException {
distribution = new ChiSquaredDistributionImpl(expected.length - 1.0); ChiSquaredDistribution distribution =
new ChiSquaredDistributionImpl(expected.length - 1.0);
return 1.0 - distribution.cumulativeProbability( return 1.0 - distribution.cumulativeProbability(
chiSquare(expected, observed)); chiSquare(expected, observed));
} }
@ -188,7 +176,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
throws MathException { throws MathException {
checkArray(counts); checkArray(counts);
double df = ((double) counts.length -1) * ((double) counts[0].length - 1); double df = ((double) counts.length -1) * ((double) counts[0].length - 1);
distribution = new ChiSquaredDistributionImpl(df); ChiSquaredDistribution distribution = new ChiSquaredDistributionImpl(df);
return 1 - distribution.cumulativeProbability(chiSquare(counts)); return 1 - distribution.cumulativeProbability(chiSquare(counts));
} }
@ -282,7 +270,8 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
*/ */
public double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2) public double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2)
throws MathException { throws MathException {
distribution = new ChiSquaredDistributionImpl((double) observed1.length - 1); ChiSquaredDistribution distribution =
new ChiSquaredDistributionImpl((double) observed1.length - 1);
return 1 - distribution.cumulativeProbability( return 1 - distribution.cumulativeProbability(
chiSquareDataSetsComparison(observed1, observed2)); chiSquareDataSetsComparison(observed1, observed2));
} }
@ -401,15 +390,4 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest {
} }
} }
} }
/**
* Modify the distribution used to compute inference statistics.
*
* @param value
* the new distribution
* @since 1.2
*/
public void setDistribution(ChiSquaredDistribution value) {
distribution = value;
}
} }

View File

@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces! If the output is not quite correct, check for invisible trailing spaces!
--> -->
<release version="3.0" date="TBD" description="TBD"> <release version="3.0" date="TBD" description="TBD">
<action dev="psteitz" type="update" issue="MATH-506">
Eliminated pluggability of ChiSquaredDistribution used by ChiSquaredDistributionTest.
</action>
<action dev="luc" type="add" issue="MATH-593"> <action dev="luc" type="add" issue="MATH-593">
Added a 3D SubLine class. Added a 3D SubLine class.
</action> </action>