1 package JSci.maths.statistics; 2 3 import JSci.maths.SpecialMath; 4 5 10 public final class BetaDistribution extends ProbabilityDistribution { 11 private double p,q; 12 13 18 public BetaDistribution(double dgrP,double dgrQ) { 19 if(dgrP<=0 || dgrQ<=0) 20 throw new OutOfRangeException("The degrees of freedom must be greater than zero."); 21 p=dgrP; 22 q=dgrQ; 23 } 24 27 public double getDegreesOfFreedomP() { 28 return p; 29 } 30 33 public double getDegreesOfFreedomQ() { 34 return q; 35 } 36 40 public double probability(double X) { 41 checkRange(X); 42 if(X==0.0 || X==1.0) 43 return 0.0; 44 return Math.exp(-SpecialMath.logBeta(p,q)+(p-1.0)*Math.log(X)+(q-1.0)*Math.log(1.0-X)); 45 } 46 50 public double cumulative(double X) { 51 checkRange(X); 52 return SpecialMath.incompleteBeta(X,p,q); 53 } 54 58 public double inverse(double probability) { 59 checkRange(probability); 60 if(probability==0.0) 61 return 0.0; 62 if(probability==1.0) 63 return 1.0; 64 return findRoot(probability, 0.5, 0.0, 1.0); 65 } 66 } 67 68 | Popular Tags |