def get_child_message(x, y, hidden={}, visible={}): with graph_context({**hidden, **visible}): data = context(y) log_likelihood = y.log_likelihood(data) stats = x.statistics() param = T.grad(T.sum(log_likelihood), [x.get_statistic(s) for s in stats]) return {s: param[i] for i, s in enumerate(stats)}
def expected_sufficient_statistics(self): if self._estats is None: natparam = self.get_parameters('natural', stop_gradient=True) stats = list(self.statistics()) log_z = self.log_z('natural', stop_gradient=True) grads = T.grad(log_z, [natparam[s] for s in stats]) self._estats = {s: g for s, g in zip(stats, grads)} return self._estats
def get_child_message(x, y, data={}): y_ = data[y] stats = x.statistics() log_likelihood = y.log_likelihood(y_) param = T.grad(T.sum(log_likelihood), [x.get_statistic(s) for s in stats]) return {s: param[i] for i, s in enumerate(stats)}
def kl_gradients(self, q_X, q_A, kl, num_data): return T.grad(kl, self.get_parameters())