// CS 1538 Fall 2009 // This handout implements the "Maximum-of-t Test" as explained in Knuth p. 70. // See notes for more information on the process. import java.util.*; public class MaxT { public static void main(String [] args) { int n = Integer.parseInt(args[0]); int t = Integer.parseInt(args[1]); int alphaInd = Integer.parseInt(args[2]); double [] alphas = {0.1, 0.05, 0.01}; double alpha = alphas[alphaInd]; if (n % t != 0) { System.out.println("n must be a multiple of t"); System.exit(0); } int points = n/t; double [] max_of_T1 = new double[points+1]; double [] max_of_T2 = new double[points+1]; double [] max_of_T3 = new double[points+1]; long seed = System.currentTimeMillis(); Random R1 = new Random(seed); Rand2 R2 = new Rand2(seed); Rand2 R3 = new Rand2(seed); for (int i = 1; i <= points; i++) { double max1 = R1.nextDouble(); double max2 = R2.nextDouble(); double max3 = R3.nextDouble32(); for (int j = 1; j < t; j++) { double curr1 = R1.nextDouble(); double curr2 = R2.nextDouble(); double curr3 = R3.nextDouble32(); if (curr1 > max1) max1 = curr1; if (curr2 > max2) max2 = curr2; if (curr3 > max3) max3 = curr3; } max_of_T1[i] = max1; max_of_T2[i] = max2; max_of_T3[i] = max3; } max_of_T1[0] = 0.0; max_of_T2[0] = 0.0; max_of_T3[0] = 0.0; for (int i = 1; i < points; i++) { max_of_T1[i] = Math.pow(max_of_T1[i], t); max_of_T2[i] = Math.pow(max_of_T2[i], t); max_of_T3[i] = Math.pow(max_of_T3[i], t); } Arrays.sort(max_of_T1); Arrays.sort(max_of_T2); Arrays.sort(max_of_T3); double D1plus = 0.0; double D1minus = 0.0; double D2plus = 0.0; double D2minus = 0.0; double D3plus = 0.0; double D3minus = 0.0; for (int i = 1; i < points; i++) { double curr = ((double)i/points) - max_of_T1[i]; if (curr > D1plus) D1plus = curr; curr = max_of_T1[i] - ((double)(i-1)/points); if (curr > D1minus) D1minus = curr; curr = ((double)i/points) - max_of_T2[i]; if (curr > D2plus) D2plus = curr; curr = max_of_T2[i] - ((double)(i-1)/points); if (curr > D2minus) D2minus = curr; curr = ((double)i/points) - max_of_T3[i]; if (curr > D3plus) D3plus = curr; curr = max_of_T3[i] - ((double)(i-1)/points); if (curr > D3minus) D3minus = curr; } double D1 = Math.max(D1plus, D1minus); double D2 = Math.max(D2plus, D2minus); double D3 = Math.max(D3plus, D3minus); double critVal = 0.0; if (alphaInd == 0) critVal = 1.22/(Math.sqrt(points)); else if (alphaInd == 1) critVal = 1.36/(Math.sqrt(points)); else critVal = 1.63/(Math.sqrt(points)); System.out.println("Results from Max_of_T test:\n"); System.out.println("Values generated (n) = " + n); System.out.println("Value of t = " + t); System.out.println("Degrees of freedom = " + points); System.out.println("Level of significance (alpha) = " + alpha); System.out.println("Critical value = " + critVal); System.out.println(); System.out.println("Max D for R1 = " + D1); if (D1 < critVal) System.out.println("R1 passed the test"); else System.out.println("R1 failed the test"); System.out.println(); System.out.println("Max D for R2 = " + D2); if (D2 < critVal) System.out.println("R2 passed the test"); else System.out.println("R2 failed the test"); System.out.println(); System.out.println("Max D for R3 = " + D3); if (D3 < critVal) System.out.println("R3 passed the test"); else System.out.println("R3 failed the test"); } }