pyAgrum.lib.image¶
pyAgrum.lib.image aims to graphically export models and inference using pydot (and then graphviz).
For more details, <https://lip6.fr/Pierre-Henri.Wuillemin/aGrUM/docs/last/notebooks/colouringAndExportingBNs.ipynb.html>
1import pyAgrum as gum
2from pyAgrum.lib.image as gumimage
3
4bn = gum.fastBN("a->b->d;a->c->d[3]->e;f->b")
5gumimage.export(bn,"out/test_export.png",
6 nodeColor={'a': 1,
7 'b': 0.3,
8 'c': 0.4,
9 'd': 0.1,
10 'e': 0.2,
11 'f': 0.5},
12 arcColor={(0, 1): 0.2,
13 (1, 2): 0.5},
14 arcWidth={(0, 3): 0.4,
15 (3, 2): 0.5,
16 (2,4) :0.6})
Visualization of models and inference¶
- pyAgrum.lib.image.export(model, filename=None, **kwargs)¶
export the graphical representation of the model in filename (png, pdf,etc.)
- Parameters
model (GraphicalModel) – the model to show (pyAgrum.BayesNet, pyAgrum.MarkovNet, pyAgrum.InfluenceDiagram or pyAgrum.Potential)
filename (str) – the name of the resulting file (suffix in [‘pdf’, ‘png’, ‘fig’, ‘jpg’, ‘svg’, ‘ps’]). If filename is None, the result is a np.array ready to be used with imshow().
Warning
Model can also just possess a method toDot() or even be a simple string in dot syntax.
- pyAgrum.lib.image.exportInference(model, filename=None, **kwargs)¶
the graphical representation of an inference in a notebook
- Parameters
model (GraphicalModel) – the model in which to infer (pyAgrum.BayesNet, pyAgrum.MarkovNet or pyAgrum.InfluenceDiagram)
filename (str) – the name of the resulting file (suffix in [‘pdf’, ‘png’, ‘ps’]). If filename is None, the result is a np.array ready to be used with imshow().
engine (gum.Inference) – inference algorithm used. If None, gum.LazyPropagation will be used for BayesNet, gum.ShaferShenoy for gum.MarkovNet and gum.ShaferShenoyLIMIDInference for gum.InfluenceDiagram.
evs (dictionnary) – map of evidence
targets (set) – set of targets
size (string) – size of the rendered graph
nodeColor – a nodeMap of values (between 0 and 1) to be shown as color of nodes (with special colors for 0 and 1)
factorColor – a nodeMap of values (between 0 and 1) to be shown as color of factors (in MarkovNet representation)
arcWidth – a arcMap of values to be shown as width of arcs
arcColor – a arcMap of values (between 0 and 1) to be shown as color of arcs
cmap – color map to show the color of nodes and arcs
cmapArc – color map to show the vals of Arcs.
graph – only shows nodes that have their id in the graph (and not in the whole BN)
view – graph | factorgraph | None (default) for Markov network
- Returns
the desired representation of the inference