Please download Demonstration program (perl) (save as demo.p) and Xdefaults file (save as Xdefaults.gnu). The latter is not essential, but improves the appearance.
xrdb -load Xdefaults.gnu
demo.pThis program writes output to your terminal (24 lines recommended) and also creates a load of files for gnuplot to plot.
It shows a metropolis method simulation of a
system with 21 states. The target distribution
is uniform. The proposal density is 0.5,0.5 over the two adjacent
states left and right.
Rejections only occur when proposals take the state off the end.
Notice how long it takes to reach an end-state.
And then how long it takes to reach the other end-state.
Simple monte carlo methods, even in one dimension, take a huge time to converge and a huge time to generate independent samples.
gnuplot load 'gnucom'This will show how the histogram evolves during the simulation you have seen.