RBM gradient function updated