Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  credalNetworks 
pyAgrum 0.16.3   
Zipped notebooks   
generation: 2019-10-20 09:16  

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

In [1]:
import os

%matplotlib inline
from pylab import *
import matplotlib.pyplot as plt
In [2]:
import pyAgrum as gum
import pyAgrum.lib.notebook as gnb
gnb.configuration()
LibraryVersion
OSposix [linux]
Python3.7.4 (default, Jul 16 2019, 07:12:58) [GCC 9.1.0]
IPython7.8.0
MatPlotLib3.1.1
Numpy1.17.2
pyAgrum0.16.2.9
Wed Oct 02 13:55:13 2019 CEST

Static Credal Net

In [3]:
cn=gum.CredalNet(os.path.join("res","cn/2Umin.bif"),os.path.join("res","cn/2Umax.bif"))
In [4]:
cn.intervalToCredal()
In [5]:
gnb.showBN(cn.current_bn(),"3")
G A A E E A->E B B B->E C C F F C->F D D D->F G G D->G H H E->H F->H L L H->L
In [6]:
ie=gum.CNMonteCarloSampling(cn)
ie.insertEvidenceFile(os.path.join("res","cn/L2U.evi"))
In [7]:
ie.setRepetitiveInd(False)

ie.setRepetitiveInd(False)
ie.setMaxTime(1)
ie.setMaxIter(1000)

ie.makeInference()
In [8]:
print(ie.marginalMax(0))
print(ie.marginalMin(0))
(0.6947454920765357, 0.5666134001087296)
(0.43338659989127026, 0.3052545079234643)

Dynamical Credal Net

In [9]:
cn=gum.CredalNet(os.path.join("res","cn/bn_c_8.bif"),os.path.join("res","cn/den_c_8.bif"))
cn.bnToCredal(0.8,False)
In [10]:
ie=gum.CNMonteCarloSampling(cn)
ie.insertModalsFile(os.path.join("res","cn/modalities.modal"))

ie.setRepetitiveInd(True)
ie.setMaxTime(30)
ie.setMaxIter(1000)

ie.makeInference()
In [11]:
print(ie.dynamicExpMax("temp"))
(14.20340463585978, 11.911090727297022, 12.190483111797988, 12.031555626094853, 12.003107222323997, 12.008870939724428, 12.007860681770776, 12.007682976449974, 12.007727248106775)
In [12]:
fig=figure()
ax=fig.add_subplot(111)
ax.fill_between(range(9),ie.dynamicExpMax("temp"),ie.dynamicExpMin("temp"))
Out[12]:
<matplotlib.collections.PolyCollection at 0x7f3f1d55c3d0>
In [13]:
ie=gum.CNMonteCarloSampling(cn)
ie.insertModalsFile(os.path.join("res","cn/modalities.modal"))

ie.setRepetitiveInd(False)
ie.setMaxTime(30)
ie.setMaxIter(1000)

ie.makeInference()
In [14]:
fig=figure()
ax=fig.add_subplot(111)
ax.fill_between(range(9),ie.dynamicExpMax("temp"),ie.dynamicExpMin("temp"))
Out[14]:
<matplotlib.collections.PolyCollection at 0x7f3fa964db10>
In [15]:
ie=gum.CNMonteCarloSampling(cn)
ie.insertModalsFile(os.path.join("res","cn/modalities.modal"))

ie.setRepetitiveInd(False)
ie.setMaxTime(30)
ie.setMaxIter(2000)

gnb.animApproximationScheme(ie)
ie.makeInference()
In [16]:
fig=figure()
ax=fig.add_subplot(111)
ax.fill_between(range(9),ie.dynamicExpMax("temp"),ie.dynamicExpMin("temp"));
In [ ]: