Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

percolationstats.java Can anyone help me finish the code? import stdlib.StdOut; import stdlib.StdRandom; import stdlib.StdStats; //percolationStats.java public class PercolationStats { private int m; private double[] x;

percolationstats.java Can anyone help me finish the code? import stdlib.StdOut; import stdlib.StdRandom; import stdlib.StdStats; //percolationStats.java public class PercolationStats { private int m; private double[] x; // Performs m independent experiments on an n x n percolation system. public PercolationStats(int n, int m) { // Returns sample mean of percolation threshold. public double mean() { } // Returns sample standard deviation of percolation threshold. public double stddev() { } // Returns low endpoint of the 95% confidence interval. public double confidenceLow() { } // Returns high endpoint of the 95% confidence interval. public double confidenceHigh() { } // Unit tests the data type. [DO NOT EDIT] public static void main(String[] args) { int n = Integer.parseInt(args[0]); int m = Integer.parseInt(args[1]); PercolationStats stats = new PercolationStats(n, m); StdOut.printf("Percolation threshold for a %d x %d system: ", n, n); StdOut.printf(" Mean = %.3f ", stats.mean()); StdOut.printf(" Standard deviation = %.3f ", stats.stddev()); StdOut.printf(" Confidence interval = [%.3f, %.3f] ", stats.confidenceLow(), stats.confidenceHigh()); } import stdlib.StdOut; import stdlib.StdRandom; import stdlib.StdStats; //percolationStats.java public class PercolationStats { private int m; private double[] x; // Performs m independent experiments on an n x n percolation system. public PercolationStats(int n, int m) { if (n <= 0 || m <= 0) { throw new IllegalArgumentException("Illegal n"); } this.m = m; this.x = new double[m]; for (int i = 0; i < m; i++) { int count = 0; Percolation percolation = new ArrayPercolation(m); while (!percolation.percolates()) { int x, y; do { x = StdRandom.uniform(n) + 1; y = StdRandom.uniform(n) + 1; } while (percolation.isOpen(x,y)); percolation.open(x,y); count++; } x[i] = (double) count / n / n; } } // Returns sample mean of percolation threshold. public double mean() { return StdStats.mean(x); } // Returns sample standard deviation of percolation threshold. public double stddev() { return StdStats.stddev(x); } // Returns low endpoint of the 95% confidence interval. public double confidenceLow() { return StdStats.mean(x) - 1.96 * StdStats.stddev(x) / Math.sqrt(m); } // Returns high endpoint of the 95% confidence interval. public double confidenceHigh() { return StdStats.mean(x) + 1.96 * StdStats.stddev(x) / Math.sqrt(m); } // Unit tests the data type. [DO NOT EDIT] public static void main(String[] args) { int n = Integer.parseInt(args[0]); int m = Integer.parseInt(args[1]); PercolationStats stats = new PercolationStats(n, m); StdOut.printf("Percolation threshold for a %d x %d system: ", n, n); StdOut.printf(" Mean = %.3f ", stats.mean()); StdOut.printf(" Standard deviation = %.3f ", stats.stddev()); StdOut.printf(" Confidence interval = [%.3f, %.3f] ", stats.confidenceLow(), stats.confidenceHigh()); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

answer fastly please 2 0 8 . What is a photodisintegration?

Answered: 1 week ago