functioncat_map(N) U =zeros(N) ϕ =zeros(N) U[1], ϕ[1] =rand(Uniform(0, 1), 2)for i =2:N ϕ[i] =rem(U[i-1] +2* ϕ[i-1], 1.0) U[i] =rem(U[i-1] + ϕ[i-1], 1.0)endreturn UendN =1_000Z =cat_map(N)U =rand(MersenneTwister(1), N) # Mersenne Twister is not the default in Julia, but is in other languages, so using it here by explicitly setting it as the generatorp1 =scatter(Z[1:end-1], Z[2:end], xlabel=L"$U_t$", ylabel=L"$U_{t+1}$", title="Cat Map", label=false, size=(500, 500))p2 =scatter(U[1:end-1], U[2:end], xlabel=L"$U_t$", ylabel=L"$U_{t+1}$", title="Mersenne Twister", label=false, size=(500, 500))display(p1)display(p2)
(a) Comparison of the Arnold cat map and output from the Mersenne Twister
(b)
Figure 8
Random Seeds
Pseudo-random numbers are deterministic, so can be repeated. The sequence depends on a seed.
If you don’t set a seed explicitly, the computer will choose one (usually based on the date/time stamp when you execute the script or program).
Setting a seed resets the sequence.
Set seeds to ensure reproducibility.
But…Be Careful With Seeds
Possible for a statistical procedure to appear to work with just one seed; test across several.
Seeds may match, but RNG algorithm may be different across different languages/versions.
Key Points and Upcoming Schedule
Key Points: Bayesian Statistics
Use prior predictive simulations to refine priors.
Priors matter less when likelihood is highly informative.
Key Points: Random Numbers
Can generate uniform distributions using pseudorandom number generators (unstable dynamical systems).
Transform into other distributions using:
Quantile method;
Rejection method.
Default functions work well; only really have to worry about any of this when sampling from “non-nice” distributions
Upcoming Schedule
Next Classes
Next Week: Monte Carlo Simulation and the Bootstrap
Term Project
Can work in groups of 1-2
Proposal due 3/21.
Max three pages, should include background and problem statement, data overview, proposed probability models, and research plan.
Deliverables include presentations (in class, last 2-3 sessions) and written report (during finals week).