rewrote the contrastiveDivergence method to work with the gradient methods