Contrastive Divergence refactoring