パーコレーションのシミュレーションで一番面倒かつ難しいのはサイト同士がどこまで繋がっているかを判定することだと思いますが、Images.jlのなかにある label_components を使うと一瞬で終わります。本来は画像処理のために使う物なのでしょうがパーコレーションのシミュレーションにも使えます。ただし、周期的境界条件でシミュレーションしたい場合には使えません。
using Images, Plots; gr() "n: matrix size" function percolation(n::Integer; niter=100, width=0.05) ps = 0:width:1 nhit = zeros(Int, length(ps)) for (idx, p) in enumerate(ps) for iter in 1:niter site = rand(n,n) .< p site = label_components(site) if ! isempty(setdiff((Set(site[1,:]) ∩ Set(site[n,:])) ∪ (Set(site[:,1]) ∩ Set(site[:,n])), 0)) nhit[idx] += 1 end end end return ps, nhit / niter end plot(percolation(100, width=0.01), xlabel="concentration", ylabel="probability", legend=false) savefig("percolation.png")
正方格子のサイトパーコレーションの臨界点の値はだいたい0.6弱なのでいい感じ。