DeepLearning icon indicating copy to clipboard operation
DeepLearning copied to clipboard

RBM Weight Updates Issue

Open Darwin2011 opened this issue 10 years ago • 5 comments

Such Issues are in your RBM different implementation. [python version] self.W += lr * (numpy.dot(self.input.T, ph_sample) - numpy.dot(nv_samples.T, nh_means)) [C++ version] W[i][j] += lr * (ph_mean[i] * input[j] - nh_means[i] * nv_samples[j]) / N;

For there two versions, the weight update methods are incosistent. And Actually I think the right version should be self.W += lr * (numpy.dot(self.input.T, ph_means) - numpy.dot(nv_means.T, nh_means)) Could you please help me confirm such issues? I am not quite sure that whether it's issue or not. And I am just a freshman for deep learning.

Best Regards

Darwin2011 avatar Oct 20 '14 16:10 Darwin2011

@Darwin2011 I think (ph_mean[i] * input[j] - nh_means[i] * nv_samples[j]) is right. The weights gradient should be data-model。

liulhdarks avatar Oct 21 '14 12:10 liulhdarks

@liulhdarks ,thanks The following code shows that the different weight update method. Could you check the following link? https://github.com/echen/restricted-boltzmann-machines/blob/master/rbm.py

Darwin2011 avatar Oct 21 '14 16:10 Darwin2011

@Darwin2011 https://github.com/echen/restricted-boltzmann-machines/blob/master/rbm.py doesn't use the visible layer after sampling when updating weights. You can refer to the follow ML frameworks.

  • [Deeplearning4j] https://github.com/agibsonccc/java-deeplearning/blob/master/deeplearning4j-core/src/main/java/org/deeplearning4j/models/featuredetectors/rbm/RBM.java

INDArray wGradient = input.transpose().mmul(probHidden.getSecond()).sub( nvSamples.transpose().mmul(nhMeans));

  • [darks-learning] https://github.com/liulhdarks/darks-learning/blob/master/src/main/java/darks/learning/neuron/rbm/RBM.java

DoubleMatrix wGradient = input.transpose().mmul(hProp1.prob) .sub(vPropn.sample.transpose().mmul(hPropn.prob));

Hope to help you!

liulhdarks avatar Oct 22 '14 14:10 liulhdarks

@liulhdarks thanks for your kind help. I will follow your guide.

Best Regards

Darwin2011 avatar Oct 22 '14 15:10 Darwin2011

@liulhdarks @yusugomori I think the update for W , a , b should as follows: self.W += lr * (numpy.dot(self.input.T, ph_mean - numpy.dot(nv_samples.T, nh_means)) self.vbias += lr * numpy.mean(self.input - nv_samples, axis=0) self.hbias += lr * numpy.mean(ph_mean - nh_means, axis=0)

In origin python RBM.py. , self.W and self.hbias is not correct. This problem is also in C/C++ files, but the W has been fixed. If I am not right, please inform me. Thanks.

luochao436 avatar Nov 19 '14 15:11 luochao436