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 TDistributionImpl 30 extends AbstractContinuousDistribution 31 implements TDistribution, Serializable { 32 33 34 static final long serialVersionUID = -5852615386664158222L; 35 36 37 private double degreesOfFreedom; 38 39 43 public TDistributionImpl(double degreesOfFreedom) { 44 super(); 45 setDegreesOfFreedom(degreesOfFreedom); 46 } 47 48 52 public void setDegreesOfFreedom(double degreesOfFreedom) { 53 if (degreesOfFreedom <= 0.0) { 54 throw new IllegalArgumentException ("degrees of freedom must be positive."); 55 } 56 this.degreesOfFreedom = degreesOfFreedom; 57 } 58 59 63 public double getDegreesOfFreedom() { 64 return degreesOfFreedom; 65 } 66 67 74 public double cumulativeProbability(double x) throws MathException{ 75 double ret; 76 if (x == 0.0) { 77 ret = 0.5; 78 } else { 79 double t = 80 Beta.regularizedBeta( 81 getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)), 82 0.5 * getDegreesOfFreedom(), 83 0.5); 84 if (x < 0.0) { 85 ret = 0.5 * t; 86 } else { 87 ret = 1.0 - 0.5 * t; 88 } 89 } 90 91 return ret; 92 } 93 94 108 public double inverseCumulativeProbability(final double p) 109 throws MathException { 110 if (p == 0) { 111 return Double.NEGATIVE_INFINITY; 112 } 113 if (p == 1) { 114 return Double.POSITIVE_INFINITY; 115 } 116 return super.inverseCumulativeProbability(p); 117 } 118 119 128 protected double getDomainLowerBound(double p) { 129 return -Double.MAX_VALUE; 130 } 131 132 141 protected double getDomainUpperBound(double p) { 142 return Double.MAX_VALUE; 143 } 144 145 153 protected double getInitialDomain(double p) { 154 return 0.0; 155 } 156 } 157 | Popular Tags |