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='4', format='svg', 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
  • format – render as “png” or “svg”
  • 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='4', format='png')

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
  • format – render as “png” or “svg”
pyAgrum.lib.notebook.getDot(dotstring, size='4', format='png')

get a dot string as a HTML string

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

the HTML representation of the graph

pyAgrum.lib.notebook.getGraph(gr, size='4', format='png')

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='7', format='png', nodeColor=None, arcWidth=None, cmap=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
  • format (string) – render as “png” or “svg”
  • 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
  • cmap – color map to show the color of nodes and arcs
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='4', format='png')

get a HTML string for an influence diagram as a graph

Parameters:
  • diag – the influence diagram
  • size – size of the rendered graph
  • format – render as “png” or “svg”
Returns:

the HTML representation of the influence diagram

pyAgrum.lib.notebook.getInformation(bn, evs=None, size='4', 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='4', format='png')

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
  • format – render as “png” or “svg”
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=4, 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='4', format='svg', 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
  • format – render as “png” or “svg”
  • 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='4', format='png')

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
  • format – render as “png” or “svg”
pyAgrum.lib.notebook.showDot(dotstring, size='4', format='png')

show a dot string as a graph

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

the representation of the graph

pyAgrum.lib.notebook.showGraph(gr, size='4', format='png')

show a pydot graph in a notebook

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

the representation of the graph

pyAgrum.lib.notebook.showInference(bn, engine=None, evs=None, targets=None, size='7', format='png', nodeColor=None, arcWidth=None, cmap=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
  • format (string) – render as “png” or “svg”
  • asString (boolean) – display the graph or return a string containing the corresponding HTML fragment
Returns:

the desired representation of the inference

pyAgrum.lib.notebook.showInfluenceDiagram(diag, size='4', format='png')

show an influence diagram as a graph

Parameters:
  • diag – the influence diagram
  • size – size of the rendered graph
  • format – render as “png” or “svg”
Returns:

the representation of the influence diagram

pyAgrum.lib.notebook.showInformation(bn, evs=None, size='4', 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='4', format='png')

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
  • format – render as “png” or “svg”
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=4, 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)

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)

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=4, 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=4, 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='4', format='png')

get a dot string as a HTML string

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

the HTML representation of the graph

pyAgrum.lib.notebook.showDot(dotstring, size='4', format='png')

show a dot string as a graph

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

the representation of the graph

pyAgrum.lib.notebook.getGraph(gr, size='4', format='png')

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='4', format='png')

show a pydot graph in a notebook

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

the representation of the graph

Visualization of graphical models

pyAgrum.lib.notebook.getBN(bn, size='4', format='svg', 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
  • format – render as “png” or “svg”
  • 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='4', format='svg', 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
  • format – render as “png” or “svg”
  • 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='7', format='png', nodeColor=None, arcWidth=None, cmap=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
  • format (string) – render as “png” or “svg”
  • 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
  • cmap – color map to show the color of nodes and arcs
Returns:

the desired representation of the inference

pyAgrum.lib.notebook.showInference(bn, engine=None, evs=None, targets=None, size='7', format='png', nodeColor=None, arcWidth=None, cmap=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
  • format (string) – render as “png” or “svg”
  • asString (boolean) – display the graph or return a string containing the corresponding HTML fragment
Returns:

the desired representation of the inference

pyAgrum.lib.notebook.getJunctionTree(bn, withNames=True, size='4', format='png')

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
  • format – render as “png” or “svg”
Returns:

the HTML representation of the graph

pyAgrum.lib.notebook.showJunctionTree(bn, withNames=True, size='4', format='png')

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
  • format – render as “png” or “svg”
Returns:

the representation of the graph

pyAgrum.lib.notebook.showInformation(bn, evs=None, size='4', 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='4', 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='4', format='png')

show an influence diagram as a graph

Parameters:
  • diag – the influence diagram
  • size – size of the rendered graph
  • format – render as “png” or “svg”
Returns:

the representation of the influence diagram

pyAgrum.lib.notebook.getInfluenceDiagram(diag, size='4', format='png')

get a HTML string for an influence diagram as a graph

Parameters:
  • diag – the influence diagram
  • size – size of the rendered graph
  • format – render as “png” or “svg”
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