python - Ignoring samples in Gibbs sampling -
import random,math def gibbs(n=50000,thin=1000): x=0 y=0 print "iter x y" in range(n): j in range(thin): x=random.gammavariate(3,1.0/(y*y+4)) y=random.gauss(1.0/(x+1),1.0/math.sqrt(2*x+2)) print i,x,y gibbs()
the above python code gibbs sampling , following line confuses me.
for j in range(thin):
what significance of additional inner loop?
the reason seems introduction of thinning gibbs sampling. thinning used reduce effect of correlation between consecutive samples. gibbs sampling generates markov chain of samples , nearby samples correlated, while typically intention draw samples independent.
to achieve that, can use every m-th
value, while ignoring intermediate values. in case m
stored in variable thinning
, taking every thinning
value printed below loop.
Comments
Post a Comment