from pylab import *
import matplotlib.pyplot as plt
import pyAgrum as gum
import pyAgrum.lib.notebook as gnb
bn=gum.fastBN("a->b->c->d;b->e->d->f;g->c")
gnb.flow.row(bn,gnb.getInference(bn))
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()},
arcLabel={a:f"v={arcvalue(a):02d}" for a in bn.arcs()},
arcColor={a:arcvalue2(a) for a in bn.arcs()})
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()})
gnb.flow.row(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()})
)
import matplotlib.pyplot as plt
mycmap=plt.get_cmap('Reds')
formyarcs=plt.get_cmap('winter')
gnb.flow.row(gnb.getBN(bn,
nodeColor={n:nodevalue(n) for n in bn.names()},
arcColor={a:arcvalue2(a) for a in bn.arcs()},
cmapNode=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()},
cmapNode=mycmap,
cmapArc=formyarcs)
)
Exporting as image (pdf, png, etc.) has been gathered in 2 functions : pyAgrum.lib.image.export()
and pyAgrum.lib.image.exportInference()
. The argument are the same as for pyAgrum.notebook.show{Model}
and pyAgrum.notebook.show{Inference}
.
import pyAgrum.lib.image as gumimage
from IPython.display import Image # to display the exported images
gumimage.export(bn,"out/test_export.png")
Image(filename='out/test_export.png')
bn = gum.fastBN("a->b->d;a->c->d[3]->e;f->b")
gumimage.export(bn,"out/test_export.png",
nodeColor={'a': 1,
'b': 0.3,
'c': 0.4,
'd': 0.1,
'e': 0.2,
'f': 0.5},
arcColor={(0, 1): 0.2,
(1, 2): 0.5},
arcWidth={(0, 3): 0.4,
(3, 2): 0.5,
(2,4) :0.6})
Image(filename='out/test_export.png')