Making a query for a simple BN made in PYMC3

Thank you very much for your kind help.

I agree. In case of changing the prior, the PJD I’ve gained with trace is not valid anymore and I have to resample the whole process again.

On the same note, I wonder if how I can estimate the prior (and more CPDs) better. Ideally, I would guess the prior should come from a Dirichlet distribution. I followed this example for the syntax:

Chris: Problem with pm.Categorical

import theano.tensor as tt
D = np.array([0.6, 0.4])
I = np.array([0.7, 0.3])
G = np.array([[[0.3, 0.4, 0.3],
[0.05, 0.25, 0.7]],
[[0.9, 0.08, 0.02],
[0.5, 0.3, 0.2]]])
S = np.array([[0.95, 0.05],
[0.2, 0.8]])
L = np.array([[0.1, 0.9],
[0.4, 0.6],
[0.99, 0.01]])
II = data.I.values # data = pm.trace_to_dataframe(prev_trace) from known priors
DD = data.D.values
GG = data.G.values
with pm.Model() as cpd_estimate:
Ie = pm.Dirichlet(‘Ie’, a = np.ones(2))
I_ = pm.Categorical(‘I’, p=Ie, observed=II)
De = pm.Dirichlet(‘De’, a = np.ones(2))
D_ = pm.Categorical(‘D’, p=De, observed=DD)
G_prob = pm.Dirichlet(‘Ge’, a=np.ones(G.shape), shape=G.shape)
G_0 = G_prob[I_, D_]
G_ = pm.Categorical(‘G’, p=G_0, observed=GG)
trace = pm.sample(1000)

it is very slow!!! (~2 draws/s) any suggestions? I can always use VI but I was wondering if there is something I could do to make it faster. It becomes really slow when I add G!

PS it seems there is something wrong about Dirichlet; the output of the trace log looks like this whenever I use Dirichlet in my model:

Sorry for these long messages. I really appreciate your help.

Ramin