Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  demoPyAgrum 
pyAgrum 0.16.2   
Zipped notebooks   
generation: 2019-10-02 10:58  

Creative Commons License
This pyAgrum's notebook is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

In [1]:
%matplotlib inline
from pylab import *
import matplotlib.pyplot as plt

import os

Initialisation

  • importing pyAgrum
  • importing pyAgrum.lib tools
  • loading a BN
In [2]:
import pyAgrum as gum
import pyAgrum.lib.notebook as gnb
gnb.configuration()
LibraryVersion
OSposix [darwin]
Python3.7.3 (default, Mar 27 2019, 09:23:15) [Clang 10.0.1 (clang-1001.0.46.3)]
IPython7.8.0
MatPlotLib3.1.1
Numpy1.17.2
pyAgrum0.16.0.9
Sun Sep 15 10:32:32 2019 CEST
In [3]:
bn=gum.loadBN(os.path.join("res","alarm.dsl"))
gnb.showBN(bn,size='10')
G KINKEDTUBE KINKEDTUBE VENTLUNG VENTLUNG KINKEDTUBE->VENTLUNG PRESS PRESS KINKEDTUBE->PRESS HYPOVOLEMIA HYPOVOLEMIA STROKEVOLUME STROKEVOLUME HYPOVOLEMIA->STROKEVOLUME LVEDVOLUME LVEDVOLUME HYPOVOLEMIA->LVEDVOLUME INTUBATION INTUBATION SHUNT SHUNT INTUBATION->SHUNT INTUBATION->VENTLUNG MINVOL MINVOL INTUBATION->MINVOL INTUBATION->PRESS VENTALV VENTALV INTUBATION->VENTALV MINVOLSET MINVOLSET VENTMACH VENTMACH MINVOLSET->VENTMACH PULMEMBOLUS PULMEMBOLUS PAP PAP PULMEMBOLUS->PAP PULMEMBOLUS->SHUNT INSUFFANESTH INSUFFANESTH CATECHOL CATECHOL INSUFFANESTH->CATECHOL ERRLOWOUTPUT ERRLOWOUTPUT HRBP HRBP ERRLOWOUTPUT->HRBP ERRCAUTER ERRCAUTER HRSAT HRSAT ERRCAUTER->HRSAT HREKG HREKG ERRCAUTER->HREKG FIO2 FIO2 PVSAT PVSAT FIO2->PVSAT LVFAILURE LVFAILURE LVFAILURE->STROKEVOLUME LVFAILURE->LVEDVOLUME HISTORY HISTORY LVFAILURE->HISTORY DISCONNECT DISCONNECT VENTTUBE VENTTUBE DISCONNECT->VENTTUBE ANAPHYLAXIS ANAPHYLAXIS TPR TPR ANAPHYLAXIS->TPR CO CO STROKEVOLUME->CO TPR->CATECHOL BP BP TPR->BP PCWP PCWP LVEDVOLUME->PCWP CVP CVP LVEDVOLUME->CVP VENTMACH->VENTTUBE SAO2 SAO2 SHUNT->SAO2 VENTTUBE->VENTLUNG VENTTUBE->PRESS VENTLUNG->MINVOL VENTLUNG->VENTALV EXPCO2 EXPCO2 VENTLUNG->EXPCO2 ARTCO2 ARTCO2 VENTALV->ARTCO2 VENTALV->PVSAT ARTCO2->EXPCO2 ARTCO2->CATECHOL PVSAT->SAO2 SAO2->CATECHOL HR HR CATECHOL->HR HR->HRBP HR->HRSAT HR->CO HR->HREKG CO->BP

Visualisation and inspection

