Skip to content

Commit 38843c8

Browse files
committed
chapter 4 of rmt (4.1 and 4.2)
1 parent 224e060 commit 38843c8

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

demos/book/3/.gitignore

Whitespace-only changes.

demos/book/4/cauchymp.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#achchymp.jl
2+
#Algorithm 4.1 of Random Eigenvalues by Alan Edelman
3+
4+
#Experiment: Calculate Cauchy transform as trace of resolvent of Wishart matrix
5+
#Theory: Marcenko-Pastur law
6+
7+
m = 2000 # larger dimension of matrix
8+
n = 1000 # smaller dimension of matrix
9+
r = n/m # aspect ratio
10+
a = (1-sqrt(r))^2
11+
b = (1+sqrt(r))^2
12+
z = 3 # should be outside [a,b]
13+
X = randn(m,n)
14+
W = X'*X/m # Generate Wishart matrix
15+
println(( trace(inv(z*eye(n)-W))/n,
16+
(z-1+r-sqrt((z-a)*(z-b)))/(2*r*z) ))

demos/book/4/mpexperiment.jl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#mpexperiment.jl
2+
#Algorithm 4.2 of Random Eigenvalues by Alan Edelman
3+
4+
#Experiment: Marcenko-Pastur for applications
5+
#Plot: Histogram eigenvalues of the covariance matrix
6+
#Theory: Marcenko-Pastur as n->Infinity
7+
8+
## Parameters
9+
t = 100 # trials
10+
r = 1 # aspect ratio
11+
n = 100 # matrix column size
12+
dx = 0.1 # binsize
13+
14+
function mp_experiment()
15+
m = iround(n/r)
16+
## Experiment
17+
v = Float64[] # eigenvalue samples
18+
for i = 1:t
19+
A = randn(m,n) + 4*sqrt(n)*diagm(((1:n).<10))
20+
A = A + sqrt(n) * diagm((1:n).>(n-1)) * 3 #3+0.1*randn(n,1) #3/sqrt(n)
21+
append!(v, svd(A)[2]) # eigenvalues
22+
end
23+
v = v / sqrt(m) # normalized eigenvalues
24+
## Theory
25+
a = 1-sqrt(r)
26+
b = 10
27+
x = a-dx/2:dx:b
28+
y = real(sqrt((x.^2-a^2).*(2^2-x.^2) + 0im)./(pi*x*r))
29+
return (hist(v, x), (x, y))
30+
end
31+
((grid, count), (x,y)) = mp_experiment()
32+
33+
## Plot
34+
using Winston
35+
p = FramedPlot()
36+
h = Histogram(count/(t*n*dx), step(grid))
37+
h.x0 = first(grid)
38+
add(p, h)
39+
add(p, Curve(x, y, "linewidth", 2, "color", "blue"))
40+
last = length(count)-2
41+
while count[last] == 0
42+
last -= 1
43+
end
44+
setattr(p, "xrange", (0, grid[last+2]))
45+
setattr(p, "yrange", (-.1, ceil(max(count/(t*n*dx)))))
46+
if isinteractive()
47+
Winston.display(p)
48+
else
49+
file(p, "mpexperiment.png")
50+
end

0 commit comments

Comments
 (0)