1 package JSci.maths.statistics; 2 3 import JSci.maths.SpecialMath; 4 5 10 public final class GammaDistribution extends ProbabilityDistribution { 11 private double shape; 12 13 17 public GammaDistribution(double s) { 18 if(s<=0.0) 19 throw new OutOfRangeException("The shape parameter should be (strictly) positive."); 20 shape=s; 21 } 22 25 public double getShapeParameter() { 26 return shape; 27 } 28 31 public double getMean() { 32 return shape; 33 } 34 37 public double getVariance() { 38 return shape; 39 } 40 45 public double probability(double X) { 46 checkRange(X,0.0,Double.MAX_VALUE); 47 if(X==0.0) 48 return 0.0; 49 else 50 return Math.exp(-SpecialMath.logGamma(shape)-X+(shape-1)*Math.log(X)); 51 } 52 56 public double cumulative(double X) { 57 checkRange(X,0.0,Double.MAX_VALUE); 58 return SpecialMath.incompleteGamma(shape,X); 59 } 60 64 public double inverse(double probability) { 65 checkRange(probability); 66 if(probability==0.0) 67 return 0.0; 68 if(probability==1.0) 69 return Double.MAX_VALUE; 70 return findRoot(probability, shape, 0.0, Double.MAX_VALUE); 71 } 72 } 73 74 | Popular Tags |