In [4]:
print(bn.variableFromName('SHUNT'))
SHUNT<NORMAL,HIGH>
In [5]:
print(bn.cpt(bn.idFromName('SHUNT')))
<SHUNT:NORMAL|PULMEMBOLUS:TRUE|INTUBATION:NORMAL> :: 0.1 /<SHUNT:HIGH|PULMEMBOLUS:TRUE|INTUBATION:NORMAL> :: 0.9 /<SHUNT:NORMAL|PULMEMBOLUS:FALSE|INTUBATION:NORMAL> :: 0.95 /<SHUNT:HIGH|PULMEMBOLUS:FALSE|INTUBATION:NORMAL> :: 0.05 /<SHUNT:NORMAL|PULMEMBOLUS:TRUE|INTUBATION:ESOPHAGEAL> :: 0.1 /<SHUNT:HIGH|PULMEMBOLUS:TRUE|INTUBATION:ESOPHAGEAL> :: 0.9 /<SHUNT:NORMAL|PULMEMBOLUS:FALSE|INTUBATION:ESOPHAGEAL> :: 0.95 /<SHUNT:HIGH|PULMEMBOLUS:FALSE|INTUBATION:ESOPHAGEAL> :: 0.05 /<SHUNT:NORMAL|PULMEMBOLUS:TRUE|INTUBATION:ONESIDED> :: 0.01 /<SHUNT:HIGH|PULMEMBOLUS:TRUE|INTUBATION:ONESIDED> :: 0.99 /<SHUNT:NORMAL|PULMEMBOLUS:FALSE|INTUBATION:ONESIDED> :: 0.05 /<SHUNT:HIGH|PULMEMBOLUS:FALSE|INTUBATION:ONESIDED> :: 0.95
In [6]:
gnb.showPotential(bn.cpt(bn.idFromName('SHUNT')),digits=3)
SHUNT
INTUBATION
PULMEMBOLUS
NORMAL
HIGH
NORMAL
TRUE
0.10000.9000
FALSE
0.95000.0500
ESOPHAGEAL
TRUE
0.10000.9000
FALSE
0.95000.0500
ONESIDED
TRUE
0.01000.9900
FALSE
0.05000.9500

Results of inference

It is easy to look at result of inference

In [7]:
gnb.showPosterior(bn,{'SHUNT':'HIGH'},'PRESS')
In [8]:
gnb.showPosterior(bn,{'MINVOLSET':'NORMAL'},'VENTALV')

Overall results

In [9]:
gnb.showInference(bn,size="10",evs={'MINVOLSET':'NORMAL'})
structs Inference in   7.72ms KINKEDTUBE VENTLUNG KINKEDTUBE->VENTLUNG PRESS KINKEDTUBE->PRESS HYPOVOLEMIA STROKEVOLUME HYPOVOLEMIA->STROKEVOLUME LVEDVOLUME HYPOVOLEMIA->LVEDVOLUME INTUBATION SHUNT INTUBATION->SHUNT INTUBATION->VENTLUNG MINVOL INTUBATION->MINVOL INTUBATION->PRESS VENTALV INTUBATION->VENTALV MINVOLSET VENTMACH MINVOLSET->VENTMACH PULMEMBOLUS PAP PULMEMBOLUS->PAP PULMEMBOLUS->SHUNT INSUFFANESTH CATECHOL INSUFFANESTH->CATECHOL ERRLOWOUTPUT HRBP ERRLOWOUTPUT->HRBP ERRCAUTER HRSAT ERRCAUTER->HRSAT HREKG ERRCAUTER->HREKG FIO2 PVSAT FIO2->PVSAT LVFAILURE LVFAILURE->STROKEVOLUME LVFAILURE->LVEDVOLUME HISTORY LVFAILURE->HISTORY DISCONNECT VENTTUBE DISCONNECT->VENTTUBE ANAPHYLAXIS TPR ANAPHYLAXIS->TPR CO STROKEVOLUME->CO TPR->CATECHOL BP TPR->BP PCWP LVEDVOLUME->PCWP CVP LVEDVOLUME->CVP VENTMACH->VENTTUBE SAO2 SHUNT->SAO2 VENTTUBE->VENTLUNG VENTTUBE->PRESS VENTLUNG->MINVOL VENTLUNG->VENTALV EXPCO2 VENTLUNG->EXPCO2 ARTCO2 VENTALV->ARTCO2 VENTALV->PVSAT ARTCO2->EXPCO2 ARTCO2->CATECHOL PVSAT->SAO2 SAO2->CATECHOL HR