Algorithms from statistical physics for generative models of images