Lab Exercises (lab05)


Exercise 1.

Intro to Markov Chain Monte Carlo.

Write a 1-D MCMC code that realizes samples of a normal, zero-mean variate x. (That is, the PDF of x is p(x)~exp(-0.5*x**2).) Plot a histogram of n=10000 samples to confirm that they are distributed as expect.

Exercise 2.

MCMC in 2-d.

Generate MCMC samples (x_i,y_i) for PDF p(x,y)~exp(-0.5*r*Cinv*r) where is vector r=(x,y) and Cinv is the inverse of the covariance matrix C=[[sxx,sxy],[sxy,syy]). Let variances sxx=syy=1 and chose sxy=0.7. Make a scatter plot, also a 2-d histogram to confirm that the samples are distributed as expected.

Exercise 3.

Repeat the above exercise with the emcee MCMC package.