1 package JSci.maths.statistics; 2 3 8 public final class ExponentialDistribution extends ProbabilityDistribution { 9 private double lambda; 10 11 14 public ExponentialDistribution() { 15 this(1.0); 16 } 17 21 public ExponentialDistribution(double decay) { 22 if(decay<0.0) 23 throw new OutOfRangeException("The scale parameter should be positive."); 24 lambda=decay; 25 } 26 30 public ExponentialDistribution(double array[]) { 31 double sumX=array[0]; 32 for(int i=1;i<array.length;i++) 33 sumX+=array[i]; 34 lambda=sumX/array.length; 35 } 36 39 public double getScaleParameter() { 40 return lambda; 41 } 42 45 public double getMean() { 46 return lambda; 47 } 48 51 public double getVariance() { 52 return lambda*lambda; 53 } 54 59 public double probability(double X) { 60 checkRange(X,0.0,Double.MAX_VALUE); 61 return lambda*Math.exp(-lambda*X); 62 } 63 67 public double cumulative(double X) { 68 checkRange(X,0.0,Double.MAX_VALUE); 69 return 1.0-Math.exp(-lambda*X); 70 } 71 75 public double inverse(double probability) { 76 checkRange(probability); 77 return -Math.log(1.0-probability)/lambda; 78 } 79 } 80 81 | Popular Tags |