pyro.nn.PyroSample and log_prob_sum for GPRegression?

We tried the tutorial on GP https://pyro.ai/examples/gp.html
(thank you for the awesome tutorials!)
and we have a few questions:

1. We could not get these lines to work?
gpr.kernel.lengthscale = pyro.nn.PyroSample(dist.LogNormal(0.0, 1.))
gpr.kernel.variance = pyro.nn.PyroSample(dist.LogNormal(0.0, 1.))

It says: AttributeError: module ‘pyro.nn’ has no attribute ‘PyroSample’.

Could you please give an example on how to fix this?

2. We would like to compute log_p, log_q. It looks like we could do this using poutine.
How does poutine work with GPRegression or SparseGPRegression in the lines below?
What shape of data should we pass in get_trace(data)? is it a tuple data=(X,y)?

model_trace = pyro.poutine.trace(gpr.model).get_trace(data)
guide_trace = pyro.poutine.trace(gpr.guide).get_trace(data)

3. If we pass data=None in the lines above, how does it compute log_prob_sum()?
(ie. how does it do the random sampling?)

log_p = model_trace.log_prob_sum()
log_q = guide_trace.log_prob_sum()

Hi @pookie, I think you need to update Pyro to a version >= 1.0.0. About computing log_p, log_q, I think you just need to call ...get_trace() because there is no argument in gpr.model and gpr.guide - data is fixed in gpr.__init__() method (or it can be set through gpr.set_data() method). To compute log_p, first you need to get guide_trace (i.e. a sample z ~ q(z)), then replay guide_trace to model (i.e. pass values of latent variables in guide to latent variables in model - so you can compute p(z) where z is drawn from q(z)).

1 Like

Thank you very much @fehiepsi, that works.