Skip to content

Random Variables

aGrUM/pyAgrum is currently dedicated for discrete probability distributions.

There are 5 types of discrete random variables in aGrUM/pyAgrum: pyagrum.LabelizedVariable, pyagrum.DiscretizedVariable, pyagrum.IntegerVariable, pyagrum.RangeVariable and pyagrum.NumericalDiscreteVariable. The 5 types are mainly provided in order to ease modelization. Derived from DiscreteVariable, they share a common API. They essentially differ by the means to create, name and access to their modalities.

The function pyagrum.fastVariable() allows to easily create variables of any types with the fast syntax.

class pyagrum.DiscreteVariable(*args, **kwargs)

Section titled “class pyagrum.DiscreteVariable(*args, **kwargs)”

DiscreteVariable is the (abstract) base class for discrete random variables.

Tries to cast the variable as a pyagrum.DiscretizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.DiscretizedVar
  • Return type: DiscretizedVariable

Tries to cast the variable as a pyagrum.IntegerVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.IntegerVar
  • Return type: IntegerVariable

Tries to cast the variable as a pyagrum.LabelizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.LabelizedVar
  • Return type: LabelizedVariable

Tries to cast the variable as a pyagrum.NumericalDiscreteVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.NumericalDiscreteVar
  • Return type: NumericalDiscreteVariable

Tries to cast the variable as a pyagrum.RangeVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.RangeVar
  • Return type: RangeVariable

returns whether x belongs to the variable domain (if the variable is a pyagrum.RangeVariable)

  • Parameters: x (int) – the value for which we want to know if it belongs to the variable domain
  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: bool
  • Returns: bool : True if x belongs to the variable domain, False otherwise

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the index of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the index of the closest value to value in the variable’s domain
  • Return type: int
  • Raises: pyagrum.NotImplementedYet – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the label of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the label of the closest value to value in the variable’s domain
  • Return type: str
  • Raises: pyagrum.InvalidArgument – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).
  • Returns: the description of the variable
  • Return type: str
  • Returns: the domain of the variable
  • Return type: str
  • Returns: the number of modalities in the variable domain
  • Return type: int

Draw a random float value from the x-th interval of the variable (only for pyagrum.DiscretizedVariable).

  • Parameters: x (int) – the index of the interval from which to draw
  • Returns: a random value drawn uniformly from the x-th interval
  • Return type: float
  • Raises:
    • NotImplementedError – if the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – if x is not a valid interval index
  • Returns: True if the domain size < 2
  • Return type: bool
  • Parameters: label (str) – a label
  • Returns: the index of the label
  • Return type: int

Returns the integer domain of the variable (if the variable is a pyagrum.integerVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.IntegerVariable
  • Return type: tuple[int, ...]
  • Returns: tuple[int,…] : the integer domain of the variable

Returns whether the variable is empirical (if the variable is a pyagrum.DiscretizedVariable). I.e. whether its limits (max and min) are defined by data and accept any values below or above these limits, contrary to non-empirical discretized variables for which the limits are fixed and values outside of these limits are not accepted)

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: bool
  • Returns: bool : whether the variable is empirical

returns whether s is a label of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
  • Return type: bool
  • Returns: bool : True if s is a label of the variable, False otherwise
  • Parameters: s (str)

Returns True if the variable has a meaningful numerical representation, i.e. it is not a LabelizedVariable.

  • Returns: True for DiscretizedVariable, IntegerVariable, NumericalDiscreteVariable and RangeVariable; False for LabelizedVariable.
  • Return type: bool

Returns whether x is a tick for the variable

  • Parameters: x (float) – the value for which we want to know if it is a tick for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Returns: bool : whether x is a tick for the variable, i.e. whether x belongs to the variable’s domain

Returns whether x is a value for the variable

  • Parameters: x (float) – the value for which we want to know if it is a value for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable or a pyagrum.IntegerVariable
  • Return type: bool
  • Returns: bool : whether x is a value for the variable, i.e. whether x belongs to the variable domain
  • Parameters: i (int) – the index of the label we wish to return
  • Returns: the label at the given index
  • Return type: str
  • Raises: pyagrum.OutOfBounds – If the variable does not contain the label
  • Returns: a tuple containing the labels
  • Return type: tuple[str, ...]

returns the maximum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the maximum value of the variable domain

returns the minimum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the minimum value of the variable domain
  • Returns: the name of the variable
  • Return type: str
  • Parameters:
    • index (int) – an index
    • indice (int)
  • Returns: the numerical representation of the value at the given index
  • Return type: float

