Hybrid Bayesian Network getting stuck in PyMC3

We don’t have a Gibb sampler in PyMC3, and the Metropolis samplers could get stuck in high dimension easily as it tries to update all parameters at once and got proposal rejected most of the time. [Edit]: Metropolis is actually update parameters one by one as default, but still in high-dimension the rejection rate is high.
Nonetheless, you can try the code below which seems to give acceptable result (minor changes based on your implementation):

p_pr = np.asarray([0.7, 0.2, 0.1])
a_cl = 3.
b_cl = 1.
g_g1 = tt.as_tensor_variable(np.asarray([1, 3, 10]))
k_g2 = 10.
m_tr = 5.
s_tr = 2.5
r_lo = 1/3
d_lo = 1.

with pm.Model() as model:
    PR = pm.Categorical('PR', p=p_pr, testval=2)
    CL = pm.Beta('CL', alpha=a_cl, beta=b_cl)
    G1 = pm.Poisson('G1', mu=CL*g_g1[PR])
    G2 = pm.Poisson('G2', mu=G1*k_g2)
    TR = pm.Bernoulli('TR', p=pm.math.invlogit((G1-m_tr)/s_tr))
    x_LO = pm.Deterministic('x_LO', G2*(1-(1-r_lo)*TR))
    j = pm.Poisson('j', mu=x_LO) # no ncx2 function, so we sample this way
                                # https://discourse.pymc.io/t/noncentral-chi-squared-distribution/432
    LO = pm.ChiSquared('LO', nu=d_lo+2*j)
    trace = pm.sample(10000)
pm.traceplot(trace);

1 Like