Difference `pyro.param` vs `pyro.sample`

I wonder what is the difference between pyro.sample and pyro.param when declaring variables in my probabilistic model or the guide? E.g.,

def model(data):
    x = pyro.param("x", torch.zeros(A, B))
    ...

vs

def model(data):
    x = pyro.sample("x", dist.Normal(torch.zeros(A), torch.ones(B)))
    ...

If I understand it correctly, during SVI the variable s will be “learned” in both models. Moreover, I can use x to declare/specify other variables in my model. So the difference is not clear to me.

Thanks in advance!

parameters corresponds to point estimates and sample statements correspond to latent variables. latent variables are governed by distributions and inference yields a distribution over the inferred values of the latent variable (not a point estimate).

in other words sample statements correspond to quantities with associated uncertainty while parameters have no uncertainty about them.

1 Like

Thanks for the quick reply.
To clarify: assume I want to estimate x_i = A * z_i, where x is my input of dimension N x F (samples x features).
Hence, with latent dimension K:

  • A should be a parameter, because it is fixed across samples:
    A = pyro.param("A", torch.ones(F, K))

  • z_i is a latent variable and therefore needs to be sampled:
    z = pyro.sample("z", dist.Normal(torch.zeros(K,1), torch.ones(K,1)))

Is that correct?

there is no notion of correctness here. there are all kinds of modeling assumptions you could make: A could be a parameter or it could be a latent variable, etc

1 Like

Thanks, the original question is answered!