Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  colouringBNs 
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]:
from pylab import *
import matplotlib.pyplot as plt
In [2]:
import pyAgrum as gum
import pyAgrum.lib.notebook as gnb
gnb.forDarkTheme()

bn=gum.fastBN("a->b->c->d;b->e->d->f;g->c")
gnb.sideBySide(bn,gnb.getInference(bn))
G a a b b a->b c c b->c e e b->e d d c->d f f d->f e->d g g g->c
structs Inference in   0.85ms a b a->b c b->c e b->e d c->d f d->f e->d g g->c
In [3]:
def nodevalue(n):
    return 0.5 if n in "aeiou" else 0.7
def arcvalue(a):
    return (10-a[0])*a[1]
def arcvalue2(a):
    return (a[0]+a[1]+5)/22
gnb.showBN(bn,
           nodeColor={n:nodevalue(n) for n in bn.names()},
           arcWidth={a:arcvalue(a) for a in bn.arcs()},
           arcColor={a:arcvalue2(a) for a in bn.arcs()})
G a a b b a->b c c b->c e e b->e d d c->d f f d->f e->d g g g->c
In [4]:
gnb.showInference(bn,
           targets={"a","g","f","b"},
           evs={'e':0},
           nodeColor={n:nodevalue(n) for n in bn.names()},
           arcWidth={a:arcvalue(a) for a in bn.arcs()})
structs Inference in   1.27ms a b a->b c c b->c e e b->e d d c->d f d->f e->d g g->c
In [5]:
gnb.sideBySide(gnb.getBN(bn,
                         nodeColor={n:nodevalue(n) for n in bn.names()},
                         arcWidth={a:arcvalue(a) for a in bn.arcs()}),
               gnb.getInference(bn,
                                nodeColor={n:nodevalue(n) for n in bn.names()},
                                arcWidth={a:arcvalue(a) for a in bn.arcs()})
              )
G a a b b a->b c c b->c e e b->e d d c->d f f d->f e->d g g g->c
structs Inference in   1.43ms a b a->b c b->c e b->e d c->d f d->f e->d g g->c
In [6]:
import matplotlib.pyplot as plt
mycmap=plt.get_cmap('Reds')
formyarcs=plt.get_cmap('winter')
gnb.sideBySide(gnb.getBN(bn,
                         nodeColor={n:nodevalue(n) for n in bn.names()},
                         arcColor={a:arcvalue2(a) for a in bn.arcs()},
                         cmap=mycmap,
                         cmapArc=formyarcs),
               gnb.getInference(bn,
                                nodeColor={n:nodevalue(n) for n in bn.names()},
                                arcColor={a:arcvalue2(a) for a in bn.arcs()},
                                arcWidth={a:arcvalue(a) for a in bn.arcs()},
                                cmap=mycmap,
                                cmapArc=formyarcs)
              )
G a a b b a->b c c b->c e e b->e d d c->d f f d->f e->d g g g->c
structs Inference in   1.79ms a b a->b c b->c e b->e d c->d f d->f e->d g g->c
In [ ]: