Modified to extend AbstractContinuousDistribution.
Changed to throw IllegalArgumentException instead of returning NaN for inverseCumulativeProbability argument not in [0,1]. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141281 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d41fbb2325
commit
c9f353cee2
|
@ -22,10 +22,10 @@ import org.apache.commons.math.MathException;
|
||||||
/**
|
/**
|
||||||
* The default implementation of {@link ExponentialDistribution}
|
* The default implementation of {@link ExponentialDistribution}
|
||||||
*
|
*
|
||||||
* @version $Revision: 1.16 $ $Date: 2004/06/02 00:15:16 $
|
* @version $Revision: 1.17 $ $Date: 2004/06/06 16:38:05 $
|
||||||
*/
|
*/
|
||||||
public class ExponentialDistributionImpl
|
public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
||||||
implements ExponentialDistribution, Serializable {
|
implements ExponentialDistribution, Serializable {
|
||||||
|
|
||||||
/** Serializable version identifier */
|
/** Serializable version identifier */
|
||||||
static final long serialVersionUID = 2401296428283614780L;
|
static final long serialVersionUID = 2401296428283614780L;
|
||||||
|
@ -95,12 +95,14 @@ public class ExponentialDistributionImpl
|
||||||
* @return x, such that P(X < x) = <code>p</code>
|
* @return x, such that P(X < x) = <code>p</code>
|
||||||
* @throws MathException if the inverse cumulative probability can not be
|
* @throws MathException if the inverse cumulative probability can not be
|
||||||
* computed due to convergence or other numerical errors.
|
* 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;
|
double ret;
|
||||||
|
|
||||||
if (p < 0.0 || p > 1.0) {
|
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) {
|
} else if (p == 1.0) {
|
||||||
ret = Double.POSITIVE_INFINITY;
|
ret = Double.POSITIVE_INFINITY;
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,14 +113,54 @@ public class ExponentialDistributionImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For this disbution, X, this method returns P(x0 < X < x1).
|
* Access the domain value lower bound, based on <code>p</code>, used to
|
||||||
* @param x0 the lower bound
|
* bracket a CDF root.
|
||||||
* @param x1 the upper bound
|
*
|
||||||
* @return the cumulative probability.
|
* @param p the desired probability for the critical value
|
||||||
* @throws MathException if the cumulative probability can not be
|
* @return domain value lower bound, i.e.
|
||||||
* computed due to convergence or other numerical errors.
|
* P(X < <i>lower bound</i>) < <code>p</code>
|
||||||
*/
|
*/
|
||||||
public double cumulativeProbability(double x0, double x1) throws MathException{
|
protected double getDomainLowerBound(double p) {
|
||||||
return cumulativeProbability(x1) - cumulativeProbability(x0);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue