fast syntax
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:
by default, a variable is a
pyAgrum.RangeVariable
using the default domain size (second argument of the functions).with
a[10]
, the variable is apyAgrum.RangeVariable
using 10 as domain size (from 0 to 9)with
a[3,7]
, the variable is apyAgrum.RangeVariable
using the integer values from 3 to 7.with
a[1,3.14,5,6.2]
, the variable is apyAgrum.DiscretizedVariable
using the given ticks (at least 3 values).with
a[1:6.15:9]
, the variable is apyAgrum.DiscretizedVariable
using the ticks from 1 to 6.15 in 9 steps (the domain size is 9).with
a+[1,3.14,5,6.2]
, the variable is apyAgrum.DiscretizedVariable
using the given ticks (at least 3 values), empirical.with
a+[1:6.15:9]
, the variable is apyAgrum.DiscretizedVariable
using the ticks from 1 to 6.15 in 9 steps (the domain size is 9), empirical.with
a{top|middle|bottom}
, the variable is apyAgrum.LabelizedVariable
using the given labels (here : top, middle and bottom).with
a{-1|5|0|3}
, the variable is apyAgrum.IntegerVariable
using the sorted given values.with
a{-0.5|5.01|0|3.1415}
, the variable is apyAgrum.NumericalDiscreteVariable
using the sorted given values.with
a{-0.5:3.1415:5}
, the variable is apyAgrum.NumericalDiscreteVariable
using the values from -0.5 to 3.1415 in 5 steps (the domain size is 5).
- pyAgrum.fastVariable(*args)
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:
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
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]')
- 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.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.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: