Skip to content

Commit 1656a7e

Browse files
committed
chapter 6 of rmt (5.6 to 5.8)
1 parent dcea45b commit 1656a7e

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

demos/book/5/finitesemi.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#finitesemi.jl
2+
#Algorithm 5.6 of Random Eigenvalues by Alan Edelman
3+
4+
#Experiment: Eigenvalues of GUE matrices
5+
#Plot: Histogram of eigenvalues
6+
#Theory: Semicircle and finite semicircle
7+
8+
## Parameters
9+
n = 3 # size of matrix
10+
s = 10000 # number of samples
11+
d = 0.1 # bin size
12+
13+
## Experiment
14+
function finitesemi_experiment(n,s,d)
15+
e = Float64[]
16+
for i = 1:s
17+
a = randn(n,n)+im*randn(n,n)
18+
a = (a+a')/(2*sqrt(4n))
19+
v = eigvals(a)
20+
append!(e, v)
21+
end
22+
return hist(e, -1.5:d:1.5)
23+
end
24+
grid, count = finitesemi_experiment(n,s,d)
25+
26+
## Theory
27+
x = -1:0.01:1
28+
y = sqrt(1-x.^2)
29+
30+
## Plot
31+
using Winston
32+
p = FramedPlot()
33+
h = Histogram(count*pi/(2*d*n*s), step(grid))
34+
h.x0 = first(grid)
35+
add(p, h)
36+
add(p, Curve(x, y, "color", "red", "linewidth", 2))
37+
include("levels.jl")
38+
add(p, Curve(levels(n)..., "color", "blue", "linewidth", 2))
39+
if isinteractive()
40+
Winston.display(p)
41+
else
42+
file(p, "spherecomponent.png")
43+
end
44+

demos/book/5/levels.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#levels.jl
2+
#Algorithm 5.7 of Random Eigenvalues by Alan Edelman
3+
4+
function levels(n)
5+
# Plot exact semicircle formula for GUE
6+
# This is given in formula (5.2.16) in Mehta as the sum of phi_j^2
7+
# but Christoffel-Darboux seems smarter
8+
## Parameter
9+
# n: Dimension of matrix for which to determine exact semicircle
10+
x = (-1:0.001:1) * sqrt(2n) * 1.3
11+
pold = zeros(size(x)) # -1st Hermite Polynomial
12+
p = ones(size(x)) # 0th Hermite Polynomial
13+
k = p
14+
for j = 1:n # Compute the three-term recurrence
15+
pnew = (sqrt(2) * x .* p - sqrt(j - 1) * pold) / sqrt(j)
16+
pold = p
17+
p = pnew
18+
end
19+
pnew = (sqrt(2) * x .* p - sqrt(n) * pold)/sqrt(n + 1)
20+
21+
k = n * p .^ 2 - sqrt(n * (n+1)) * pnew .* pold # Use p.420 of Mehta
22+
k = k .* exp(-x .^ 2) / sqrt(pi) # Normalize
23+
24+
# Rescale so that "semicircle" is on [-1, 1] and area is pi/2
25+
(x / sqrt(2n), k * pi / sqrt(2n))
26+
end
27+

demos/book/5/levels2.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#levels2.jl
2+
#Algorithm 5.8 of Random Eigenvalues by Alan Edelman
3+
4+
function levels2(n)
5+
# Plot exact semicircle formula for GUE
6+
xfull = (-1:0.001:1) * sqrt(2n) * 1.3
7+
8+
# Form the T matrix
9+
T = diagm(sqrt(1:n-1),1)
10+
T = T + T'
11+
12+
# Do the eigen-decomposition of T, T = UVU'
13+
V, U = eig(T)
14+
15+
# Precompute U'*e_n
16+
# tmp_en = U' * ((0:n-1) == n-1)'
17+
tmp_en = U[end, :]'
18+
19+
y = Array(Float64, length(xfull))
20+
for i = 1:length(xfull)
21+
x = xfull[i]
22+
# generate the v vector as in (2.5)
23+
v = U * (tmp_en ./ (V - sqrt(2) * x))
24+
# multiply the normalization term
25+
y[i] = norm((sqrt(pi)) ^ (-1/2) * exp(-x^2/2) * v/v[1])^2
26+
end
27+
28+
# Rescale so that "semicircle" is on [-1, 1] and area is pi/2
29+
(xfull/sqrt(2n), y * pi / sqrt(2n))
30+
end

0 commit comments

Comments
 (0)