Skip to content

Commit 6fd2e86

Browse files
committed
draft of README for book demos
1 parent ecd1eba commit 6fd2e86

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

demos/book/README

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
The codes in this folder are translations of MATLAB code by Alan Edelman in his book "Random Eigenvalues" to Julia v0.2. Cross-referencing between these codes and the book can be done by folder number / file name and the comments at the top of each file that identify its counterpart in the book. The translation was done by Jeff Bezanson, Jiahao Chen, and Jameson Nash. d
2+
3+
It is intended that these codes can be run in batch mode to generate the sample figures as output files, but that the codes are most useful when used interactively in the exploration of random matrix theory. For this reason, when run from the Julia REPL, the plots will be output to the screen.
4+
5+
Additional codes should use the following template (modified from book/4/mpexperiment.jl). While some experiments will need to be single-threaded, many codes in Random Matrix Theory are Monte Carlo simulations which are trivial to parallelize using the pmap function. To make use of the parallelism this provides, either start Julia with the `-p N` flag or run `addprocs(N-1)` at the REPL (where N>=3 and equals CPU_CORES+1 optimally). When doing Julia-level parallelism, it is typically best to disable OpenBLAS parallelism by calling `Base.openblas_set_num_threads(1)`.
6+
7+
```julia
8+
#<filename>.jl
9+
#Algorithm <X.X> of Random Eigenvalues by Alan Edelman
10+
11+
#Experiment: Explain what theory or principle is being demonstrated
12+
#Plot: Indicate what to expect the plot to contain
13+
#Theory: Mention what mathematical concept is being applied
14+
15+
## Parameters # Include the most interesting configurable values at the top, with brief descriptions
16+
t = 10000 # trials
17+
n = 100 # matrix column size
18+
dx = 0.1 # binsize
19+
20+
function mp_experiment(t,n,dx) # wrap the experimental logic in a function to enable faster JIT
21+
## Experiment
22+
23+
#Single threaded experiment
24+
# v = Float64[]
25+
# for i = 1:t
26+
# append!(v, <new values>)
27+
# end
28+
29+
#Parallel experiment
30+
v = pmap((i)->(<new value>), 1:t)
31+
# v = vcat(pmap((i)->(<vector of new values>), 1:t)...)
32+
33+
## Theory
34+
x = -2:dx:2
35+
y = x .^ 2
36+
return (hist(v, x), (x, y))
37+
end
38+
((grid, count), (x,y)) = mp_experiment(t,n,dx) #run the experiment, making the global variables local for speed
39+
40+
## Plot
41+
using Winston
42+
p = FramedPlot()
43+
44+
h = Histogram(count/(sum(count)*step(grid)), step(grid)) # add the histogram of data
45+
h.x0 = first(grid)
46+
add(p, h)
47+
48+
add(p, Curve(x, y, "linewidth", 2, "color", "blue")) # overlay the theory
49+
50+
if isinteractive()
51+
Winston.display(p)
52+
else
53+
file(p, "<filename>.png")
54+
end
55+
```

0 commit comments

Comments
 (0)