I am just getting started with the Gibbs Sampler and came across an implementation from here and here and here. All of theses implementations are based on the first article.
There is an inner loop in the implementation and I don't understand it's purpose.
Here is the code (written in julia). It's been changed slightly to the implementation from the article, but not where it matters.
function gibbs(n, thin)
#array to store the results
mat = Array(Float64, (n,2))
x = y = 0.0
#outer loop number of samples to draw
for i in 1:n
#inner loop: purpose unknown.
for j in 1:thin
x = rand ( Normal( .9 * y, 1 - .9^2))
y = rand ( Normal( .9 * x, 1 - .9^2))
end
mat[i,1] = x; mat[i,2] = y
end
mat
#end of program
end
function main()
gibbs(10000, 200)
end
main()
From my understanding the inner loop creates an addition $n * thin$ amount of samples and thus decreases the likelihood of two consecutive draws being to close to each other. Is there another purpose to this?