Calculating Percolation Thresholds

I am kinda sorta following a great class on Coursera: Algorithms, Part I (Princeton University) and one of the interesting applications I learned about is the use of simulations to calculate percolation thresholds.

There are a lot more percolation models than the one they discuss in the course but the basic idea is that given a regular lattice of sites and rules for adjacencies between sites, if the sites are turned on independently with probability p there is a critical threshold value of p which is very interesting. Long-range connectivity is very difficult to establish at values of p below this threshold and very easy at values of p above it.

Nobody knows how to find these values analytically - if I understand correctly - but there is a computational method available: basically we set up a grid and start turning cells on until there is percolation i.e. a flow from top to bottom. The fraction of cells that are turned on when percolation is first achieved is an estimate for the percolation threshold. Carry out repeated experiments and the mean of these estimates should really close in on the threshold.

The course material comes into play by using a Union-find data structure to determine connectivity quickly.

I wrote some code to run experiments in-browser for this simple model. White squares represent sites that have been turned on or opened; two open sites that share a side are connected and it is possible for there to be a flow from one to the other; when there is a path of flow from the top of the grid to a cell, that cells becomes blue. As if water is making its way from the top of the grid.

Feel free to try different grid sizes and numbers of experiments (might bog down your browser). The answer should be around .5927 theoretically.

Grid Dimension:    # of Experiments:       Calculated Threshold: