Dependent priors with pyro.random_module


Let’s say I have pytorch module like this:

class MyClass(nn.Module):
    def __init__(self, x, y, z):
        super(MyClass, self).__init__()
        self.x = nn.Parameter(x.clone().detach())
        self.y = nn.Parameter(y.clone().detach())
        self.z = nn.Parameter(z.clone().detach())
    def model(self, obs):
        # Evaluate some complicated stochastic function

I want to lift this and generate new instances with randomly sampled values for x, y and z. However, the PDFs for the variables are dependent. If they were independent, I would use pyro.random_module, but I don’t see a way to apply that here. What’s a good way to go about doing this?

Also, I would later like to use the model with some observations to sample from the posterior for x, y and z with HMC/NUTS and compute their marginals.

I’m guessing the best approach to just sample x, y and z by hand and construct a new instance of MyClass with those values?


right, the best thing to do would be to write the variables out explicitly (ie with sample statements) like in here