Java program – Percolation probability estimate

by Nideesh C on April 29, 2011 · 0 comments

in Java Programming




public class Estimate {

    // do M trials and return fraction that percolate
    public static double eval(int N, double p, int M) {
        int count = 0;
        for (int k = 0; k < M; k++) {
            boolean[][] open = Percolation.random(N, p);
            if (Percolation.percolates(open))
                count++;
        }
        return (double) count / M;
    }

    public static void main(String[] args) {
        int    N = Integer.parseInt(args[0]);
        double p = Double.parseDouble(args[1]);
        int    M = Integer.parseInt(args[2]);
        double q = eval(N, p, M);
        StdOut.println(q);
    }
}


/*************************************************************************
 *  Execution:    java Estiamte N p trials
 *  Dependencies: Percolation.java StdOut.java
 *
 *  Repeatedly generated N-by-N boolean matrices, where each site
 *  is true with probability p, and compute the probability that
 *  the system percolates.
 *
 *  % java Estimate 32 .4 10000
 *
 *************************************************************************/

 

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Java program – Percolation scaffolding
  2. Java program – Visualization client
  3. Java program – Vertical percolation
  4. Java program – A simple filter
  5. Java program – Casting to get a random integer

Leave a Comment

Previous post:

Next post: