I'm trying to set up a simplified version of the Bayesian network here with only 3 categorical variables, and then do inference on that. The idea is that D3 is a child of D1 and D2, I'm setting D3=0, and then seeing what that suggestion about the posterior distributions of D1 and D2.
Here is the code:
import pymc3 as pm
import numpy as np
d1_prob = np.array([0.3,0.7]) # 2 choices
d2_prob = np.array([0.6,0.3,0.1]) # 3 choices
d3_prob = np.array([[[0.1, 0.9], # (2x3)x2 choices
[0.3, 0.7],
[0.4, 0.6]],
[[0.6, 0.4],
[0.8, 0.2],
[0.9, 0.1]]])
with pm.Model() as model:
D1 = pm.Categorical('D1',p=d1_prob)
D2 = pm.Categorical('D2',p=d2_prob)
D3 = pm.Categorical('D3',p=d3_prob, observed=[0])
with model:
trace = pm.sample(10000)
print(pm.summary(trace, varnames=['D1', 'D2'], start=1000))
pm.traceplot(trace[1000:], varnames=['D1', 'D2'])
I'm sure there are some fundamental mistakes I'm making here but I cannot identify them and am not sure where else to seek help. This is my best shot at the problem and it's clearly terribly wrong. Could someone help me? Thanks in advance.