1 16 package org.apache.commons.math.distribution; 17 18 19 26 public class FDistributionTest extends ContinuousDistributionAbstractTest { 27 28 32 public FDistributionTest(String name) { 33 super(name); 34 } 35 36 38 39 public ContinuousDistribution makeDistribution() { 40 return DistributionFactory.newInstance().createFDistribution(5.0, 6.0); 41 } 42 43 44 public double[] makeCumulativeTestPoints() { 45 return new double[] {0.03468084d ,0.09370091d, 0.1433137d, 47 0.2020084d, 0.2937283d, 20.80266d, 8.745895d, 5.987565d, 48 4.387374d, 3.107512d}; 49 } 50 51 52 public double[] makeCumulativeTestValues() { 53 return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d, 54 0.990d, 0.975d, 0.950d, 0.900d}; 55 } 56 57 protected void setup() throws Exception { 59 super.setUp(); 60 setTolerance(1E-6); 61 } 62 63 65 public void testCumulativeProbabilityExtremes() throws Exception { 66 setCumulativeTestPoints(new double[] {-2, 0}); 67 setCumulativeTestValues(new double[] {0, 0}); 68 verifyCumulativeProbabilities(); 69 } 70 71 public void testInverseCumulativeProbabilityExtremes() throws Exception { 72 setInverseCumulativeTestPoints(new double[] {0, 1}); 73 setInverseCumulativeTestValues(new double[] {0, Double.POSITIVE_INFINITY}); 74 verifyInverseCumulativeProbabilities(); 75 } 76 77 public void testDfAccessors() { 78 FDistribution distribution = (FDistribution) getDistribution(); 79 assertEquals(5d, distribution.getNumeratorDegreesOfFreedom(), Double.MIN_VALUE); 80 distribution.setNumeratorDegreesOfFreedom(4d); 81 assertEquals(4d, distribution.getNumeratorDegreesOfFreedom(), Double.MIN_VALUE); 82 assertEquals(6d, distribution.getDenominatorDegreesOfFreedom(), Double.MIN_VALUE); 83 distribution.setDenominatorDegreesOfFreedom(4d); 84 assertEquals(4d, distribution.getDenominatorDegreesOfFreedom(), Double.MIN_VALUE); 85 try { 86 distribution.setNumeratorDegreesOfFreedom(0d); 87 fail("Expecting IllegalArgumentException for df = 0"); 88 } catch (IllegalArgumentException ex) { 89 } 91 try { 92 distribution.setDenominatorDegreesOfFreedom(0d); 93 fail("Expecting IllegalArgumentException for df = 0"); 94 } catch (IllegalArgumentException ex) { 95 } 97 } 98 99 public void testLargeDegreesOfFreedom() throws Exception { 100 org.apache.commons.math.distribution.FDistributionImpl fd = 101 new org.apache.commons.math.distribution.FDistributionImpl( 102 100000., 100000.); 103 double p = fd.cumulativeProbability(.999); 104 double x = fd.inverseCumulativeProbability(p); 105 assertEquals(.999, x, 1.0e-5); 106 } 107 } 108 | Popular Tags |