def __init__(self, num_visibles, num_hiddens): """ Initializes the parameters of the SemiRBM. @type num_visibles: integer @param num_visibles: number of visible units @type num_hiddens: integer @param num_hiddens: number of hidden units """ AbstractBM.__init__(self, num_visibles, num_hiddens) # additional hyperparameters self.learning_rate_lateral = 0.01 self.momentum_lateral = 0.5 self.weight_decay_lateral = 0. self.damping = 0.2 self.num_lateral_updates = 20 self.sampling_method = AbstractBM.MF # additional parameters self.L = np.matrix(np.random.randn(num_visibles, num_visibles)) / num_visibles / 200 self.L = np.triu(self.L) + np.triu(self.L).T - 2. * np.diag(np.diag(self.L)) self.dL = np.zeros_like(self.L)
def __init__(self, num_visibles, num_hiddens): AbstractBM.__init__(self, num_visibles, num_hiddens) # hyperparameters self.sigma = 0.2 self.vsigma = np.asmatrix(np.ones(num_visibles)).T self.dvsigma = np.ones_like(self.vsigma)
def __init__(self, num_visibles, num_hiddens): """ Initializes the parameters of the SemiRBM. @type num_visibles: integer @param num_visibles: number of visible units @type num_hiddens: integer @param num_hiddens: number of hidden units """ AbstractBM.__init__(self, num_visibles, num_hiddens) # additional hyperparameters self.learning_rate_lateral = 0.01 self.momentum_lateral = 0.5 self.weight_decay_lateral = 0. self.damping = 0.2 self.num_lateral_updates = 20 self.sampling_method = AbstractBM.MF # additional parameters self.L = np.matrix(np.random.randn(num_visibles, num_visibles)) / num_visibles / 200 self.L = np.triu(self.L) + np.triu( self.L).T - 2. * np.diag(np.diag(self.L)) self.dL = np.zeros_like(self.L)
def __init__(self, num_visibles, num_hiddens): """ Initializes the parameters of the RBM. @type num_visibles: integer @param num_visibles: number of visible units @type num_hiddens: integer @param num_hiddens: number of hidden units """ AbstractBM.__init__(self, num_visibles, num_hiddens)
def train(self, X): X = np.asmatrix(X) if self.sampling_method is AbstractBM.MF: # positive phase self.forward(X) # store posterior probabilities Q = self.Q.copy() if self.persistent: self.X = self.pX self.Y = self.pY # negative phase for t in range(self.cd_steps): self.backward() self.forward() if self.persistent: self.pX = self.X.copy() self.pY = self.Y.copy() # update parameters self.dW = X * Q.T / X.shape[1] - self.P * self.Y.T / self.X.shape[1] \ - self.weight_decay * self.W \ + self.momentum * self.dW self.db = X.mean(1) - self.P.mean(1) + self.momentum * self.db self.dc = Q.mean(1) - self.Y.mean(1) + self.momentum * self.dc self.dL = X * X.T / X.shape[1] - self.P * self.P.T / self.X.shape[1] \ - self.weight_decay_lateral * self.L \ + self.momentum_lateral * self.dL self.dL -= np.diag(np.diag(self.dL)) self.W += self.dW * self.learning_rate self.b += self.db * self.learning_rate self.c += self.dc * self.learning_rate self.L += self.dL * self.learning_rate_lateral else: # update RBM parameters AbstractBM.train(self, X) # update lateral connections self.dL = X * X.T / X.shape[1] - self.X * self.X.T / self.X.shape[1] \ - self.weight_decay_lateral * self.L \ + self.momentum_lateral * self.dL self.dL -= np.diag(np.diag(self.dL)) self.L += self.dL * self.learning_rate_lateral
def __init__(self, num_visibles, num_hiddens): AbstractBM.__init__(self, num_visibles, num_hiddens) # hyperparameters self.sigma = 1.