|
| 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