1 package JSci.maths.statistics; 2 3 8 public final class GeometricDistribution extends ProbabilityDistribution { 9 private double success; 10 private double failure; 11 12 16 public GeometricDistribution(double prob) { 17 if(prob<0.0 || prob>1.0) 18 throw new OutOfRangeException("The probability should be between 0.0 and 1.0."); 19 success=prob; 20 failure=1.0-prob; 21 } 22 25 public double getSuccessParameter() { 26 return success; 27 } 28 31 public double getMean() { 32 return 1.0/success; 33 } 34 37 public double getVariance() { 38 return failure/(success*success); 39 } 40 46 public double probability(double X) { 47 checkRange(X,0.0,Double.MAX_VALUE); 48 return success*Math.pow(failure,X-1); 49 } 50 55 public double cumulative(double X) { 56 checkRange(X,0.0,Double.MAX_VALUE); 57 return 1.0-Math.pow(failure,X); 58 } 59 63 public double inverse(double probability) { 64 checkRange(probability); 65 return Math.log(1.0-probability)/Math.log(failure); 66 } 67 } 68 69 | Popular Tags |