1 16 package org.apache.commons.math.distribution; 17 18 25 public class TDistributionTest extends ContinuousDistributionAbstractTest { 26 27 31 public TDistributionTest(String name) { 32 super(name); 33 } 34 35 37 38 public ContinuousDistribution makeDistribution() { 39 return DistributionFactory.newInstance().createTDistribution(5.0); 40 } 41 42 43 public double[] makeCumulativeTestPoints() { 44 return new double[] {-5.89343,-3.36493, -2.570582, -2.015048, 46 -1.475884, 0.0, 5.89343, 3.36493, 2.570582, 47 2.015048, 1.475884}; 48 } 49 50 51 public double[] makeCumulativeTestValues() { 52 return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.5d, 0.999d, 53 0.990d, 0.975d, 0.950d, 0.900d}; 54 } 55 56 protected void setup() throws Exception { 58 super.setUp(); 59 setTolerance(1E-6); 60 } 61 62 67 public void testCumulativeProbabilityAgaintStackOverflow() throws Exception { 68 TDistributionImpl td = new TDistributionImpl(5.); 69 double est; 70 est = td.cumulativeProbability(.1); 71 est = td.cumulativeProbability(.01); 72 } 73 74 public void testSmallDf() throws Exception { 75 setDistribution(DistributionFactory.newInstance().createTDistribution(1d)); 76 setTolerance(1E-4); 77 setCumulativeTestPoints(new double[] {-318.3088, -31.82052, -12.70620, -6.313752, 79 -3.077684, 0.0, 318.3088, 31.82052, 12.70620, 80 6.313752, 3.077684}); 81 setInverseCumulativeTestValues(getCumulativeTestPoints()); 82 verifyCumulativeProbabilities(); 83 verifyInverseCumulativeProbabilities(); 84 } 85 86 public void testInverseCumulativeProbabilityExtremes() throws Exception { 87 setInverseCumulativeTestPoints(new double[] {0, 1}); 88 setInverseCumulativeTestValues( 89 new double[] {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}); 90 verifyInverseCumulativeProbabilities(); 91 } 92 93 public void testDfAccessors() { 94 TDistribution distribution = (TDistribution) getDistribution(); 95 assertEquals(5d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE); 96 distribution.setDegreesOfFreedom(4d); 97 assertEquals(4d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE); 98 try { 99 distribution.setDegreesOfFreedom(0d); 100 fail("Expecting IllegalArgumentException for df = 0"); 101 } catch (IllegalArgumentException ex) { 102 } 104 } 105 106 } 107 | Popular Tags |