Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  credalNetworks 
pyAgrum 0.18.0   
Zipped notebooks   
generation: 2020-06-11 14:09  

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.8.3 (default, May 17 2020, 18:15:42) [GCC 10.1.0]
IPython7.15.0
MatPlotLib3.2.1
Numpy1.18.5
pyAgrum0.17.3.9
Wed Jun 10 14:19:59 2020 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.6951976906927922, 0.5671641791044777)
(0.43283582089552236, 0.3048023093072078)

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.203404648293022, 11.769513762315974, 12.190483075680442, 12.023367090540296, 12.004198572496797, 12.008328195599265, 12.007694250617146, 12.007688078235907, 12.00772208700393)
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 0x7ff744e5dd00>
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 0x7ff7447db4f0>
In [17]:
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 [ ]: