# Bayes Nets, Belief Networks, and PyMC

**URL:** <https://discourse.pymc.io/t/bayes-nets-belief-networks-and-pymc/5150>\
**Category:** Questions\
**Created:** [May 25, 2020, 11:27am UTC](https://discourse.pymc.io/t/bayes-nets-belief-networks-and-pymc/5150 "2020-05-25T11:27:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [May 25, 2020, 12:59pm UTC](https://discourse.pymc.io/t/bayes-nets-belief-networks-and-pymc/5150/2 "2020-05-25T12:59:08Z")

</div>

> [@drbenvincent](#):
>
> Q1: Is there anything fundamentally different from these kinds of networks compared to the typical models used in PyMC3?

I dont think there is anything fundamentally different, after all they are mathematical model that you apply the chain rule and product rule of probability, and the differences of discrete and continuous is mostly how you do marginalization. You can express Bayes Net with discrete distributions (i.e., Categorical distribution), and PyMC3 Model will then construct a joint distribution conditioned on the observed (but since you can also construct a model with no observed, you dont need to label it as conditional probability distribution).

> [@drbenvincent](#):
>
> Q2: Can PyMC evaluate these kinds of models?

Certainly, my approach will goes like this:

```python
import pymc3 as pm
import numpy as np

import theano
import theano.tensor as tt

lookup_table = theano.shared(np.asarray([
    [[.99, .01], [.1, .9]],
    [[.9, .1], [.1, .9]]]))

def f(smoker, covid):
    return lookup_table[smoker, covid]

with pm.Model() as m:
    smoker = pm.Categorical('smoker', [.75, .25])
    covid = pm.Categorical('covid', [.9, .1])
    hospital = pm.Categorical('hospital', f(smoker, covid))
    prior_trace = pm.sample_prior_predictive(100000)

predict_proba0 = prior_trace['covid'][
    (prior_trace['smoker'] == 0)
  & (prior_trace['hospital'] == 1)].mean()
predict_proba1 = prior_trace['covid'][
    (prior_trace['smoker'] == 1)
  & (prior_trace['hospital'] == 1)].mean()

print(f'P(covid|¬smoking, hospital) is {predict_proba0}')
print(f'P(covid|smoking, hospital) is {predict_proba1}')

```

which you can get an approximation of:

```auto
P(covid|¬smoking, hospital) is 0.9103626239304631
P(covid|smoking, hospital) is 0.4927695004382121

```

---

_[View the full topic](https://discourse.pymc.io/t/bayes-nets-belief-networks-and-pymc/5150)._
