Module notebook

tools for BN analysis in jupyter notebook

pyAgrum.lib.notebook.animApproximationScheme(apsc, scale=<ufunc 'log10'>)

show an animated version of an approximation algorithm

Parameters:
  • apsc – the approximation algorithm
  • scale – a function to apply to the figure
pyAgrum.lib.notebook.configuration()

Display the collection of dependance and versions

pyAgrum.lib.notebook.getBN(bn, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None)

get a HTML string for a Bayesian network

Parameters:
  • bn – the bayesian network
  • size – 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)
  • 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 colors
  • cmapArc – color map to show the arc color if distinction is needed
Returns:

the graph

pyAgrum.lib.notebook.getBNDiff(bn1, bn2, size=None)

get a HTML string representation of a graphical diff between the arcs of _bn1 (reference) with those of _bn2.

  • full black line: the arc is common for both
  • full red line: the arc is common but inverted in _bn2
  • dotted black line: the arc is added in _bn2
  • dotted red line: the arc is removed in _bn2
Parameters:
  • bn1 (BayesNet) – referent model for the comparison
  • bn2 (BayesNet) – bn compared to the referent model
  • size – size of the rendered graph
pyAgrum.lib.notebook.getDot(dotstring, size=None)

get a dot string as a HTML string

Parameters:
  • dotstring – dot string
  • size – size of the rendered graph
  • format – render as “png” or “svg”
  • bg – color for background
Returns:

the HTML representation of the graph

pyAgrum.lib.notebook.getGraph(gr, size=None)

get a HTML string representation of pydot graph

Parameters:
  • gr – pydot graph
  • size – size of the rendered graph
  • format – render as “png” or “svg”
Returns:

the HTML representation of the graph as a string

pyAgrum.lib.notebook.getInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None, dag=None)

get a HTML string for an inference in a notebook

Parameters:
  • bn (gum.BayesNet) –
  • engine (gum.Inference) – inference algorithm used. If None, LazyPropagation will be used
  • 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)
  • 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.

:param dag : only shows nodes that have their id in the dag (and not in the whole BN)

Returns:the desired representation of the inference
pyAgrum.lib.notebook.getInferenceEngine(ie, inferenceCaption)

display an inference as a BN+ lists of hard/soft evidence and list of targets

Parameters:
  • ie (gum.InferenceEngine) – inference engine
  • inferenceCaption (string) – title for caption
pyAgrum.lib.notebook.getInfluenceDiagram(diag, size=None)

get a HTML string for an influence diagram as a graph

Parameters:
  • diag – the influence diagram
  • size – size of the rendered graph
Returns:

the HTML representation of the influence diagram

pyAgrum.lib.notebook.getInformation(bn, evs=None, size=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>)

get a HTML string for a bn annoted with results from inference : entropy and mutual informations

Parameters:
  • bn – the BN
  • evs – map of evidence
  • size – size of the graph
  • cmap – colour map used
Returns:

the HTML string

pyAgrum.lib.notebook.getJunctionTree(bn, withNames=True, size=None)

get a HTML string for a junction tree (more specifically a join tree)

Parameters:
  • bn – the bayesian network
  • withNames (boolean) – display the variable names or the node id in the clique
  • size – size of the rendered graph
Returns:

the HTML representation of the graph

pyAgrum.lib.notebook.getPosterior(bn, evs, target)

shortcut for getProba(gum.getPosterior(bn,evs,target))

Parameters:
  • bn (gum.BayesNet) – the BayesNet
  • evs (dict(str->int)) – map of evidence
  • target (str) – name of target variable
Returns:

the matplotlib graph

pyAgrum.lib.notebook.getPotential(pot, digits=None, withColors=None, varnames=None)

return a HTML string of a gum.Potential as a HTML table. The first dimension is special (horizontal) due to the representation of conditional probability table

Parameters:
  • pot (gum.Potential) – the potential to get
  • digits (int) – number of digits to show
  • of strings varnames (list) – the aliases for variables name in the table
Param:

boolean withColors : bgcolor for proba cells or not

Returns:

the HTML string

pyAgrum.lib.notebook.getSideBySide(*args, **kwargs)

create an HTML table for args as string (using string, _repr_html_() or str())

Parameters:
  • args – HMTL fragments as string arg, arg._repr_html_() or str(arg)
  • captions – list of strings (captions)
Returns:

a string representing the table

pyAgrum.lib.notebook.showBN(bn, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None)

show a Bayesian network

Parameters:
  • bn – the bayesian network
  • size – 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)
  • 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 colors
  • cmapArc – color map to show the arc color if distinction is needed
Returns:

the graph

pyAgrum.lib.notebook.showBNDiff(bn1, bn2, size=None)

