1 16 package org.apache.commons.math.distribution; 17 18 25 public class BinomialDistributionTest extends IntegerDistributionAbstractTest { 26 27 31 public BinomialDistributionTest(String name) { 32 super(name); 33 } 34 35 37 38 public IntegerDistribution makeDistribution() { 39 return DistributionFactory.newInstance().createBinomialDistribution(10,0.70); 40 } 41 42 43 public int[] makeDensityTestPoints() { 44 return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; 45 } 46 47 48 public double[] makeDensityTestValues() { 49 return new double[] {0d, 0.0000d, 0.0001d, 0.0014d, 0.0090d, 0.0368d, 0.1029d, 50 0.2001d, 0.2668d, 0.2335d, 0.1211d, 0.0282d, 0d}; 51 } 52 53 54 public int[] makeCumulativeTestPoints() { 55 return makeDensityTestPoints(); 56 } 57 58 59 public double[] makeCumulativeTestValues() { 60 return new double[] {0d, 0.0000d, 0.0001d, 0.0016d, 0.0106d, 0.0473d, 61 0.1503d, 0.3504d, 0.6172d, 0.8507d, 0.9718d, 1d, 1d}; 62 } 63 64 65 public double[] makeInverseCumulativeTestPoints() { 66 return new double[] {0, 0.001d, 0.010d, 0.025d, 0.050d, 0.100d, 0.999d, 67 0.990d, 0.975d, 0.950d, 0.900d,1}; 68 } 69 70 71 public int[] makeInverseCumulativeTestValues() { 72 return new int[] {-1, 1, 2, 3, 4, 4, 9, 9, 9, 8, 8, Integer.MAX_VALUE}; 73 } 74 75 77 78 public void testDegenerate0() throws Exception { 79 setDistribution(DistributionFactory.newInstance().createBinomialDistribution(5,0.0d)); 80 setCumulativeTestPoints(new int[] {-1, 0, 1, 5, 10 }); 81 setCumulativeTestValues(new double[] {0d, 1d, 1d, 1d, 1d}); 82 setDensityTestPoints(new int[] {-1, 0, 1, 10, 11}); 83 setDensityTestValues(new double[] {0d, 1d, 0d, 0d, 0d}); 84 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d}); 85 setInverseCumulativeTestValues(new int[] {-1, -1}); 86 verifyDensities(); 87 verifyCumulativeProbabilities(); 88 verifyInverseCumulativeProbabilities(); 89 } 90 91 92 public void testDegenerate1() throws Exception { 93 setDistribution(DistributionFactory.newInstance().createBinomialDistribution(5,1.0d)); 94 setCumulativeTestPoints(new int[] {-1, 0, 1, 2, 5, 10 }); 95 setCumulativeTestValues(new double[] {0d, 0d, 0d, 0d, 1d, 1d}); 96 setDensityTestPoints(new int[] {-1, 0, 1, 2, 5, 10}); 97 setDensityTestValues(new double[] {0d, 0d, 0d, 0d, 1d, 0d}); 98 setInverseCumulativeTestPoints(new double[] {0.1d, 0.5d}); 99 setInverseCumulativeTestValues(new int[] {4, 4}); 100 verifyDensities(); 101 verifyCumulativeProbabilities(); 102 verifyInverseCumulativeProbabilities(); 103 } 104 105 } 106 | Popular Tags |