psteitz 2004/07/24 13:43:29
Modified: math/src/java/org/apache/commons/math/distribution
ChiSquaredDistributionImpl.java
math/src/test/org/apache/commons/math/distribution
ChiSquareDistributionTest.java
Log:
Changed inverseCumulativeProbability to correctly handle p=0,1 as discussed on
commons-dev.
Revision Changes Path
1.19 +25 -1
jakarta-commons/math/src/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java
Index: ChiSquaredDistributionImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ChiSquaredDistributionImpl.java 23 Jun 2004 16:26:15 -0000 1.18
+++ ChiSquaredDistributionImpl.java 24 Jul 2004 20:43:29 -0000 1.19
@@ -70,6 +70,30 @@
public double cumulativeProbability(double x) throws MathException {
return getGamma().cumulativeProbability(x);
}
+
+ /**
+ * For this distribution, X, this method returns the critical point x, such
+ * that P(X < x) = <code>p</code>.
+ * <p>
+ * Returns 0 for p=0 and <code>Double.POSITIVE_INFINITY</code> for p=1.
+ *
+ * @param p the desired probability
+ * @return x, such that P(X < x) = <code>p</code>
+ * @throws MathException if the inverse cumulative probability can not be
+ * computed due to convergence or other numerical errors.
+ * @throws IllegalArgumentException if <code>p</code> is not a valid
+ * probability.
+ */
+ public double inverseCumulativeProbability(final double p)
+ throws MathException {
+ if (p == 0) {
+ return 0d;
+ }
+ if (p == 1) {
+ return Double.POSITIVE_INFINITY;
+ }
+ return super.inverseCumulativeProbability(p);
+ }
/**
* Access the domain value lower bound, based on <code>p</code>, used to
1.16 +16 -2
jakarta-commons/math/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java
Index: ChiSquareDistributionTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ChiSquareDistributionTest.java 29 May 2004 22:52:44 -0000 1.15
+++ ChiSquareDistributionTest.java 24 Jul 2004 20:43:29 -0000 1.16
@@ -51,7 +51,20 @@
public double[] makeCumulativeTestValues() {
return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d,
0.990d, 0.975d, 0.950d, 0.900d};
- }
+ }
+
+ /** Creates the default inverse cumulative probability test input values */
+ public double[] makeInverseCumulativeTestPoints() {
+ return new double[] {0, 0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d,
+ 0.990d, 0.975d, 0.950d, 0.900d, 1};
+ }
+
+ /** Creates the default inverse cumulative probability density test expected
values */
+ public double[] makeInverseCumulativeTestValues() {
+ return new double[] {0, 0.210216d, 0.5542981d, 0.8312116d, 1.145476d,
1.610308d,
+ 20.51501d, 15.08627d, 12.83250d, 11.07050d, 9.236357d,
+ Double.POSITIVE_INFINITY};
+ }
// --------------------- Override tolerance --------------
protected void setup() throws Exception {
@@ -69,6 +82,7 @@
1.144775E-26, 1.168926E-20, 5.472917, 2.175255, 1.13438,
0.5318646, 0.1526342});
setInverseCumulativeTestValues(getCumulativeTestPoints());
+ setInverseCumulativeTestPoints(getCumulativeTestValues());
verifyCumulativeProbabilities();
verifyInverseCumulativeProbabilities();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]