Hi, sorry for another dumb question - I’m trying to use SVI to find the posterior over the parameters of a Dirichlet distribution in a hierarchical model. The parameters are a scalar Alpha and a vector Beta with an exponential prior and a uniform prior respectively.
I’m getting stuck on how to specify the guide function such that I can end up with the posterior over Alpha and Beta, given my data. I know I’m doing something wrong because during inference Alpha increases, whereas the data is best explained by a very small value. Thanks again for the help!
Revelant chunk of code is:
lmbda = 1
bag_samples = 10
colors = 2
data = torch.Tensor([[0., 10.],[10., 0.],[0., 10.],[10., 0.],[0., 10.],[10., 0.],[0., 10.],[10., 0.]])
def model(lmbda=lmbda):
alpha = 1.0
beta = torch.ones(colors)/2
with pyro.plate("thetas", len(data):
theta = pyro.sample("theta", dist.Dirichlet(torch.FloatTensor(alpha*beta)))
with pyro.plate("obs", len(data)):
return pyro.sample("draws", dist.Multinomial(bag_samples, theta), obs = data)
def guide(lmbda=lmbda):
q_alpha = pyro.param("alpha", dist.Exponential(1/lmbda))
q_beta = pyro.param("beta", dist.Dirichlet(torch.ones(colors)))
with pyro.plate("thetas", len(data)):
q_theta = pyro.sample("theta", dist.Dirichlet(torch.FloatTensor(q_alpha*q_beta)))
with pyro.plate("obs", len(data)):
return pyro.sample("draws", dist.Multinomial(bag_samples, q_theta))