Instantly share code, notes, and snippets.

# gwtaylor/crbm.py Last active Jul 9, 2019

Theano CRBM demonstration
 """ Mocap data See: Taylor GW, Hinton GE, Roweis ST. Modeling Human Motion Using Binary Latent Variables. In: Advances in Neural Information Processing Systems 19. MIT Press; 2007. pp. 1345–1352. Download: https://uoguelphca-my.sharepoint.com/:u:/g/personal/gwtaylor_uoguelph_ca/EfJARkZuiX1JmwMKQxQqKJMBaMBUNOcF83FW_n9gk7OIbg?e=fnCjet Place in ../data Data originally from Eugene Hsu, MIT. http://people.csail.mit.edu/ehsu/work/sig05stf/ @author Graham Taylor """ import scipy.io import numpy as np from numpy import arange import theano def preprocess_data(Motion): n_seq = Motion.shape # assume data is MIT format for now indx = np.r_[ arange(0,6), arange(6,9), 13, arange(18,21), 25, arange(30,33), 37, arange(42,45), 49, arange(54,57), arange(60,63), arange(66,69), arange(72,75), arange(78,81), arange(84,87), arange(90,93), arange(96,99), arange(102,105)] row1 = Motion[0,0] offsets = np.r_[ row1[None,9:12], row1[None,15:18], row1[None,21:24], row1[None,27:30], row1[None,33:36], row1[None,39:42], row1[None,45:48], row1[None,51:54], row1[None,57:60], row1[None,63:66], row1[None,69:72], row1[None,75:78], row1[None,81:84], row1[None,87:90], row1[None,93:96], row1[None,99:102], row1[None,105:108]] # collapse sequences batchdata = np.concatenate([m[:, indx] for m in Motion.flat], axis=0) data_mean = batchdata.mean(axis=0) data_std = batchdata.std(axis=0) batchdata = (batchdata - data_mean) / data_std # get sequence lengths seqlen = [s.shape for s in Motion.flat] return batchdata, seqlen, data_mean, data_std def load_data(filename): # load data post preprocess1 mat_dict = scipy.io.loadmat(filename) Motion = mat_dict['Motion'] batchdata, seqlen, data_mean, data_std = preprocess_data(Motion) # put data into shared memory shared_x = theano.shared(np.asarray(batchdata, dtype=theano.config.floatX)) return shared_x, seqlen, data_mean, data_std if __name__ == "__main__": batchdata, seqlen, data_mean, data_std = load_data('../data/motion.mat')

### vberthiaume commented Feb 27, 2013

 awesome work! However my crbm wouldn't display anything until I added plt.show() at the end, is that normal?
Owner Author

### gwtaylor commented Jul 15, 2013

 It depends on whether you have interactive plotting enabled in matplotlib. I start ipython with the "--pylab" option, so interactive plotting is enabled and my figures show up without explicitly calling plt.show(). But technically, I should include this line in my code because many people will not use interactive plotting mode. Thanks for the feedback.

### IssamLaradji commented Sep 8, 2013

 Amazing implementation! One concern though, can C-RBM be used for time series prediction which comprises of sequences of recordings? such as predicting changes in the stock values at the next time step? Thanks!

### dansmith11235 commented Dec 12, 2015

 In your paper you say in your experiments you had n=m= 3 where m is the visibles to current hidden config. and n is the past conf. In this code it has delay = 6. So in this code does n=m=6?
Owner Author

### gwtaylor commented Mar 12, 2019

 Yes, in this code n=m=6.
to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.