Monitor determinstic parameter of interest

Hi, I have a question but don’t know what is the keywords I should search for after a few trials on Google. So basically, suppose I have a GLM. setting where

mu = torch.exp(b0 + b1* x)

and b0, b1 are my true parameters which needs to be estimated either through MCMC or SVI.

Is there anyway that I can get samples or posterior samples for mu? I know I can definitely takes samples from b0 and b1 then calculate mu by myself, but that seems dumb since I feel this should already be handled by Pyro.

At high level, if theta is my parameter which needs to be estimate, how can I let Pyro know I want samples for f(theta), some transformations from theta like theta^2, or theta_1 - theta_2, etc? I don’t know what this kind of stuff is called in Pyro so need some help. Thanks!

The thing you are looking for is probably pyro.deterministic.

mu = torch.exp(b0 + b1 * x)
mu = pyro.deterministic("mu", mu)

It adds the deterministic variable to the trace, so you will be able to see it in your posterior samples.


Thank you. It is seems what I need. I tried to get posterior samples through sampling from guide(), which doesn’t include the deterministic value. Do you know what is the correct way to obtain posterior samples? I was trying Predictive from pyro.infer but it seems to slow and crashed my GPU memory since it is predicting the y values as well (but I don’t need).

Predictive is a good option for this. You can specify a list of sites to return when creating a Predictive object (return_sites keyword) - that helps to reduce memory consumption by removing sites you don’t need from the trace.

That won’t work if your deterministic sites are located in your guide (however I don’t see any reasons to place them there) - in this case, you can use poutine.trace

from pyro import poutine

trace = poutine.trace(guide).get_trace(*agrs, **kwargs)