题注
这本来是我新浪博客中的一个文章,不过感觉技术博客还是在优快云中发表比较合适,以后优快云会是自己的领地了!把以前的一些有用的,阅读量比较多的博客搬过来,造福更多人吧~
转眼又到寒假了,话说我这简单的技术小博客一直没有更新呢~ 寒假有充足的时间给自己充电,整个寒假净忙着弄英语、看论文、写ReportReview,当然还有我自己最喜欢的:上Coursera的课程了~这个寒假总共注册了三门课程:Stanford《Introduction toDatabase》;Princeton《Algorithms partI》;以及一门和以后研究方向有关的《Health info inCloud》。对于Introduction toDatabase这门课来说,Stanford的作业量那真是超大…都贴常来我博客就爆了…不过我还是争取在闲余时间把那门课的InteractiveExercise的答案贴出来,供大家参考。Princeton的算法课程完全用Java写,这是我的最爱嘛~贴上来代码和大家分享一下,我觉得对于我和对于有兴趣阅读这一系列博客的人来说都会有帮助。
题目
Programming Assignment 1: Percolation
Write a program to estimate the value of the percolationthreshold via Monte Carlo simulation.
Percolation. Given a composite systems comprised ofrandomly distributed insulating and metallic materials: whatfraction of the materials need to be metallic so that the compositesystem is an electrical conductor? Given a porous landscape withwater on the surface (or oil below), under what conditions will thewater be able to drain through to the bottom (or the oil to gushthrough to the surface)? Scientists have defined an abstractprocess known aspercolation to model such situations.
The model. We model a percolation system using anN-by-N grid ofsites. Each site iseitheropen or blocked. A full site isan open site that can be connected to an open site in the top rowvia a chain of neighboring (left, right, up, down) open sites. Wesay the systempercolates if there is a full site in thebottom row. In other words, a system percolates if we fill all opensites connected to the top row and that process fills some opensite on the bottom row. (For the insulating/metallic materialsexample, the open sites correspond to metallic materials, so that asystem that percolates has a metallic path from top to bottom, withfull sites conducting. For the porous substance example, the opensites correspond to empty space through which water might flow, sothat a system that percolates lets water fill open sites, flowingfrom top to bottom.)

The problem. In a famous scientific problem, researchersare interested in the following question: if sites areindependently set to be open with probabilityp (andtherefore blocked with probability 1 −p), what is theprobability that the system percolates? Whenp equals 0,the system does not percolate; whenp equals 1, the systempercolates. The plots below show the site vacancy probabilityp versus the percolation probability for 20-by-20 randomgrid (left) and 100-by-100 random grid (right).