Returns the numerical domain of the variable (if the variable is a pyagrum.NumericalDiscreteVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the numerical domain of the variable

Returns the index of the label s in the variable’s domain (if the variable is a pyagrum.LabelizedVariable)

  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
    • NotFoundError – If the variable does not contain the label s
  • Return type: int
  • Returns: int : the index of the label s in the variable’s domain
  • Parameters: s (str)

set the description of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None

sets the name of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None
  • Returns: a description of its type
  • Return type: str

Returns the x-th tick of the variable (if the variable is a pyagrum.DiscretizedVariable)

  • Parameters: x (int) – the index of the tick we want to get
  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – If x is not a valid index for the ticks of the variable
  • Returns: float : the x-th tick of the variable

Returns the ticks of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the ticks of the variable, i.e. the values that belong to the variable’s domain

Return the variable description in fast syntax (e.g. name[val1|val2|...]).

  • Returns: fast-syntax string representation
  • Return type: str
  • Returns: a description of the variable
  • Return type: str

returns the type of variable

  • Returns: the type of the variable.

    0: DiscretizedVariable, 1: LabelizedVariable, 2: IntegerVariable, 3: NumericalDiscreteVariable, 4: RangeVariable

  • Return type: int

Concrete classes for Random Discrete Variables

Section titled “Concrete classes for Random Discrete Variables”

LabelizedVariable is a discrete random variable with a customizable sequence of labels.

LabelizedVariable(aName, aDesc=’’, nbrLabel=2) -> LabelizedVariable : Parameters: : - aName (str) – the name of the variable - aDesc (str) – the (optional) description of the variable - nbrLabel (int) – the number of labels to create (2 by default)

LabelizedVariable(aName, aDesc=’’, labels) -> LabelizedVariable : Parameters: : - aName (str) – the name of the variable - aDesc (str) – the (optional) description of the variable - labels (list of str) – the labels to create

LabelizedVariable(aLDRV) -> LabelizedVariable : Parameters: : - aLDRV (pyagrum.LabelizedVariable) – The pyagrum.LabelizedVariable that will be copied

Examples

>>> import pyagrum as gum
>>> # creating a variable with 3 labels : '0', '1' and '2'
>>> va=pyagrum.LabelizedVariable('a','a labelized variable',3)
>>> print(va)
a:Labelized(<0,1,2>)
>>> va.addLabel('foo')
(pyagrum.LabelizedVariable@0x7fc4c840dd90) a:Labelized(<0,1,2,foo>)
>>> va.changeLabel(1,'bar')
>>> print(va)
a:Labelized(<0,bar,2,foo>)
>>> vb=pyagrum.LabelizedVariable('b','b',0).addLabel('A').addLabel('B').addLabel('C')
>>> print(vb)
b:Labelized(<A,B,C>)
>>> vb.labels()
('A', 'B', 'C')
>>> vb.isLabel('E')
False
>>> vb.label(2)
'C'
>>> vc=pyagrum.LabelizedVariable('b','b',['one','two','three'])
>>> vc
(pyagrum.LabelizedVariable@0x7fc4c840c130) b:Labelized(<one,two,three>)

Add a label with a new index (we assume that we will NEVER remove a label).

Tries to cast the variable as a pyagrum.DiscretizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.DiscretizedVar
  • Return type: DiscretizedVariable

Tries to cast the variable as a pyagrum.IntegerVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.IntegerVar
  • Return type: IntegerVariable

Tries to cast the variable as a pyagrum.LabelizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.LabelizedVar
  • Return type: LabelizedVariable

Tries to cast the variable as a pyagrum.NumericalDiscreteVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.NumericalDiscreteVar
  • Return type: NumericalDiscreteVariable

Tries to cast the variable as a pyagrum.RangeVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.RangeVar
  • Return type: RangeVariable

returns whether x belongs to the variable domain (if the variable is a pyagrum.RangeVariable)

  • Parameters: x (int) – the value for which we want to know if it belongs to the variable domain
  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: bool
  • Returns: bool : True if x belongs to the variable domain, False otherwise

Change the label at the specified index

  • Parameters:
    • pos (int) – the index of the label to be changed
    • aLabel (str) – the label to be added to the labelized variable
  • Raises:
  • Return type: None

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the index of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the index of the closest value to value in the variable’s domain
  • Return type: int
  • Raises: pyagrum.NotImplementedYet – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the label of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the label of the closest value to value in the variable’s domain
  • Return type: str
  • Raises: pyagrum.InvalidArgument – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).
  • Returns: the description of the variable
  • Return type: str
  • Returns: the domain of the variable as a string
  • Return type: str
  • Returns: the number of modalities in the variable domain
  • Return type: int

Draw a random float value from the x-th interval of the variable (only for pyagrum.DiscretizedVariable).

  • Parameters: x (int) – the index of the interval from which to draw
  • Returns: a random value drawn uniformly from the x-th interval
  • Return type: float
  • Raises:
    • NotImplementedError – if the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – if x is not a valid interval index
  • Returns: True if the domain size < 2
  • Return type: bool

Erase all the labels from the variable.

  • Return type: None
  • Parameters: label (str) – a label
  • Returns: the index of the label
  • Return type: int

