1 16 package org.apache.commons.math.distribution; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.math.MathException; 21 import org.apache.commons.math.special.Beta; 22 23 29 public class FDistributionImpl 30 extends AbstractContinuousDistribution 31 implements FDistribution, Serializable { 32 33 34 static final long serialVersionUID = -8516354193418641566L; 35 36 37 private double numeratorDegreesOfFreedom; 38 39 40 private double denominatorDegreesOfFreedom; 41 42 47 public FDistributionImpl(double numeratorDegreesOfFreedom, 48 double denominatorDegreesOfFreedom) { 49 super(); 50 setNumeratorDegreesOfFreedom(numeratorDegreesOfFreedom); 51 setDenominatorDegreesOfFreedom(denominatorDegreesOfFreedom); 52 } 53 54 69 public double cumulativeProbability(double x) throws MathException { 70 double ret; 71 if (x <= 0.0) { 72 ret = 0.0; 73 } else { 74 double n = getNumeratorDegreesOfFreedom(); 75 double m = getDenominatorDegreesOfFreedom(); 76 77 ret = Beta.regularizedBeta((n * x) / (m + n * x), 78 0.5 * n, 79 0.5 * m); 80 } 81 return ret; 82 } 83 84 97 public double inverseCumulativeProbability(final double p) 98 throws MathException { 99 if (p == 0) { 100 return 0d; 101 } 102 if (p == 1) { 103 return Double.POSITIVE_INFINITY; 104 } 105 return super.inverseCumulativeProbability(p); 106 } 107 108 117 protected double getDomainLowerBound(double p) { 118 return 0.0; 119 } 120 121 130 protected double getDomainUpperBound(double p) { 131 return Double.MAX_VALUE; 132 } 133 134 142 protected double getInitialDomain(double p) { 143 return getDenominatorDegreesOfFreedom() / 144 (getDenominatorDegreesOfFreedom() - 2.0); 145 } 146 147 153 public void setNumeratorDegreesOfFreedom(double degreesOfFreedom) { 154 if (degreesOfFreedom <= 0.0) { 155 throw new IllegalArgumentException ( 156 "degrees of freedom must be positive."); 157 } 158 this.numeratorDegreesOfFreedom = degreesOfFreedom; 159 } 160 161 165 public double getNumeratorDegreesOfFreedom() { 166 return numeratorDegreesOfFreedom; 167 } 168 169 175 public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) { 176 if (degreesOfFreedom <= 0.0) { 177 throw new IllegalArgumentException ( 178 "degrees of freedom must be positive."); 179 } 180 this.denominatorDegreesOfFreedom = degreesOfFreedom; 181 } 182 183 187 public double getDenominatorDegreesOfFreedom() { 188 return denominatorDegreesOfFreedom; 189 } 190 } 191 | Popular Tags |