def get_op(self, row_cnt): if row_cnt in self.ops: return self.ops[row_cnt] graph = self.model.graph X = graph.X # build the graph h0_probs, hn_sample = graph.get_op_sample_h_given_v(X, row_cnt) for n in range(1, self.k + 1): vn_probs, vn_sample, hn_probs, hn_sample = graph.get_op_gibbs_hvh( hn_sample, row_cnt) # gradients grad_W = (sym.dot(sym.transpose(vn_sample), hn_probs) - sym.dot(sym.transpose(X), h0_probs)) grad_v_bias = sym.sum(vn_sample - X, axis=0) grad_h_bias = sym.sum(hn_probs - h0_probs, axis=0) # loss loss = sym.mean(sym.square(X - vn_probs)) op = sym.Group([loss, grad_W, grad_v_bias, grad_h_bias]) self.ops[row_cnt] = op return op
def get_op_propgate_h2v(self, h): v_probs = sym.sigmoid( sym.broadcast_add(sym.dot(h, sym.transpose(self.W)), self.v_bias)) return v_probs
def hybrid_flatten_pred(sym_pred): return sym.transpose(sym_pred, (0, 2, 3, 1)).flatten()