show a graphical diff between the arcs of _bn1 (reference) with those of _bn2.

  • full black line: the arc is common for both
  • full red line: the arc is common but inverted in _bn2
  • dotted black line: the arc is added in _bn2
  • dotted red line: the arc is removed in _bn2
Parameters:
  • bn1 (BayesNet) – referent model for the comparison
  • bn2 (BayesNet) – bn compared to the referent model
  • size – size of the rendered graph
pyAgrum.lib.notebook.showDot(dotstring, size=None)

show a dot string as a graph

Parameters:
  • dotstring – dot string
  • size – size of the rendered graph
Returns:

the representation of the graph

pyAgrum.lib.notebook.showGraph(gr, size=None)

show a pydot graph in a notebook

Parameters:
  • gr – pydot graph
  • size – size of the rendered graph
Returns:

the representation of the graph

pyAgrum.lib.notebook.showInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None, dag=None)

show pydot graph for an inference in a notebook

Parameters:
  • bn (gum.BayesNet) –
  • engine (gum.Inference) – inference algorithm used. If None, LazyPropagation will be used
  • 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)
  • 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.

:param dag : only shows nodes that have their id in the dag (and not in the whole BN)

Returns:the desired representation of the inference
pyAgrum.lib.notebook.showInfluenceDiagram(diag, size=None)

show an influence diagram as a graph

Parameters:
  • diag – the influence diagram
  • size – size of the rendered graph
Returns:

the representation of the influence diagram

pyAgrum.lib.notebook.showInformation(bn, evs=None, size=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>)

show a bn annoted with results from inference : entropy and mutual informations

Parameters:
  • bn – the BN
  • evs – map of evidence
  • size – size of the graph
  • cmap – colour map used
Returns:

the graph

pyAgrum.lib.notebook.showJunctionTree(bn, withNames=True, size=None)

Show a junction tree

Parameters:
  • bn – the bayesian network
  • withNames (boolean) – display the variable names or the node id in the clique
  • size – size of the rendered graph
Returns:

the representation of the graph

pyAgrum.lib.notebook.showPosterior(bn, evs, target)

shortcut for showProba(gum.getPosterior(bn,evs,target))

Parameters:
  • bn – the BayesNet
  • evs – map of evidence
  • target – name of target variable
pyAgrum.lib.notebook.showPotential(pot, digits=None, withColors=None, varnames=None)

show a gum.Potential as a HTML table. The first dimension is special (horizontal) due to the representation of conditional probability table

Parameters:
  • pot (gum.Potential) – the potential to get
  • digits (int) – number of digits to show
  • of strings varnames (list) – the aliases for variables name in the table
Param:

boolean withColors : bgcolor for proba cells or not

Returns:

the display of the potential

pyAgrum.lib.notebook.showProba(p, scale=1.0)

Show a mono-dim Potential

Parameters:p – the mono-dim Potential
Returns:
pyAgrum.lib.notebook.sideBySide(*args, **kwargs)

display side by side args as HMTL fragment (using string, _repr_html_() or str())

Parameters:
  • args – HMTL fragments as string arg, arg._repr_html_() or str(arg)
  • captions – list of strings (captions)
_images/pyAgrum_all.png

Helpers

pyAgrum.lib.notebook.configuration()

Display the collection of dependance and versions

pyAgrum.lib.notebook.sideBySide(*args, **kwargs)

display side by side args as HMTL fragment (using string, _repr_html_() or str())

Parameters:
  • args – HMTL fragments as string arg, arg._repr_html_() or str(arg)
  • captions – list of strings (captions)

Visualization of Potentials

pyAgrum.lib.notebook.showProba(p, scale=1.0)

Show a mono-dim Potential

Parameters:p – the mono-dim Potential
Returns:
pyAgrum.lib.notebook.getPosterior(bn, evs, target)

shortcut for getProba(gum.getPosterior(bn,evs,target))

Parameters:
  • bn (gum.BayesNet) – the BayesNet
  • evs (dict(str->int)) – map of evidence
  • target (str) – name of target variable
Returns:

the matplotlib graph

pyAgrum.lib.notebook.showPosterior(bn, evs, target)

shortcut for showProba(gum.getPosterior(bn,evs,target))

Parameters:
  • bn – the BayesNet
  • evs – map of evidence
  • target – name of target variable
pyAgrum.lib.notebook.getPotential(pot, digits=None, withColors=None, varnames=None)

return a HTML string of a gum.Potential as a HTML table. The first dimension is special (horizontal) due to the representation of conditional probability table

Parameters:
  • pot (gum.Potential) – the potential to get
  • digits (int) – number of digits to show
  • of strings varnames (list) – the aliases for variables name in the table
Param:

boolean withColors : bgcolor for proba cells or not

Returns:

the HTML string

pyAgrum.lib.notebook.showPotential(pot, digits=None, withColors=None, varnames=None)

