Kernel: Python 3
Inference in the "Asia" directed probabilistic graphical model
Based on https://github.com/probml/pmtk3/blob/master/demos/asiaDgm.m and https://github.com/pgmpy/pgmpy/blob/dev/examples/Inference in Bayesian Networks.ipynb
In [1]:
Out[1]:
Collecting pgmpy
Downloading pgmpy-0.1.18-py3-none-any.whl (1.9 MB)
|████████████████████████████████| 1.9 MB 5.0 MB/s
Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from pgmpy) (4.64.0)
Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from pgmpy) (1.4.1)
Requirement already satisfied: networkx in /usr/local/lib/python3.7/dist-packages (from pgmpy) (2.6.3)
Requirement already satisfied: torch in /usr/local/lib/python3.7/dist-packages (from pgmpy) (1.10.0+cu111)
Requirement already satisfied: scikit-learn in /usr/local/lib/python3.7/dist-packages (from pgmpy) (1.0.2)
Requirement already satisfied: statsmodels in /usr/local/lib/python3.7/dist-packages (from pgmpy) (0.10.2)
Requirement already satisfied: joblib in /usr/local/lib/python3.7/dist-packages (from pgmpy) (1.1.0)
Requirement already satisfied: pyparsing in /usr/local/lib/python3.7/dist-packages (from pgmpy) (3.0.8)
Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from pgmpy) (1.3.5)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from pgmpy) (1.21.6)
Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->pgmpy) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->pgmpy) (2022.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->pgmpy) (1.15.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn->pgmpy) (3.1.0)
Requirement already satisfied: patsy>=0.4.0 in /usr/local/lib/python3.7/dist-packages (from statsmodels->pgmpy) (0.5.2)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch->pgmpy) (4.1.1)
Installing collected packages: pgmpy
Successfully installed pgmpy-0.1.18
In [2]:
Out[2]:
--2022-04-22 22:02:00-- http://www.bnlearn.com/bnrepository/asia/asia.bif.gz
Resolving www.bnlearn.com (www.bnlearn.com)... 176.58.124.98
Connecting to www.bnlearn.com (www.bnlearn.com)|176.58.124.98|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.bnlearn.com/bnrepository/asia/asia.bif.gz [following]
--2022-04-22 22:02:00-- https://www.bnlearn.com/bnrepository/asia/asia.bif.gz
Connecting to www.bnlearn.com (www.bnlearn.com)|176.58.124.98|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 310 [application/gzip]
Saving to: ‘asia.bif.gz’
asia.bif.gz 100%[===================>] 310 --.-KB/s in 0s
2022-04-22 22:02:01 (36.8 MB/s) - ‘asia.bif.gz’ saved [310/310]
asia.bif sample_data
In [12]:
Out[12]:
/usr/local/lib/python3.7/dist-packages/pgmpy/factors/discrete/DiscreteFactor.py:537: UserWarning: Found unknown state name. Trying to switch to using all state names as state numbers
UserWarning,
0it [00:00, ?it/s]
0it [00:00, ?it/s]
p(bronchitis | smoke=0 [0.6 0.4]
In [19]:
Out[19]:
/usr/local/lib/python3.7/dist-packages/pgmpy/factors/discrete/DiscreteFactor.py:537: UserWarning: Found unknown state name. Trying to switch to using all state names as state numbers
UserWarning,
0it [00:00, ?it/s]
0it [00:00, ?it/s]
p(asia | tb=1) [0.04807692 0.95192308]
In [ ]: