Several questions on how to sample from a model?


#1

Assume that I have a model

def model(weight, height):
    alpha = pyro.sample("alpha", dist.normal, ng_ones(1)*178, ng_ones(1)*100)
    beta = pyro.sample("beta", dist.normal, ng_zeros(1), ng_ones(1)*10)
    mu = alpha + beta * weight
    sigma = pyro.sample("sigma", dist.uniform, ng_zeros(1), ng_ones(1)*50)
    return pyro.sample("height", dist.normal, mu, sigma.expand_as(mu), obs=height)

and its corresponding guide. After using SVI inference, I get good parameters for guide. Using guide, I get samples for alpha, beta, sigma from their posterior distribution. Now, I want to use guide and model to get samples for height.

The only way I can figure out is to use pyro.condition instead of pyro.sample(..., obs=...). We rewrite model as def model1(weight): ... then define conditioned_model = pyro.condition(...) and its corresponding guide. We use SVI to train guide. After that, we use Importance on model1 and guide, then do Marginal to get samples for height.

I would like to ask if it is the only way to do? (is there any Poutine which helps to disable the observed sites, so we can use Importance on model and guide, then Marginal to get samples for height?)

Another question is how to get samples for mu? In PyMC3, we have pymc3.Deterministic which helps to do that.

My last question is: if I want to get 100 samples for height, then how many execution traces is good enough?

Thanks a lot in advance!

Edit: There is still a problem with the way I proposed above. The requirement for guide is to include all pyro.sample from model. So the guide for model1 has to include pyro.sample('height',...). It seems that we have to define a new guide with the same params.


#2

I just discovered that I am able to solve the first problem by setting height=None. No need to create a new model

The third problem is sensitive, I can manage it by myself.

It is better to ask the second problem in another topic.