Functions from pyAgrum¶
Useful functions in pyAgrum
-
pyAgrum.
about
()¶ about() for pyAgrum
-
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.
Returns: 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
Returns: posterior Potential
Input/Output for bayesian networks¶
-
pyAgrum.
availableBNExts
()¶ Give the list of all formats known by pyAgrum to save a Bayesian network.
Returns: a string which lists all suffixes for supported BN file formats.
-
pyAgrum.
loadBN
(filename, listeners=None, verbose=False, **opts)¶ load a file with optional listeners and arguments
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
Returns: a BN from a file using one of the availableBNExts() suffixes.
Listeners could be added in order to monitor its loading.
Examples
>>> import pyAgrum as gum >>> >>> # creating listeners >>> def foo_listener(progress): >>> if progress==200: >>> print(' BN loaded ') >>> 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 >>> gum.loadBN('./bn.bif',listeners=[foo_listener,bar_listener]) >>> # .........#.........#.........#.........#..50% >>> # .......#.........#.........#.........#.........#.........% | bn loaded
-
pyAgrum.
saveBN
(bn, filename)¶ save a BN into a file using the format corresponding to one of the availableWriteBNExts() suffixes.
Parma bn(gum.BayesNet): the BN to save Parameters: filename(str) – the name of the output file