RBM code from edwin chen