3131/**
3232 * @author Kevin Lang
3333 */
34+ @ SuppressWarnings ("javadoc" )
3435public class BinomialBoundsNTest {
3536
3637 public static double [] runTestAux (long max_numSamplesI , int ci , double min_p ) {
@@ -41,54 +42,54 @@ public static double[] runTestAux (long max_numSamplesI, int ci, double min_p) {
4142 double sum3 = 0.0 ;
4243 double sum4 = 0.0 ;
4344 long count = 0 ;
44-
45+
4546 while (numSamplesI <= max_numSamplesI ) { /* was <= */
4647 p = 1.0 ;
47-
48+
4849 while (p >= min_p ) {
4950 lb = BinomialBoundsN .getLowerBound (numSamplesI , p , ci , false );
5051 ub = BinomialBoundsN .getUpperBound (numSamplesI , p , ci , false );
51-
52+
5253 // if (numSamplesI == 300 && p > 0.365 && p < 0.367) { ub += 0.01; } // artificial discrepancy
53-
54+
5455 // the logarithm helps discrepancies to not be swamped out of the total
55- sum1 += Math .log (lb + 1.0 );
56+ sum1 += Math .log (lb + 1.0 );
5657 sum2 += Math .log (ub + 1.0 );
5758 count += 2 ;
58-
59+
5960 if (p < 1.0 ) {
6061 lb = BinomialBoundsN .getLowerBound (numSamplesI , 1.0 - p , ci , false );
6162 ub = BinomialBoundsN .getUpperBound (numSamplesI , 1.0 - p , ci , false );
6263 sum3 += Math .log (lb + 1.0 );
6364 sum4 += Math .log (ub + 1.0 );
6465 count += 2 ;
6566 }
66-
67+
6768 p *= 0.99 ;
6869 }
69- numSamplesI = Math .max (numSamplesI +1 , 1001 *numSamplesI /1000 );
70+ numSamplesI = Math .max (numSamplesI +1 , ( 1001 *numSamplesI ) /1000 );
7071 }
71-
72+
7273 println (String .format ("{%.15e, %.15e, %.15e, %.15e, %d}" , sum1 , sum2 , sum3 , sum4 , count ));
7374 double [] arrOut = {sum1 , sum2 , sum3 , sum4 , count };
7475 return arrOut ;
7576 }
76-
77+
7778 private static final double TOL = 1E-15 ;
78-
79+
7980 @ Test
8081 public static void checkBounds () {
8182 int i = 0 ;
8283 for (int ci = 1 ; ci <= 3 ; ci ++, i ++) {
8384 double [] arr = runTestAux (20 , ci , 1e-3 );
8485 for (int j =0 ; j <5 ; j ++) {
85- assertTrue ((arr [j ] / std [i ][j ] -1.0 ) < TOL );
86+ assertTrue ((( arr [j ] / std [i ][j ]) -1.0 ) < TOL );
8687 }
8788 }
8889 for (int ci = 1 ; ci <= 3 ; ci ++, i ++) {
8990 double [] arr = runTestAux (200 , ci , 1e-5 );
9091 for (int j =0 ; j <5 ; j ++) {
91- assertTrue ((arr [j ] / std [i ][j ] -1.0 ) < TOL );
92+ assertTrue ((( arr [j ] / std [i ][j ]) -1.0 ) < TOL );
9293 }
9394 }
9495 //comment last one out for a shorter test
@@ -99,22 +100,22 @@ public static void checkBounds() {
99100// }
100101// }
101102 }
102-
103+
103104 // With all 3 enabled the test should produce in groups of 3 */
104105 private static final double [][] std = {
105106 {7.083330682531043e+04 , 8.530373642825481e+04 , 3.273647725073409e+04 , 3.734024243699785e+04 , 57750 },
106107 {6.539415269641498e+04 , 8.945522372568645e+04 , 3.222302546497840e+04 , 3.904738469737429e+04 , 57750 },
107108 {6.006043493107306e+04 , 9.318105731423477e+04 , 3.186269956585285e+04 , 4.096466221922520e+04 , 57750 },
108-
109+
109110 {2.275584770163813e+06 , 2.347586549014998e+06 , 1.020399409477305e+06 , 1.036729927598294e+06 , 920982 },
110111 {2.243569126699713e+06 , 2.374663344107342e+06 , 1.017017233582122e+06 , 1.042597845553438e+06 , 920982 },
111112 {2.210056231903739e+06 , 2.400441267999687e+06 , 1.014081235946986e+06 , 1.049480769755676e+06 , 920982 },
112-
113+
113114 {4.688240115809608e+07 , 4.718067204619278e+07 , 2.148362024482338e+07 , 2.153118905212302e+07 , 12834414 },
114115 {4.674205938540214e+07 , 4.731333757486791e+07 , 2.146902141966406e+07 , 2.154916650733873e+07 , 12834414 },
115116 {4.659896614422579e+07 , 4.744404182094614e+07 , 2.145525391547799e+07 , 2.156815612325058e+07 , 12834414 }
116117 };
117-
118+
118119 @ Test
119120 public static void checkCheckArgs () {
120121 try {
@@ -129,7 +130,7 @@ public static void checkCheckArgs() {
129130 //pass
130131 }
131132 }
132-
133+
133134 @ Test
134135 public static void checkComputeApproxBino_LB_UB () {
135136 long n = 100 ;
@@ -143,12 +144,12 @@ public static void checkComputeApproxBino_LB_UB() {
143144 result = getUpperBound (n , theta , 1 , true );
144145 assertEquals (result , 0.0 , 0.0 );
145146 }
146-
147+
147148 @ Test (expectedExceptions = SketchesArgumentException .class )
148149 public static void checkThetaLimits1 () {
149150 BinomialBoundsN .getUpperBound (100 , 1.1 , 1 , false );
150151 }
151-
152+
152153 @ Test
153154 public static void boundsExample () {
154155 println ("BinomialBoundsN Example:" );
@@ -164,17 +165,17 @@ public static void boundsExample() {
164165 println ("LB: " +lb );
165166 println ("" );
166167 }
167-
168+
168169 @ Test
169170 public void printlnTest () {
170171 println ("PRINTING: " +this .getClass ().getName ());
171172 }
172-
173+
173174 /**
174- * @param s value to print
175+ * @param s value to print
175176 */
176177 static void println (String s ) {
177178 //System.out.println(s); //disable here
178179 }
179-
180+
180181}
0 commit comments