def v_to_h(self, V, do_sampling=True): """ Compute the data representation in the hidden space """ m = V.shape[0] if len(V.shape) == 1: V.shape = (1, m) # print V.shape, self.W.shape, self.hbias.shape H = Activation.sigmoid_function( np.dot(np.c_[np.ones(m), V], np.vstack((self.hbias, self.W)) ) ) if do_sampling: H = self.sample(H) return H
def h_to_v(self, H, do_sampling=False, pois_N=None): """ Restore visual data using hidden space representation. Returns the data representation in the original space. """ m = H.shape[0] pre_distr = np.dot( np.c_[np.ones(m), H], np.vstack((self.vbias, self.W.T)) ) if self.mode == 'gaus-bin': return pre_distr elif self.mode == 'pois-bin': e = np.exp(pre_distr) if pois_N is None: return ( e.T / np.sum(e, axis=1) ).T else: return ( e.T / ((1. / pois_N) * np.sum(e, axis=1)) ).T V = Activation.sigmoid_function(pre_distr) if do_sampling: V = self.sample(V) return V