def partial_fit(self, X): """ Fit the model to the data X which should contain a partial segment of the data. Adjust the parameters to maximize the likelihood of v using Stochastic Maximum Likelihood (SML). Parameters ---------- X : array-like, shape (n_samples, n_features) The data to use for training. """ v_pos = X h_pos = self._mean_hiddens(v_pos) if self.use_pcd: v_neg = self._sample_visibles(self.h_samples_) else: v_neg = self._sample_visibles(h_pos) h_neg = self._mean_hiddens(v_neg) lr = float(self.learning_rate) / v_pos.shape[0] op.add_dot(h_pos, v_pos, self.dW, True, False, alpha=1.0, beta=self.momentum) op.add_dot(h_neg, v_neg, self.dW, True, False, alpha=-1.0, beta=1.0) self.W += lr * self.dW self.dbh *= self.momentum self.dbv *= self.momentum self.dbh += (op.sum(h_pos, axis=0) - op.sum(h_neg, axis=0)).reshape(1, self.dbh.shape[1]) self.dbv += (op.sum(v_pos, axis=0) - op.sum(v_neg, axis=0)).reshape(1, self.dbv.shape[1]) self.bh += lr * self.dbh self.bv += lr * self.dbv if self.use_pcd: self.h_samples_ = op.sample_binomial(h_neg)
def _sample_hiddens(self, v): """Sample from the distribution P(h|v). Parameters ---------- v : array-like, shape (n_samples, n_features) Values of the visible layer to sample from. Returns ------- h : array-like, shape (n_samples, n_components) Values of the hidden layer. """ p = self._mean_hiddens(v) return op.sample_binomial(p)
def partial_fit(self, X): """ Fit the model to the data X which should contain a partial segment of the data. Adjust the parameters to maximize the likelihood of v using Stochastic Maximum Likelihood (SML). Parameters ---------- X : array-like, shape (n_samples, n_features) The data to use for training. """ v_pos = X h_pos = self._mean_hiddens(v_pos) if self.use_pcd: v_neg = self._sample_visibles(self.h_samples_) else: v_neg = self._sample_visibles(h_pos) h_neg = self._mean_hiddens(v_neg) lr = float(self.learning_rate) / v_pos.shape[0] op.add_dot(h_pos, v_pos, self.dW, True, False, alpha=1.0, beta=self.momentum) op.add_dot(h_neg, v_neg, self.dW, True, False, alpha=-1.0, beta=1.0) self.W += lr * self.dW self.dbh *= self.momentum self.dbv *= self.momentum self.dbh += (op.sum(h_pos, axis=0) - op.sum(h_neg, axis=0)).reshape( 1, self.dbh.shape[1]) self.dbv += (op.sum(v_pos, axis=0) - op.sum(v_neg, axis=0)).reshape( 1, self.dbv.shape[1]) self.bh += lr * self.dbh self.bv += lr * self.dbv if self.use_pcd: self.h_samples_ = op.sample_binomial(h_neg)