Returns the integer domain of the variable (if the variable is a pyagrum.integerVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.IntegerVariable
  • Return type: tuple[int, ...]
  • Returns: tuple[int,…] : the integer domain of the variable

Returns whether the variable is empirical (if the variable is a pyagrum.DiscretizedVariable). I.e. whether its limits (max and min) are defined by data and accept any values below or above these limits, contrary to non-empirical discretized variables for which the limits are fixed and values outside of these limits are not accepted)

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: bool
  • Returns: bool : whether the variable is empirical

Indicates whether the variable already has the label passed in argument

  • Parameters: aLabel (str) – the label to be tested
  • Returns: True if the label already exists
  • Return type: bool

Returns True if the variable has a meaningful numerical representation, i.e. it is not a LabelizedVariable.

  • Returns: True for DiscretizedVariable, IntegerVariable, NumericalDiscreteVariable and RangeVariable; False for LabelizedVariable.
  • Return type: bool

Returns whether x is a tick for the variable

  • Parameters: x (float) – the value for which we want to know if it is a tick for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Returns: bool : whether x is a tick for the variable, i.e. whether x belongs to the variable’s domain

Returns whether x is a value for the variable

  • Parameters: x (float) – the value for which we want to know if it is a value for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable or a pyagrum.IntegerVariable
  • Return type: bool
  • Returns: bool : whether x is a value for the variable, i.e. whether x belongs to the variable domain
  • Parameters: i (int) – the index of the label we wish to return
  • Returns: the label at the given index
  • Return type: str
  • Raises: pyagrum.OutOfBounds – If the variable does not contain the label
  • Returns: a tuple containing the labels
  • Return type: tuple[str, ...]

returns the maximum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the maximum value of the variable domain

returns the minimum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the minimum value of the variable domain
  • Returns: the name of the variable
  • Return type: str
  • Parameters: index (int) – an index
  • Returns: the numerical representation of the value at the given index
  • Return type: float

