def setUp(self):
# lognormal-normal model
# putting some of the parameters inside of a torch module to
# make sure that that functionality is ok (XXX: do this somewhere else in the future)
self.mu0 = Variable(torch.Tensor([1.0])) # normal prior hyperparameter
# normal prior hyperparameter
self.tau0 = Variable(torch.Tensor([1.0]))
# known precision for observation likelihood
self.tau = Variable(torch.Tensor([2.5]))
self.n_data = 2
self.data = Variable(torch.Tensor([[1.5], [2.2]])) # two observations
self.tau_n = self.tau0 + \
Variable(torch.Tensor([self.n_data])) * self.tau # posterior tau
mu_numerator = self.mu0 * self.tau0 + \
self.tau * torch.sum(torch.log(self.data))
self.mu_n = mu_numerator / self.tau_n # posterior mu
self.log_mu_n = torch.log(self.mu_n)
self.log_tau_n = torch.log(self.tau_n)
self.verbose = True
评论列表
文章目录