1 16 package org.apache.commons.math.distribution; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.math.MathException; 21 22 27 public class ExponentialDistributionImpl extends AbstractContinuousDistribution 28 implements ExponentialDistribution, Serializable { 29 30 31 static final long serialVersionUID = 2401296428283614780L; 32 33 34 private double mean; 35 36 40 public ExponentialDistributionImpl(double mean) { 41 super(); 42 setMean(mean); 43 } 44 45 50 public void setMean(double mean) { 51 if (mean <= 0.0) { 52 throw new IllegalArgumentException ("mean must be positive."); 53 } 54 this.mean = mean; 55 } 56 57 61 public double getMean() { 62 return mean; 63 } 64 65 80 public double cumulativeProbability(double x) throws MathException{ 81 double ret; 82 if (x <= 0.0) { 83 ret = 0.0; 84 } else { 85 ret = 1.0 - Math.exp(-x / getMean()); 86 } 87 return ret; 88 } 89 90 102 public double inverseCumulativeProbability(double p) throws MathException { 103 double ret; 104 105 if (p < 0.0 || p > 1.0) { 106 throw new IllegalArgumentException 107 ("probability argument must be between 0 and 1 (inclusive)"); 108 } else if (p == 1.0) { 109 ret = Double.POSITIVE_INFINITY; 110 } else { 111 ret = -getMean() * Math.log(1.0 - p); 112 } 113 114 return ret; 115 } 116 117 125 protected double getDomainLowerBound(double p) { 126 return 0; 127 } 128 129 137 protected double getDomainUpperBound(double p) { 138 141 if (p < .5) { 142 return getMean(); 144 } else { 145 return Double.MAX_VALUE; 147 } 148 } 149 150 157 protected double getInitialDomain(double p) { 158 if (p < .5) { 161 return getMean() * .5; 163 } else { 164 return getMean(); 166 } 167 } 168 } 169 | Popular Tags |