gibbs sampling and training implemented