// perform T independent computational // experiments on an N-by-N grid public PercolationStats(int N, int T) { if ((N <= 0) || (T <= 0)) throw new java.lang.IllegalArgumentException(); int gridSize = N * N; double[] samples = new double[T]; for (int i = 0; i < T; i++) { Percolation pcl = new Percolation(N); int openCount = 0; while ((!pcl.percolates()) && (openCount < gridSize)) { int row = StdRandom.uniform(1, N + 1); int col = StdRandom.uniform(1, N + 1); if (!pcl.isOpen(row, col)) { pcl.open(row, col); openCount++; } } samples[i] = (double) openCount / (double) gridSize; } mean = StdStats.mean(samples); stddev = StdStats.stddev(samples); confLo = mean - 1.96 * stddev / (Math.sqrt((double) T)); confHi = mean + 1.96 * stddev / (Math.sqrt((double) T)); }
public double mean() { return StdStats.mean(this.results); }
public double mean() { return StdStats.mean(threshold); }
// sample mean of percolation threshold public double mean() { if (T == 1) return threshold[0]; else { return StdStats.mean(threshold); } }