Skip to content

*fast* syntax

Quick specification of discrete random variables

Section titled “Quick specification of discrete random variables”

aGrUM/pyAgrum offers a so-called fast syntax that allows to quickly and compactly specify prototypes of graphical models.

The type of the (discrete) random variables can be specifiy with different syntaxes:

Use fast syntax to add a variable in the BayesNet.

  • Raises: pyagrum.NotAllowed
  • Parameters:
    • fast_description (str) – string following fast syntax description
    • default_nbrmod (int) – nbr of modality if fast_description does not indicate it. default_nbrmod=1 is the way to create a variable with only one value (for instance for reward in influence diagram).
  • Return type: DiscreteVariable

Examples

>>> print(pyagrum.fastVariable('A{On|Off|Defun}'))
A:Labelized({On|Off|Defun})
>>> print(pyagrum.fastVariable('A{3.14|0|1.15}'))
A:NumericalDiscrete({0|1.15|3.14})
>>> print(pyagrum.fastVariable('A{1.2:5.2:5}}'))
A:NumericalDiscrete({1.2|2.2|3.2|4.2|5.2})
>>> print(pyagrum.fastVariable('A{1|3|9}'))
A:Integer({1|3|9})
>>> print(pyagrum.fastVariable('A[4,6]'))
A:Range([4,6])
>>> print(pyagrum.fastVariable('A[5]'))
A:Range([0,4])
>>> print(pyagrum.fastVariable('A[4,6,10]'))
A:Discretized(<[4;6[,[6;10]>)
>>> print(pyagrum.fastVariable('A[1:6:5]'))
A:Discretized(<[1;2[,[2;3[,[3;4[,[4;5[,[5;6]>)

Quick specification of (randomly parameterized) graphical models

Section titled “Quick specification of (randomly parameterized) graphical models”

These fastPrototype aGrUM’s methods have also been wrapped in functions of pyagrum.

pyagrum.fastBN("A[10]->B<-C{top|middle|bottom};B->D")

Note

  • If the dot-like string contains such a specification more than once for a variable, the first specification will be used.
  • the CPTs are randomly generated.

pyagrum.fastBN(structure, domain=‘[2]’)

Section titled “pyagrum.fastBN(structure, domain=‘[2]’)”

Create a Bayesian network with a dot-like syntax which specifies: : - the structure ‘a->b->c;b->d<-e;’,

  • the type of the variables with different syntax (cf documentation).

Examples

>>> import pyagrum as gum
>>> bn=pyagrum.fastBN('A->B[1,3]<-C{yes|No}->D[2,4]<-E[1,2.5,3.9]',6)
  • Parameters:
    • structure (str) – the string containing the specification
    • domain (int or str) – the default domain size (int) or domain specification (str) for variables (default is “[2]”
  • Returns: the resulting bayesian network
  • Return type: pyagrum.BayesNet

pyagrum.fastMRF(structure, domain=‘[2]’)

Section titled “pyagrum.fastMRF(structure, domain=‘[2]’)”

Create a Markov random field with a modified dot-like syntax which specifies: : - the structure ‘a-b-c;b-d;c-e;’ where each chain ‘a-b-c’ specifies a factor,

  • the type of the variables with different syntax (cf documentation).

Examples

>>> import pyagrum as gum
>>> bn=pyagrum.fastMRF('A--B[1,3]--C{yes|No};C--D[2,4]--E[1,2.5,3.9]',6)
  • Parameters:
    • structure (str) – the string containing the specification
    • domain (int or str) – the default domain size (int) or domain specification (str) for variables (default is “[2]”
  • Returns: the resulting Markov random field
  • Return type: pyagrum.MarkovRandomField

pyagrum.fastID(structure, domain=‘[2]’)

Section titled “pyagrum.fastID(structure, domain=‘[2]’)”

Create an Influence Diagram with a modified dot-like syntax which specifies: : - the structure and the type of the variables following fast syntax,

  • a prefix for the type of node (chance/decision/utiliy nodes):
    • a : a chance node named ‘a’ (by default)
    • $a : a utility node named ‘a’
    • *a : a decision node named ‘a’

Examples

>>> import pyagrum as gum
>>> bn=pyagrum.fastID('A->B[1,3]<-*C{yes|No}->$D<-E[1,2.5,3.9]',6)
  • Parameters:
    • structure (str) – the string containing the specification
    • domain (int or str) – the default domain size (int) or domain specification (str) for variables (default is “[2]”
  • Returns: the resulting Influence Diagram
  • Return type: pyagrum.InfluenceDiagram