The following models result in equivalent inference
def model_1(data):
loc = pyro.sample("loc", dist.Normal(0, 1))
pyro.sample("obs", dist.Normal(loc, 1), obs=data)
def model_2(data):
loc = pyro.sample("loc", dist.Normal(0, 1))
pyro.factor("obs", dist.Normal(loc, 1).log_prob(data))
The latter form using pyro.factor() can be useful if you have a bunch of PyTorch code to compute a (possibly non-normalized) likelihood like fn(loc, data)
, but it is inconvenient to wrap that code in a Distribution
interface.
BTW I just realized the factor()
function you pointed to has been superseded by a public pyro.factor()
primitive. I’ll submit a little PR to replace that custom usage with our standard pyro.factor()
.