Model definition parameters in pyro language: discuss?


#1

Hi everyone!

I’ve quickly ported my model from PyMC3 to Pyro and am making quick progress. I’ve been very impressed with what you’ve built here!

I just have one minor discussion point I’m curious if the language designers could speak on. When I use model parameters within the my “model()” function, like this example:

sd_mu = torch.tensor(0.5)
sd_sd = torch.tensor(0.2)
sd = pyro.sample('sd_test', dist.Normal(sd_mu, sd_sd))

I’m wondering what the point of specifying the parameters (in this case, sd_mu, and sd_sd) if that’s explicitly what we’re trying to find in the posterior. It seems silly to define them at all. Shouldn’t they be assumed to be “undefined” at first? does changing those values (in this case, 0.5 and 0.2) change anything about the way inference is performed?

Perhaps there should be some explicit class called “InferThis()” or something. I know the guide is a better place for parameter tweaking and constraining but in the model definition, it seems … strange.

I’m wondering if anyone could speak on this design decision. :slight_smile: thanks for any insights here!


#2

does changing those values (in this case, 0.5 and 0.2) change anything about the way inference is performed?

Posterior distributions are only defined via Bayes’ theorem with reference to a prior distribution. sd = pyro.sample('sd_test', Normal(0.5, 0.2)) means there is a random variable sd_test in your model with prior (or likelihood, if sd_test is observed) distribution Normal(0.5, 0.2).

If you’re asking how to compute the posterior distributions over sd_mu and sd_scale in addition to the posterior distribution over sd_test, you’ll need to put priors on them as well. If you just want maximum likelihood estimates of these values, you can use pyro.param to mark them as free model parameters. See the model and inference introductory tutorials for more background.