I’m continuing on the model I’ve described here, adding complexity bit by bit. I’ve now updated theta to be modeled as a two layer nn.Sequential.
Relevant code snippet (some lines removed to make it more clear):
def __init__(self, in_features, h1 = 2, out_features = 1):
super().__init__()
# mu
...
# shape
...
# theta
self.theta = nn.Sequential(
nn.Linear(in_features, h1),
nn.ReLU(),
nn.Linear(h1, out_features),
nn.Sigmoid(),
)
pyro.nn.module.to_pyro_module_(self.theta)
for m in self.theta.modules():
for name, value in list(m.named_parameters(recurse=False)):
setattr(m, name, PyroSample(prior=dist.Laplace(0, 2)
.expand(value.shape)
.to_event(value.dim())))
# relu
self.relu = nn.ReLU()
def forward(self, x, y=None):
x = x.reshape(-1, 2)
...
theta = self.theta(x).squeeze(-1)
# will need to add GPU device
with pyro.plate("data", x.shape[0]):
obs = pyro.sample("obs", GammaHurdle(concentration = shape, rate = shape / mu, theta = theta), obs=y)
return torch.cat((mu, shape, theta), 0)
How do the sites get named for theta? I’d like to look at the distributions of those parameters using Predictive
. With mu for example, if I use self.linear = PyroModule[nn.Linear](...)
, I can use Predictive(model, guide, num_samples, return_sites = ("linear.weight"))
. But I can’t figure out how theta
gets named and how to access that distribution.
In general though, is there a way to get all possible options to use in return_sites? I looked at poutine
but could not get that to work.