show a gum.Potential as a HTML table. The first dimension is special (horizontal) due to the representation of conditional probability table

Parameters:
  • pot (gum.Potential) – the potential to get
  • digits (int) – number of digits to show
  • of strings varnames (list) – the aliases for variables name in the table
Param:

boolean withColors : bgcolor for proba cells or not

Returns:

the display of the potential

Visualization of graphs

pyAgrum.lib.notebook.getDot(dotstring, size=None)

get a dot string as a HTML string

Parameters:
  • dotstring – dot string
  • size – size of the rendered graph
  • format – render as “png” or “svg”
  • bg – color for background
Returns:

the HTML representation of the graph

pyAgrum.lib.notebook.showDot(dotstring, size=None)

show a dot string as a graph

Parameters:
  • dotstring – dot string
  • size – size of the rendered graph
Returns:

the representation of the graph

pyAgrum.lib.notebook.getGraph(gr, size=None)

get a HTML string representation of pydot graph

Parameters:
  • gr – pydot graph
  • size – size of the rendered graph
  • format – render as “png” or “svg”
Returns:

the HTML representation of the graph as a string

pyAgrum.lib.notebook.showGraph(gr, size=None)

show a pydot graph in a notebook

Parameters:
  • gr – pydot graph
  • size – size of the rendered graph
Returns:

the representation of the graph

Visualization of graphical models

pyAgrum.lib.notebook.getBN(bn, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None)

get a HTML string for a Bayesian network

Parameters:
  • bn – the bayesian network
  • size – 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)
  • 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 colors
  • cmapArc – color map to show the arc color if distinction is needed
Returns:

the graph

pyAgrum.lib.notebook.showBN(bn, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None)

show a Bayesian network

Parameters:
  • bn – the bayesian network
  • size – 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)
  • 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 colors
  • cmapArc – color map to show the arc color if distinction is needed
Returns:

the graph

pyAgrum.lib.notebook.getInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None, dag=None)

get a HTML string for an inference in a notebook

Parameters:
  • bn (gum.BayesNet) –
  • engine (gum.Inference) – inference algorithm used. If None, LazyPropagation will be used
  • 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)
  • 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.

:param dag : only shows nodes that have their id in the dag (and not in the whole BN)

Returns:the desired representation of the inference
pyAgrum.lib.notebook.showInference(bn, engine=None, evs=None, targets=None, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None, dag=None)

show pydot graph for an inference in a notebook

Parameters:
  • bn (gum.BayesNet) –
  • engine (gum.Inference) – inference algorithm used. If None, LazyPropagation will be used
  • 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)
  • 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.

:param dag : only shows nodes that have their id in the dag (and not in the whole BN)

Returns:the desired representation of the inference
pyAgrum.lib.notebook.getJunctionTree(bn, withNames=True, size=None)

get a HTML string for a junction tree (more specifically a join tree)

Parameters:
  • bn – the bayesian network
  • withNames (boolean) – display the variable names or the node id in the clique
  • size – size of the rendered graph
Returns:

the HTML representation of the graph

pyAgrum.lib.notebook.showJunctionTree(bn, withNames=True, size=None)

Show a junction tree

Parameters:
  • bn – the bayesian network
  • withNames (boolean) – display the variable names or the node id in the clique
  • size – size of the rendered graph
Returns:

the representation of the graph

pyAgrum.lib.notebook.showInformation(bn, evs=None, size=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>)

show a bn annoted with results from inference : entropy and mutual informations

Parameters:
  • bn – the BN
  • evs – map of evidence
  • size – size of the graph
  • cmap – colour map used
Returns:

the graph

pyAgrum.lib.notebook.getInformation(bn, evs=None, size=None, cmap=<matplotlib.colors.LinearSegmentedColormap object>)

get a HTML string for a bn annoted with results from inference : entropy and mutual informations

Parameters:
  • bn – the BN
  • evs – map of evidence
  • size – size of the graph
  • cmap – colour map used
Returns:

the HTML string

pyAgrum.lib.notebook.showInfluenceDiagram(diag, size=None)

show an influence diagram as a graph

Parameters:
  • diag – the influence diagram
  • size – size of the rendered graph
Returns:

the representation of the influence diagram

pyAgrum.lib.notebook.getInfluenceDiagram(diag, size=None)

get a HTML string for an influence diagram as a graph

Parameters:
  • diag – the influence diagram
  • size – size of the rendered graph
Returns:

the HTML representation of the influence diagram

Visualization of approximation algorithm

pyAgrum.lib.notebook.animApproximationScheme(apsc, scale=<ufunc 'log10'>)

show an animated version of an approximation algorithm

Parameters:
  • apsc – the approximation algorithm
  • scale – a function to apply to the figure