In this exercise you will familiarize yourself with the Method Marko Chain Monte Carlo (Metropolis Hastings algorithm). You should use similar analysis to validate your own MCMC algorithm.

Step 1: Download the demo function made available through Mathworks File Exchange.

  1. https://www.mathworks.com/matlabcentral/fileexchange/34812-metropolis-hastings?focused=5215352&tab=function

Step 2: Run the script metropolis_hastings.m

  1. Note the frequency of generated samples. Which samples are generated more frequently?
  2. Note the fit of the generated histogram and the probability density.

Step 3: Run the script metropolis_hastings2.m. It will take a while to execute.

  1. Note how the algorithm samples a 2D distribution. Note the differences in acceptance rates.
  2. Important. Note the autocorrelation function. How many samples should be discarded and why?