The labeled shifter ensemble where the bottom pixels are shi
     The \"labeled shifter\" ensemble where the bottom pixels are shifted left or right, or stay put from the top pixels. The extra top three pixels are the label indicator. Four samples are shown.  Machine for ML: Boltzmann Machine (i.e., 2^nd order statistics)  Is this one of them? Why?  Machine for ML: Boltzmann Machine (i.e., 2^nd order statistics)  Is this one of them? Why? 
  
  Solution
import numpy as np class PositiveToyRBM(object): def __init__(self, num_visible, num_hidden, w=None): self.num_visible = num_visible self.num_hidden = num_hidden if w is None: self.w = np.zeros((num_visible, num_hidden)) else: self.w = np.float32(w) def threshold(self, arr): arr[arr >= 0] = 1 arr[arr < 0] = -1 return arr def hebbian(self, visible, hidden): # for each pair of units determine if they are both on return np.dot(visible.reshape(visible.shape[0], 1), hidden.reshape(hidden.shape[0], 1)) def pp(self, arr): # pretty print return list([list(i) for i in arr]) def try_reconstruct(self, data): h = self.threshold(np.dot(data, self.w)) recon = self.threshold(np.dot(h, self.w.T)) return np.sum(data — recon) == 0 def train(self, data, epochs=10): data = np.array(data) for e in xrange(epochs): delta_w = [] for example in data: h = self.threshold(np.dot(example, self.w)) delta_w.append(self.hebbian(example, h)) # average delta_w = np.mean(delta_w, axis=0) self.w += delta_w result = self.try_reconstruct(data) print \'epoch\', e, \'delta w =\', self.pp(delta_w), \'new weights =\', self.pp(self.w), \'reconstruction ok?\', result