Returns the numerical domain of the variable (if the variable is a pyagrum.NumericalDiscreteVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the numerical domain of the variable

Return the position (index) of a label in the variable’s domain.

  • Parameters: label (str) – the label to look up
  • Returns: the index of the label in the domain
  • Return type: int
  • Raises: pyagrum.NotFound – if the label does not exist in the domain

set the description of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None

sets the name of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None
  • Returns: a description of its type
  • Return type: str

Returns the x-th tick of the variable (if the variable is a pyagrum.DiscretizedVariable)

  • Parameters: x (int) – the index of the tick we want to get
  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – If x is not a valid index for the ticks of the variable
  • Returns: float : the x-th tick of the variable

Returns the ticks of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the ticks of the variable, i.e. the values that belong to the variable’s domain

Return the variable description in fast syntax (e.g. name[val1|val2|...]).

  • Returns: fast-syntax string representation
  • Return type: str
  • Returns: a description of the variable
  • Return type: str

returns the type of variable

  • Returns: the type of the variable.

    0: DiscretizedVariable, 1: LabelizedVariable, 2: IntegerVariable, 3: NumericalDiscreteVariable, 4: RangeVariable

  • Return type: int

DiscretizedVariable is a discrete random variable with a set of ticks defining intervals.

DiscretizedVariable(aName, aDesc ,ticks=None,is_empirical=False) -> pyagrum.DiscretizedVariable Parameters:

  • aName (str) – the name of the variable
  • aDesc (str) – the description of the variable
  • ticks (list[float]) – the list of ticks to add
  • is_empirical (bool) – if False, raise an error if a value is out of bound.

DiscretizedVariable(aDDRV) -> DiscretizedVariable : Parameters:

Examples

>>> import pyagrum as gum
>>> vX=pyagrum.DiscretizedVariable('X','X has been discretized').addTick(1).addTick(2).addTick(3).addTick(3.1415)
>>> print(vX)
X:Discretized(<[1;2[,[2;3[,[3;3.1415]>)
>>> vX.isTick(4)
False
>>> vX.labels()
('[1;2[', '[2;3[', '[3;3.1415]')
>>> # where is the real value 2.5 ?
>>> vX.index('2.5')
1

Tries to cast the variable as a pyagrum.DiscretizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.DiscretizedVar
  • Return type: DiscretizedVariable

Tries to cast the variable as a pyagrum.IntegerVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.IntegerVar
  • Return type: IntegerVariable

Tries to cast the variable as a pyagrum.LabelizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.LabelizedVar
  • Return type: LabelizedVariable

Tries to cast the variable as a pyagrum.NumericalDiscreteVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.NumericalDiscreteVar
  • Return type: NumericalDiscreteVariable

Tries to cast the variable as a pyagrum.RangeVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.RangeVar
  • Return type: RangeVariable

returns whether x belongs to the variable domain (if the variable is a pyagrum.RangeVariable)

  • Parameters: x (int) – the value for which we want to know if it belongs to the variable domain
  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: bool
  • Returns: bool : True if x belongs to the variable domain, False otherwise

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the index of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the index of the closest value to value in the variable’s domain
  • Return type: int
  • Raises: pyagrum.NotImplementedYet – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the label of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the label of the closest value to value in the variable’s domain
  • Return type: str
  • Raises: pyagrum.InvalidArgument – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).
  • Returns: the description of the variable
  • Return type: str
  • Returns: the domain of the variable as a string
  • Return type: str
  • Returns: the number of modalities in the variable domain
  • Return type: int

Allow to draw a value in the i-th interval of the discretized variable.1

  • Parameters:
    • i (int) – the index of the interval to draw
    • indice (int)
  • Returns: the value randomly drawn in the i-th interval
  • Return type: float
  • Returns: True if the domain size < 2
  • Return type: bool

erase all the Ticks

  • Return type: None
  • Parameters: label (str) – a label
  • Returns: the index of the label
  • Return type: int

Returns the integer domain of the variable (if the variable is a pyagrum.integerVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.IntegerVariable
  • Return type: tuple[int, ...]
  • Returns: tuple[int,…] : the integer domain of the variable

Check whether the variable uses relaxed (empirical) tick bounds.

  • Returns: True if the variable is in empirical mode
  • Return type: bool

returns whether s is a label of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
  • Return type: bool
  • Returns: bool : True if s is a label of the variable, False otherwise
  • Parameters: s (str)

Returns True if the variable has a meaningful numerical representation, i.e. it is not a LabelizedVariable.

  • Returns: True for DiscretizedVariable, IntegerVariable, NumericalDiscreteVariable and RangeVariable; False for LabelizedVariable.
  • Return type: bool
  • Parameters: aTick (float) – the Tick to be tested
  • Returns: True if the Tick already exists
  • Return type: bool

Returns whether x is a value for the variable

  • Parameters: x (float) – the value for which we want to know if it is a value for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable or a pyagrum.IntegerVariable
  • Return type: bool
  • Returns: bool : whether x is a value for the variable, i.e. whether x belongs to the variable domain
  • Parameters: i (int) – the index of the label we wish to return
  • Returns: the label at the given index
  • Return type: str
  • Raises: pyagrum.OutOfBounds – If the variable does not contain the label
  • Returns: a tuple containing the labels
  • Return type: tuple[str, ...]

returns the maximum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the maximum value of the variable domain

returns the minimum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the minimum value of the variable domain
  • Returns: the name of the variable
  • Return type: str
  • Parameters:
    • index (int) – an index
    • indice (int)
  • Returns: the numerical representation of the value at the given index
  • Return type: float

Returns the numerical domain of the variable (if the variable is a pyagrum.NumericalDiscreteVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the numerical domain of the variable

Returns the index of the label s in the variable’s domain (if the variable is a pyagrum.LabelizedVariable)

  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
    • NotFoundError – If the variable does not contain the label s
  • Return type: int
  • Returns: int : the index of the label s in the variable’s domain
  • Parameters: s (str)

set the description of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None

Enable or disable empirical (relaxed bounds) mode for the variable.

  • Parameters: state (bool) – True to enable empirical mode, False to disable
  • Return type: None

sets the name of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None
  • Returns: a description of its type
  • Return type: str

Indicate the index of the Tick

  • Parameters: i (int) – the index of the Tick
  • Returns: aTick – the i-th Tick
  • Return type: float
  • Raises: pyagrum.NotFound – If the index is greater than the number of Ticks
  • Returns: a tuple containing all the Ticks
  • Return type: tuple[float, ...]

Return the variable description in fast syntax (e.g. name[v1:v2:v3]).

  • Returns: fast-syntax string representation
  • Return type: str
  • Returns: a description of the variable
  • Return type: str

returns the type of variable

  • Returns: the type of the variable.

    0: DiscretizedVariable, 1: LabelizedVariable, 2: IntegerVariable, 3: NumericalDiscreteVariable, 4: RangeVariable

  • Return type: int

IntegerVariable is a discrete random variable with a customizable sequence of int.

IntegerVariable(aName, aDesc=’’, values=None) -> IntegerVariable : Parameters: : - aName (str) – the name of the variable - aDesc (str) – the (optional) description of the variable - values (list of int) – the values to create

IntegerVariable(aIDRV) -> IntegerVariable : Parameters: : - aIDRV (pyagrum.IntegerVariable) – The pyagrum.IntegerVariable that will be copied

Examples

>>> import pyagrum as gum
>>> # creating a variable with 3 values : 1,34,142
>>> va=pyagrum.IntegerVariable('a','a integer variable',[1,34,142])
>>> print(va)
a:Integer(<1,34,142>)
>>> va.addValue(25)
(pyagrum.IntegerVariable@000001E4F5D07490) a:Integer(<1,25,34,142>)
>>> va.changeValue(34,43)
>>> print(va)
a:Integer(<1,25,43,142>)
>>> vb=pyagrum.IntegerVariable('b','b').addValue(34).addValue(142).addValue(1)
>>> print(vb)
b:Integer(<1,34,142>)
>>> vb.labels()
('1', '34', '142')

Add a value to the list of values for the variable.

Tries to cast the variable as a pyagrum.DiscretizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.DiscretizedVar
  • Return type: DiscretizedVariable

Tries to cast the variable as a pyagrum.IntegerVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.IntegerVar
  • Return type: IntegerVariable

Tries to cast the variable as a pyagrum.LabelizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.LabelizedVar
  • Return type: LabelizedVariable

Tries to cast the variable as a pyagrum.NumericalDiscreteVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.NumericalDiscreteVar
  • Return type: NumericalDiscreteVariable

Tries to cast the variable as a pyagrum.RangeVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.RangeVar
  • Return type: RangeVariable

returns whether x belongs to the variable domain (if the variable is a pyagrum.RangeVariable)

  • Parameters: x (int) – the value for which we want to know if it belongs to the variable domain
  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: bool
  • Returns: bool : True if x belongs to the variable domain, False otherwise
  • Parameters:
    • old_value (int) – the value to be changed
    • new_value (int) – the new value
  • Return type: None

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the index of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the index of the closest value to value in the variable’s domain
  • Return type: int
  • Raises: pyagrum.NotImplementedYet – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the label of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the label of the closest value to value in the variable’s domain
  • Return type: str
  • Raises: pyagrum.InvalidArgument – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).
  • Returns: the description of the variable
  • Return type: str
  • Returns: the domain of the variable
  • Return type: str
  • Returns: the number of modalities in the variable domain
  • Return type: int

Draw a random float value from the x-th interval of the variable (only for pyagrum.DiscretizedVariable).

  • Parameters: x (int) – the index of the interval from which to draw
  • Returns: a random value drawn uniformly from the x-th interval
  • Return type: float
  • Raises:
    • NotImplementedError – if the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – if x is not a valid interval index
  • Returns: True if the domain size < 2
  • Return type: bool
  • Parameters: value (int) – the value to erase. If the value is not in the domain, the function does nothing (no exception raised)
  • Return type: None

Remove all the domain.

  • Return type: None
  • Parameters: label (str) – a label
  • Returns: the index of the label
  • Return type: int
  • Returns: the tuple of integer values that form the domain of this variable
  • Return type: tuple[int, ...]

Returns whether the variable is empirical (if the variable is a pyagrum.DiscretizedVariable). I.e. whether its limits (max and min) are defined by data and accept any values below or above these limits, contrary to non-empirical discretized variables for which the limits are fixed and values outside of these limits are not accepted)

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: bool
  • Returns: bool : whether the variable is empirical

returns whether s is a label of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
  • Return type: bool
  • Returns: bool : True if s is a label of the variable, False otherwise
  • Parameters: s (str)

Returns True if the variable has a meaningful numerical representation, i.e. it is not a LabelizedVariable.

  • Returns: True for DiscretizedVariable, IntegerVariable, NumericalDiscreteVariable and RangeVariable; False for LabelizedVariable.
  • Return type: bool

Returns whether x is a tick for the variable

  • Parameters: x (float) – the value for which we want to know if it is a tick for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Returns: bool : whether x is a tick for the variable, i.e. whether x belongs to the variable’s domain
  • Parameters: value (int) – the value to look at.
  • Returns: True if the value is in the domain.
  • Return type: bool
  • Parameters:
    • i (int) – the index of the label we wish to return
    • index (int)
  • Returns: the label at the given index
  • Return type: str
  • Raises: pyagrum.OutOfBounds – If the variable does not contain the label
  • Returns: a tuple containing the labels
  • Return type: tuple[str, ...]

returns the maximum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the maximum value of the variable domain

returns the minimum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the minimum value of the variable domain
  • Returns: the name of the variable
  • Return type: str
  • Parameters: index (int) – an index
  • Returns: the numerical representation of the value at the given index
  • Return type: float

Returns the numerical domain of the variable (if the variable is a pyagrum.NumericalDiscreteVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the numerical domain of the variable

Returns the index of the label s in the variable’s domain (if the variable is a pyagrum.LabelizedVariable)

  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
    • NotFoundError – If the variable does not contain the label s
  • Return type: int
  • Returns: int : the index of the label s in the variable’s domain
  • Parameters: s (str)

set the description of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None

sets the name of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None
  • Returns: a description of its type
  • Return type: str

Returns the x-th tick of the variable (if the variable is a pyagrum.DiscretizedVariable)

  • Parameters: x (int) – the index of the tick we want to get
  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – If x is not a valid index for the ticks of the variable
  • Returns: float : the x-th tick of the variable

Returns the ticks of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the ticks of the variable, i.e. the values that belong to the variable’s domain

Return the variable description in fast syntax (e.g. name{v1|v2|...}).

  • Returns: fast-syntax string representation
  • Return type: str
  • Returns: a description of the variable
  • Return type: str

returns the type of variable

  • Returns: the type of the variable.

    0: DiscretizedVariable, 1: LabelizedVariable, 2: IntegerVariable, 3: NumericalDiscreteVariable, 4: RangeVariable

  • Return type: int

RangeVariable represents a variable with a range of integers as domain.

RangeVariable(aName, aDesc,minVal, maxVal) -> RangeVariable : Parameters: : - aName (str) – the name of the variable - aDesc (str) – the description of the variable - minVal (int) – the minimal integer of the interval - maxVal (int) – the maximal integer of the interval

RangeVariable(aName, aDesc=’’) -> RangeVariable : Parameters: : - aName (str) – the name of the variable - aDesc (str) – the description of the variable
By default minVal=0 and maxVal=1

RangeVariable(aRV) -> RangeVariable : Parameters: : - aDV (RangeVariable) – the pyagrum.RangeVariable that will be copied

Examples

>>> import pyagrum as gum
>>> vI=pyagrum.RangeVariable('I','I in [4,10]',4,10)
>>> print(vI)
I:Range([4,10])
>>> vI.maxVal()
10
>>> vI.belongs(1)
False
>>> # where is the value 5 ?
>>> vI.index('5')
1
>>> vI.labels()
('4', '5', '6', '7', '8', '9', '10')

Tries to cast the variable as a pyagrum.DiscretizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.DiscretizedVar
  • Return type: DiscretizedVariable

Tries to cast the variable as a pyagrum.IntegerVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.IntegerVar
  • Return type: IntegerVariable

Tries to cast the variable as a pyagrum.LabelizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.LabelizedVar
  • Return type: LabelizedVariable

Tries to cast the variable as a pyagrum.NumericalDiscreteVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.NumericalDiscreteVar
  • Return type: NumericalDiscreteVariable

Tries to cast the variable as a pyagrum.RangeVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.RangeVar
  • Return type: RangeVariable
  • Parameters: val (int) – the value to be tested
  • Returns: True if the value in parameters belongs to the variable’s interval.
  • Return type: bool

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the index of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the index of the closest value to value in the variable’s domain
  • Return type: int
  • Raises: pyagrum.NotImplementedYet – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the label of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the label of the closest value to value in the variable’s domain
  • Return type: str
  • Raises: pyagrum.InvalidArgument – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).
  • Returns: the description of the variable
  • Return type: str
  • Returns: the domain of the variable
  • Return type: str
  • Returns: the number of modalities in the variable domain
  • Return type: int

Draw a random float value from the x-th interval of the variable (only for pyagrum.DiscretizedVariable).

  • Parameters: x (int) – the index of the interval from which to draw
  • Returns: a random value drawn uniformly from the x-th interval
  • Return type: float
  • Raises:
    • NotImplementedError – if the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – if x is not a valid interval index
  • Returns: True if the domain size < 2
  • Return type: bool
  • Parameters: arg2 (str) – a label
  • Returns: the indice of the label
  • Return type: int

Returns the integer domain of the variable (if the variable is a pyagrum.integerVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.IntegerVariable
  • Return type: tuple[int, ...]
  • Returns: tuple[int,…] : the integer domain of the variable

Returns whether the variable is empirical (if the variable is a pyagrum.DiscretizedVariable). I.e. whether its limits (max and min) are defined by data and accept any values below or above these limits, contrary to non-empirical discretized variables for which the limits are fixed and values outside of these limits are not accepted)

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: bool
  • Returns: bool : whether the variable is empirical

returns whether s is a label of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
  • Return type: bool
  • Returns: bool : True if s is a label of the variable, False otherwise
  • Parameters: s (str)

Returns True if the variable has a meaningful numerical representation, i.e. it is not a LabelizedVariable.

  • Returns: True for DiscretizedVariable, IntegerVariable, NumericalDiscreteVariable and RangeVariable; False for LabelizedVariable.
  • Return type: bool

Returns whether x is a tick for the variable

  • Parameters: x (float) – the value for which we want to know if it is a tick for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Returns: bool : whether x is a tick for the variable, i.e. whether x belongs to the variable’s domain

Returns whether x is a value for the variable

  • Parameters: x (float) – the value for which we want to know if it is a value for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable or a pyagrum.IntegerVariable
  • Return type: bool
  • Returns: bool : whether x is a value for the variable, i.e. whether x belongs to the variable domain
  • Parameters:
    • indice (int) – the index of the label we wish to return
    • index (int)
  • Returns: the indice-th label
  • Return type: str
  • Raises: pyagrum.OutOfBounds – If the variable does not contain the label
  • Returns: a tuple containing the labels
  • Return type: tuple[str, ...]
  • Returns: the upper bound of the variable.
  • Return type: int
  • Returns: the lower bound of the variable
  • Return type: int
  • Returns: the name of the variable
  • Return type: str
  • Parameters: index (int) – an index
  • Returns: the numerical representation of the value at the given index
  • Return type: float

Returns the numerical domain of the variable (if the variable is a pyagrum.NumericalDiscreteVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.NumericalDiscreteVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the numerical domain of the variable

Returns the index of the label s in the variable’s domain (if the variable is a pyagrum.LabelizedVariable)

  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
    • NotFoundError – If the variable does not contain the label s
  • Return type: int
  • Returns: int : the index of the label s in the variable’s domain
  • Parameters: s (str)

set the description of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None

Set a new value of the upper bound

  • Parameters: maxVal (int) – The new value of the upper bound
  • Return type: None

Warning

An error should be raised if the value is lower than the lower bound.

Set a new value of the lower bound

  • Parameters: minVal (int) – The new value of the lower bound
  • Return type: None

Warning

An error should be raised if the value is higher than the upper bound.

sets the name of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None
  • Returns: a description of its type
  • Return type: str

Returns the x-th tick of the variable (if the variable is a pyagrum.DiscretizedVariable)

  • Parameters: x (int) – the index of the tick we want to get
  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – If x is not a valid index for the ticks of the variable
  • Returns: float : the x-th tick of the variable

Returns the ticks of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the ticks of the variable, i.e. the values that belong to the variable’s domain

Return the variable description in fast syntax (e.g. name[min,max]).

  • Returns: fast-syntax string representation
  • Return type: str
  • Returns: a description of the variable
  • Return type: str

returns the type of variable

  • Returns: the type of the variable.

    0: DiscretizedVariable, 1: LabelizedVariable, 2: IntegerVariable, 3: NumericalDiscreteVariable, 4: RangeVariable

  • Return type: int

class pyagrum.NumericalDiscreteVariable(*args)

Section titled “class pyagrum.NumericalDiscreteVariable(*args)”

NumericalDiscreteVariable is a discrete random variable with a customizable sequence of float.

NumericalDiscreteVariable(aName, aDesc=’’, values=None) -> NumericalDiscreteVariable : Parameters: : - aName (str) – the name of the variable - aDesc (str) – the (optional) description of the variable - values (list of float) – the values to create equivalent to fast syntax {v1|v2|v3|…|vn}

NumericalDiscreteVariable(aName, aDesc=’’, first, last, nbr) -> NumericalDiscreteVariable : Parameters: : - aName (str) – the name of the variable - aDesc (str) – the (optional) description of the variable - first (float) – specify a list of floats from first to last in nbr steps. - last (float) – - nbr (int) – equivalent to fast syntax {first:last:nbr}

NumericalDiscreteVariable(aNDRV) -> NumericalDiscreteVariable : Parameters: : - aNDRV (pyagrum.NumericalDiscreteVariable) – The pyagrum.NumericalDiscreteVariable that will be copied

Examples

>>> import pyagrum as gum
>>> # creating a variable with 3 values : 1.5,3.14,1.42
>>> va=pyagrum.NumericalDiscreteVariable('a','a numerica variable',[1.5,3.14,1.42])
>>> print(va)
a:NumericalDiscrete({1.42|1.5|3.14})
>>> va.addValue(2.01)
(pyagrum.NumericalDiscreteVariable@0x55ea157b8d60) a:NumericalDiscrete({1.42|1.5|2.01|3.14})
>>> va.changeValue(3.14,3.1415)
>>> print(va)
a:NumericalDiscrete({1.42|1.5|2.01|3.1415})
>>> vb=pyagrum.NumericalDiscreteVariable('b','b').addValue(3.14).addValue(1.42).addValue(1.5)
>>> print(vb)
b:NumericalDiscrete({1.42|1.5|3.14})
>>> vb.labels()
('1.42', '1.5', '3.14')
>>>> vc=pyagrum.NumericalDiscreteVariable('c','c',1.2,3.8,5)
>>> print(vc)
c:NumericalDiscrete({1.2|1.85|2.5|3.15|3.8})

Add a value to the list of values for the variable.

Tries to cast the variable as a pyagrum.DiscretizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.DiscretizedVar
  • Return type: DiscretizedVariable

Tries to cast the variable as a pyagrum.IntegerVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.IntegerVar
  • Return type: IntegerVariable

Tries to cast the variable as a pyagrum.LabelizedVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.LabelizedVar
  • Return type: LabelizedVariable

Tries to cast the variable as a pyagrum.NumericalDiscreteVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.NumericalDiscreteVar
  • Return type: NumericalDiscreteVariable

Tries to cast the variable as a pyagrum.RangeVar.

  • Raises: pyagrum.OperationNotAllowed if this is not possible
  • Returns: the variable as a pyagrum.RangeVar
  • Return type: RangeVariable

returns whether x belongs to the variable domain (if the variable is a pyagrum.RangeVariable)

  • Parameters: x (int) – the value for which we want to know if it belongs to the variable domain
  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: bool
  • Returns: bool : True if x belongs to the variable domain, False otherwise
  • Parameters:
    • old_value (float) – the value to be changed
    • new_value (float) – the new value
  • Return type: None

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the index of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the index of the closest value to value in the variable’s domain
  • Return type: int
  • Raises: pyagrum.NotImplementedYet – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).

For numerical discrete variables (all except pyagrum.LabelizedVariable), this method returns the label of the closest value to a given float value in the variable’s domain.

  • Parameters: val (float) – the value for which we want to find the closest index
  • Returns: the label of the closest value to value in the variable’s domain
  • Return type: str
  • Raises: pyagrum.InvalidArgument – if the variable is not numerical discrete (i.e., if it is a pyagrum.LabelizedVariable).
  • Returns: the description of the variable
  • Return type: str
  • Returns: the domain of the variable
  • Return type: str
  • Returns: the number of modalities in the variable domain
  • Return type: int

Draw a random float value from the x-th interval of the variable (only for pyagrum.DiscretizedVariable).

  • Parameters: x (int) – the index of the interval from which to draw
  • Returns: a random value drawn uniformly from the x-th interval
  • Return type: float
  • Raises:
    • NotImplementedError – if the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – if x is not a valid interval index
  • Returns: True if the domain size < 2
  • Return type: bool
  • Parameters: value (float) – the value to erase. If the value is not in the domain, the function does nothing (no exception raised)
  • Return type: None

Remove all the domain.

  • Return type: None
  • Parameters: label (str) – a label
  • Returns: the index of the label
  • Return type: int

Returns the integer domain of the variable (if the variable is a pyagrum.integerVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.IntegerVariable
  • Return type: tuple[int, ...]
  • Returns: tuple[int,…] : the integer domain of the variable

Returns whether the variable is empirical (if the variable is a pyagrum.DiscretizedVariable). I.e. whether its limits (max and min) are defined by data and accept any values below or above these limits, contrary to non-empirical discretized variables for which the limits are fixed and values outside of these limits are not accepted)

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: bool
  • Returns: bool : whether the variable is empirical

returns whether s is a label of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
  • Return type: bool
  • Returns: bool : True if s is a label of the variable, False otherwise
  • Parameters: s (str)

Returns True if the variable has a meaningful numerical representation, i.e. it is not a LabelizedVariable.

  • Returns: True for DiscretizedVariable, IntegerVariable, NumericalDiscreteVariable and RangeVariable; False for LabelizedVariable.
  • Return type: bool

Returns whether x is a tick for the variable

  • Parameters: x (float) – the value for which we want to know if it is a tick for the variable
  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Returns: bool : whether x is a tick for the variable, i.e. whether x belongs to the variable’s domain
  • Parameters: value (float) – the value to look at.
  • Returns: True if the value is in the domain.
  • Return type: bool
  • Parameters:
    • i (int) – the index of the label we wish to return
    • index (int)
  • Returns: the label at the given index
  • Return type: str
  • Raises: pyagrum.OutOfBounds – If the variable does not contain the label
  • Returns: a tuple containing the labels
  • Return type: tuple[str, ...]

returns the maximum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the maximum value of the variable domain

returns the minimum value of the variable domain (if the variable is a pyagrum.RangeVariable)

  • Raises: NotImplementedError – If the variable is not a pyagrum.RangeVariable
  • Return type: int
  • Returns: int : the minimum value of the variable domain
  • Returns: the name of the variable
  • Return type: str
  • Parameters: index (int) – an index
  • Returns: the numerical representation of the value at the given index
  • Return type: float
  • Returns: the tuple of float values that form the domain of this variable
  • Return type: tuple[float, ...]

Returns the index of the label s in the variable’s domain (if the variable is a pyagrum.LabelizedVariable)

  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.LabelizedVariable
    • NotFoundError – If the variable does not contain the label s
  • Return type: int
  • Returns: int : the index of the label s in the variable’s domain
  • Parameters: s (str)

set the description of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None

sets the name of the variable.

  • Parameters: theValue (str) – the new description of the variable
  • Return type: None
  • Returns: a description of its type
  • Return type: str

Returns the x-th tick of the variable (if the variable is a pyagrum.DiscretizedVariable)

  • Parameters: x (int) – the index of the tick we want to get
  • Raises:
    • NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
    • pyagrum.OutOfBounds – If x is not a valid index for the ticks of the variable
  • Returns: float : the x-th tick of the variable

Returns the ticks of the variable

  • Raises: NotImplementedError – If the variable is not a pyagrum.DiscretizedVariable
  • Return type: tuple[float, ...]
  • Returns: tuple[float,…] : the ticks of the variable, i.e. the values that belong to the variable’s domain

Return the variable description in fast syntax (e.g. name{v1|v2|...}).

  • Returns: fast-syntax string representation
  • Return type: str
  • Returns: a description of the variable
  • Return type: str

returns the type of variable

  • Returns: the type of the variable.

    0: DiscretizedVariable, 1: LabelizedVariable, 2: IntegerVariable, 3: NumericalDiscreteVariable, 4: RangeVariable

  • Return type: int