Skip to content

Commit 141cb17

Browse files
committed
chapter 8 of RMT (8.1 to 8.4) random growth models
1 parent fde5bea commit 141cb17

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

demos/book/8/randomgrowth.jl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#randomgrowth.jl
2+
using Winston
3+
4+
function random_growth(M, N, q)
5+
G = zeros(M, N)
6+
T = 1000
7+
8+
G[1,1] = true
9+
# update the possible sets
10+
imagesc((0,N), (M,0), G)
11+
for t = 1:T
12+
sets = next_possible_squares(G)
13+
## Highlights all the possible squares
14+
for i = 1:length(sets)
15+
idx = sets[i]::(Int,Int)
16+
G[idx[1], idx[2]] = 0.25
17+
end
18+
imagesc((0,N), (M,0), G)
19+
sleep(.01)
20+
21+
## Actual growth
22+
for i = 1:length(sets)
23+
ison = 0.5 * (rand() > (1-q))
24+
if ison > 0
25+
idx = sets[i]::(Int,Int)
26+
G[idx[1], idx[2]] = ison
27+
end
28+
end
29+
imagesc((0,N), (M,0), G)
30+
G[G .== 0.5] = 1
31+
G[G .== 0.25] = 0
32+
sleep(.01)
33+
end
34+
G
35+
end
36+
37+
function next_possible_squares(G)
38+
M, N = size(G)::(Int,Int)
39+
sets = Array((Int,Int),0)
40+
for ii = 1:M
41+
for jj = 1:N
42+
if G[ii, jj] == 0
43+
if (ii == 1 && jj > 1 && G[ii, jj-1] == 1) ||
44+
(jj == 1 && ii > 1 && G[ii-1, jj] == 1) ||
45+
(ii > 1 && jj > 1 && G[ii-1, jj] == 1 && G[ii, jj-1] == 1)
46+
push!(sets, (ii,jj))
47+
end
48+
end
49+
end
50+
end
51+
sets
52+
end

demos/book/8/randomgrowth2.jl

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#randomgrowth2.jl
2+
using Winston
3+
using ODE
4+
include("../1/gradient.jl")
5+
6+
function randomgrowth2()
7+
num_trials = 2000
8+
g = 1
9+
q = 0.7
10+
Ns = 80 # [50, 100, 200]
11+
# [-1.771086807411 08131947928329]
12+
# Gap = c d^N
13+
for jj = 1:length(Ns)
14+
N = Ns[jj]
15+
M = round(N*g)
16+
B = zeros(num_trials)
17+
@time begin
18+
for ii = 1:num_trials
19+
# G = G[M, N, q]
20+
# B[ii] = G[M,N]
21+
B[ii] = G(M, N, q)
22+
end
23+
end
24+
C = (B - N*om(g,q)) / (sigma_growth(g,q)*N^(1/3))
25+
d = 0.2
26+
x, n = hist(C - exp(-N*0.0025 - 3), -6:d:4)
27+
p = FramedPlot()
28+
h = Histogram(n/(d*num_trials), step(x))
29+
h.x0 = first(x)
30+
add(p, h)
31+
32+
## Theory
33+
t0 = 4
34+
tn = -6
35+
dx = 0.005
36+
deq = (t, y) -> [y[2]; t*y[1]+2*y[1]^3; y[4]; y[1]^2]
37+
y0 = [airy(t0); airy(1,t0); 0; airy(t0)^2] # boundary conditions
38+
t, y = ode23(deq, t0:-dx:tn, y0) # solve
39+
F2 = exp(-y[:,3]) # the distribution
40+
f2 = gradient(F2, t) # the density
41+
42+
add(p, Curve(t, f2, "color", "red", "linewidth", 3))
43+
Winston.display(p)
44+
println(mean(C))
45+
end
46+
end
47+
48+
function G(N, M, q)
49+
# computes matrix G[N,M] for a given q
50+
GG = floor(log(rand(N,M))/log(q))
51+
#float(rand(N,M) < q)
52+
53+
# Compute the edges: the boundary
54+
for ii = 2:N
55+
GG[ii, 1] = GG[ii, 1] + GG[ii-1, 1]
56+
GG[1, ii] = GG[1, ii] + GG[1, ii-1]
57+
end
58+
# Compute the inside
59+
for ii = 2:N
60+
for jj = 2:M
61+
GG[ii, jj] = GG[ii, jj] + max(GG[ii, jj-1], GG[ii-1, jj])
62+
end
63+
end
64+
## Plot
65+
# imagesc((0,N),(M,0),GG)
66+
# sleep(.01)
67+
68+
return GG[N, M]
69+
end
70+
71+
# helper functions sigma.m and om, which describe mean and
72+
# standard deviation of G[N, M]
73+
74+
# Computes G[qN,N]/N for N->inf
75+
om(g,q) = ((1 + sqrt(g * q)) ^ 2) / (1 - q) - 1
76+
77+
sigma_growth(r, q) =
78+
q^(1/6) * r^(1/6) / (1 - q) *
79+
(sqrt(r) + sqrt(q))^(2/3) *
80+
(1 + sqrt(q * r))^(2/3)
81+
82+
83+
randomgrowth2()

0 commit comments

Comments
 (0)