Hi,
I tried to use the following to get a posterior marginals prob. and found x1, x2 will become a vector instead of scalers that made python “or” operator failed.
Can pyro do both inference of discrete/continuous variables in Bayesian network or Factor graph like Microsoft infer.net ?
import pyro
import torch
import pyro.distributions as dist
from pyro.infer import TraceEnum_ELBO, config_enumerate
@config_enumerate
def TwoCoin(oneIsHead=None):
x1 = pyro.sample("x1", dist.Bernoulli(0.5))
x2 = pyro.sample("x2", dist.Bernoulli(0.5))
print(x1)
one_head = x1 or x2
oneIsHead = pyro.sample("oneIsHead", dist.Delta(one_head), obs=oneIsHead)
return oneIsHead
def guide(**kwargs):
pass
elbo = TraceEnum_ELBO()
conditional_marginals = elbo.compute_marginals(TwoCoin, guide, oneIsHead=torch.tensor(1.))
p_x1_1 = conditional_marginals["x1"].log_prob(torch.tensor(1)).exp()
print(p_x1_1)