Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  credalNetworks 
pyAgrum 0.15.2   
Zipped notebooks   
generation: 2019-07-22 10:34  

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.2 (default, Jan 10 2019, 23:51:51) [GCC 8.2.1 20181127]
IPython7.3.0
MatPlotLib3.0.2
Numpy1.16.1
pyAgrum0.14.1.9
Mon Feb 25 18:33:17 2019 CET

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.6946835443037976, 0.5636743215031316)
(0.43632567849686843, 0.3053164556962025)

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.718137448660721, 12.08366407146484, 11.961533682194089, 11.965402113597833, 11.96497391812688, 11.965020030630079, 11.965015169270032, 11.96501567303239)
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 0x7fa2899b3390>
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 0x7fa2880194a8>
In [15]:
ie=gum.CNMonteCarloSampling(cn)
ie.insertModalsFile(os.path.join("res","cn/modalities.modal"))

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

gnb.animApproximationScheme(ie)
ie.makeInference()

fig=figure()
ax=fig.add_subplot(111)
ax.fill_between(range(9),ie.dynamicExpMax("temp"),ie.dynamicExpMin("temp"))
Out[15]:
<matplotlib.collections.PolyCollection at 0x7fa2c50329e8>
In [ ]: