# Functions from pyAgrum¶

Useful functions in pyAgrum

pyAgrum.about()

pyAgrum.fastBN(arcs, domain_size=2)

rapid prototyping of BN.

Parameters: arcs – dot-like simple list of arcs (“a->b->c;a->c->d” for instance). The first apparition of a node name can be enhanced with a “[domain_size]” extension. For instance “a[5]->b->c;a[2]->c->d” will create a BN with a variable “a” whos domain size is a.nbrDim()==5 (the second “a[2]” is not taken into account since the variable has already been created). domain_size – the domain size of each created variable. the created pyAgrum.BayesNet
pyAgrum.getPosterior(bn, evs, target)

Compute the posterior of a single target (variable) in a BN given evidence

getPosterior uses a VariableElimination inference. If more than one target is needed with the same set of evidence or if the same target is needed with more than one set of evidence, this function is not relevant since it creates a new inference engine every time it is called.

Parameters: bn (pyAgrum.BayesNet) – evs (dictionary) – events map {name/id:val, name/id : [ val1, val2 ], …} target – variable name or id posterior Potential

## Input/Output for bayesian networks¶

pyAgrum.availableBNExts()
Returns: a string which lists all suffixes for supported BN file formats.
pyAgrum.loadBN(filename, listeners=None, verbose=False, **opts)
Parameters: filename – the name of the input file listeners – list of functions to execute verbose – whether to print or not warning messages system – (for O3PRM) name of the system to flatten in a BN classpath – (for O3PRM) list of folders containing classes a BN from a file using one of the availableBNExts() suffixes.

Examples

>>> import pyAgrum as gum
>>>
>>> # creating listeners
>>> def foo_listener(progress):
>>>    if progress==200:
>>>        return
>>>    elif progress==100:
>>>        car='%'
>>>    elif progress%10==0:
>>>        car='#'
>>>    else:
>>>        car='.'
>>>    print(car,end='',flush=True)
>>>
>>> def bar_listener(progress):
>>>    if progress==50:
>>>        print('50%')
>>>
>>> # loadBN with list of listeners
>>> # .........#.........#.........#.........#..50%
>>> # .......#.........#.........#.........#.........#.........% | bn loaded

pyAgrum.saveBN(bn, filename)

save a BN into a file using the format corresponding to one of the availableWriteBNExts() suffixes.

## Input for influence diagram¶

pyAgrum.loadID(filename)

read a gum.InfluenceDiagram from a bifxml file

Parameters: filename – the name of the input file an InfluenceDiagram