psteitz 2004/06/06 09:38:05
Modified: math/src/java/org/apache/commons/math/distribution
ExponentialDistributionImpl.java
Log:
Modified to extend AbstractContinuousDistribution.
Changed to throw IllegalArgumentException instead of returning NaN for
inverseCumulativeProbability argument not in [0,1].
Revision Changes Path
1.17 +55 -13
jakarta-commons/math/src/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java
Index: ExponentialDistributionImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ExponentialDistributionImpl.java 2 Jun 2004 00:15:16 -0000 1.16
+++ ExponentialDistributionImpl.java 6 Jun 2004 16:38:05 -0000 1.17
@@ -24,8 +24,8 @@
*
* @version $Revision$ $Date$
*/
-public class ExponentialDistributionImpl
- implements ExponentialDistribution, Serializable {
+public class ExponentialDistributionImpl extends AbstractContinuousDistribution
+ implements ExponentialDistribution, Serializable {
/** Serializable version identifier */
static final long serialVersionUID = 2401296428283614780L;
@@ -95,12 +95,14 @@
* @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 p < 0 or p > 1.
*/
- public double inverseCumulativeProbability(double p) throws MathException{
+ public double inverseCumulativeProbability(double p) throws MathException {
double ret;
if (p < 0.0 || p > 1.0) {
- ret = Double.NaN;
+ throw new IllegalArgumentException
+ ("probability argument must be between 0 and 1 (inclusive)");
} else if (p == 1.0) {
ret = Double.POSITIVE_INFINITY;
} else {
@@ -111,14 +113,54 @@
}
/**
- * For this disbution, X, this method returns P(x0 < X < x1).
- * @param x0 the lower bound
- * @param x1 the upper bound
- * @return the cumulative probability.
- * @throws MathException if the cumulative probability can not be
- * computed due to convergence or other numerical errors.
+ * Access the domain value lower bound, based on <code>p</code>, used to
+ * bracket a CDF root.
+ *
+ * @param p the desired probability for the critical value
+ * @return domain value lower bound, i.e.
+ * P(X < <i>lower bound</i>) < <code>p</code>
*/
- public double cumulativeProbability(double x0, double x1) throws MathException{
- return cumulativeProbability(x1) - cumulativeProbability(x0);
+ protected double getDomainLowerBound(double p) {
+ return 0;
+ }
+
+ /**
+ * Access the domain value upper bound, based on <code>p</code>, used to
+ * bracket a CDF root.
+ *
+ * @param p the desired probability for the critical value
+ * @return domain value upper bound, i.e.
+ * P(X < <i>upper bound</i>) > <code>p</code>
+ */
+ protected double getDomainUpperBound(double p) {
+ // NOTE: exponential is skewed to the left
+ // NOTE: therefore, P(X < μ) > .5
+
+ if (p < .5) {
+ // use mean
+ return getMean();
+ } else {
+ // use max
+ return Double.MAX_VALUE;
+ }
+ }
+
+ /**
+ * Access the initial domain value, based on <code>p</code>, used to
+ * bracket a CDF root.
+ *
+ * @param p the desired probability for the critical value
+ * @return initial domain value
+ */
+ protected double getInitialDomain(double p) {
+ // TODO: try to improve on this estimate
+ // Exponential is skewed to the left, therefore, P(X < μ) > .5
+ if (p < .5) {
+ // use 1/2 mean
+ return getMean() * .5;
+ } else {
+ // use mean
+ return getMean();
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]