Hi!

I’m studying Introduction to Inference now (http://pyro.ai/examples/intro_part_ii.html).

I wrote a simple example with normal distribution:

def model():

X = pyro.sample(“X”, dist.Normal(3, 1))

Y = pyro.sample(“Y”, dist.Normal(5, 1))

S = pyro.deterministic(“S”, X+Y)

return X, Y, Sconditioned_model = pyro.condition(model, data={“S”: 15})

conditioned_model()

Out: (tensor(4.1030), tensor(5.9444), 15)N = 1000

X, Y = [], []

for _ in range(N):

c = conditioned_model()

X.append(float(c[0]))

Y.append(float(c[1]))np.mean(X), np.mean(Y)

Out: (2.9528431569337843, 4.997446128606796)do_model = pyro.do(model, data={“S”: 15})

do_model()

Out: (tensor(2.2040), tensor(4.0202), 15)N = 1000

X, Y = [], []

for _ in range(N):

c = conditioned_model()

X.append(float(c[0]))

Y.append(float(c[1]))np.mean(X), np.mean(Y)

Out: (2.9624990526437758, 5.0139990842342375)

In the first case I want to sample from a conditional distribution (X, Y)|X+Y=15. But 4.1030+5.9444 not equal 15.

Why does it work like this? Or what am I doing wrong?