// 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));
 }
示例#2
0
 public double stddev() {
   return StdStats.stddev(this.results);
 }
示例#3
0
 public double mean() {
   return StdStats.mean(this.results);
 }
 // sample standard deviation of percolation threshold
 public double stddev() {
   if (results.length <= 1) return Double.NaN;
   return StdStats.stddev(results);
 }
 public double stddev() {
   return StdStats.stddev(threshold);
 }
 public double mean() {
   return StdStats.mean(threshold);
 }
 /** Returns the sample standard deviation of the percolation threshold */
 public double stddev() {
   if (thresholds.length <= 1) {
     return Double.NaN;
   }
   return StdStats.stddev(thresholds);
 }
示例#8
0
 // sample mean of percolation threshold
 public double mean() {
   if (T == 1) return threshold[0];
   else {
     return StdStats.mean(threshold);
   }
 }