1 16 17 package org.apache.commons.math.distribution; 18 19 26 public class ChiSquareDistributionTest extends ContinuousDistributionAbstractTest { 27 28 32 public ChiSquareDistributionTest(String name) { 33 super(name); 34 } 35 36 38 39 public ContinuousDistribution makeDistribution() { 40 return DistributionFactory.newInstance().createChiSquareDistribution(5.0); 41 } 42 43 44 public double[] makeCumulativeTestPoints() { 45 return new double[] {0.210216d, 0.5542981d, 0.8312116d, 1.145476d, 1.610308d, 47 20.51501d, 15.08627d, 12.83250d, 11.07050d, 9.236357d}; 48 } 49 50 51 public double[] makeCumulativeTestValues() { 52 return new double[] {0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d, 53 0.990d, 0.975d, 0.950d, 0.900d}; 54 } 55 56 57 public double[] makeInverseCumulativeTestPoints() { 58 return new double[] {0, 0.001d, 0.01d, 0.025d, 0.05d, 0.1d, 0.999d, 59 0.990d, 0.975d, 0.950d, 0.900d, 1}; 60 } 61 62 63 public double[] makeInverseCumulativeTestValues() { 64 return new double[] {0, 0.210216d, 0.5542981d, 0.8312116d, 1.145476d, 1.610308d, 65 20.51501d, 15.08627d, 12.83250d, 11.07050d, 9.236357d, 66 Double.POSITIVE_INFINITY}; 67 } 68 69 protected void setup() throws Exception { 71 super.setUp(); 72 setTolerance(1E-6); 73 } 74 75 77 public void testSmallDf() throws Exception { 78 setDistribution(DistributionFactory.newInstance().createChiSquareDistribution(0.1d)); 79 setTolerance(1E-4); 80 setCumulativeTestPoints(new double[] {1.168926E-60, 1.168926E-40, 1.063132E-32, 82 1.144775E-26, 1.168926E-20, 5.472917, 2.175255, 1.13438, 83 0.5318646, 0.1526342}); 84 setInverseCumulativeTestValues(getCumulativeTestPoints()); 85 setInverseCumulativeTestPoints(getCumulativeTestValues()); 86 verifyCumulativeProbabilities(); 87 verifyInverseCumulativeProbabilities(); 88 } 89 90 public void testDfAccessors() { 91 ChiSquaredDistribution distribution = (ChiSquaredDistribution) getDistribution(); 92 assertEquals(5d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE); 93 distribution.setDegreesOfFreedom(4d); 94 assertEquals(4d, distribution.getDegreesOfFreedom(), Double.MIN_VALUE); 95 try { 96 distribution.setDegreesOfFreedom(0d); 97 fail("Expecting IllegalArgumentException for df = 0"); 98 } catch (IllegalArgumentException ex) { 99 } 101 } 102 103 } 104 | Popular Tags |