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.

Common API for Random Discrete Variables

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

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

asDiscretizedVar()

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:

pyAgrum.DiscretizedVar

asIntegerVar()

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:

pyAgrum.IntegerVar

asLabelizedVar()

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:

pyAgrum.LabelizedVar

asNumericalDiscreteVar()

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:

pyAgrum.NumericalDiscreteVar

asRangeVar()

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:

pyAgrum.RangeVar

belongs(x)
closestIndex(val)
Parameters:

val (float)

Return type:

int

closestLabel(val)
Parameters:

val (float)

Return type:

str

description()
Returns:

the description of the variable

Return type:

str

domain()
Returns:

the domain of the variable

Return type:

str

domainSize()
Returns:

the number of modalities in the variable domain

Return type:

int

empty()
Returns:

True if the domain size < 2

Return type:

bool

index(label)
Parameters:

label (str) – a label

Returns:

the indice of the label

Return type:

int

integerDomain()
isEmpirical()
isLabel(s)
isTick(x)
isValue(x)
label(i)
Parameters:

i (int) – the index of the label we wish to return

Returns:

the indice-th label

Return type:

str

Raises:

pyAgrum.OutOfBounds – If the variable does not contain the label

labels()
Returns:

a tuple containing the labels

Return type:

tuple

maxVal()
minVal()
name()
Returns:

the name of the variable

Return type:

str

numerical(indice)
Parameters:

indice (int) – an index

Returns:

the numerical representation of the indice-th value

Return type:

float

numericalDomain()
posLabel(s)
setDescription(theValue)

set the description of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

setName(theValue)

sets the name of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

stype()
Returns:

a description of its type

Return type:

str

tick(x)
ticks()
toDiscretizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toFast()
Return type:

str

toIntegerVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toLabelizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toNumericalDiscreteVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toRangeVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toStringWithDescription()
Returns:

a description of the variable

Return type:

str

varType()

returns the type of variable

Returns:

the type of the variable.

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

Return type:

int

Concrete classes for Random Discrete Variables

LabelizedVariable

class pyAgrum.LabelizedVariable(*args)

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[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>)
addLabel(*args)

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

Parameters:

aLabel (str) – the label to be added to the labelized variable

Returns:

the labelized variable

Return type:

pyAgrum.LabelizedVariable

Raises:

pyAgrum.DuplicateElement – If the variable already contains the label

asDiscretizedVar()

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:

pyAgrum.DiscretizedVar

asIntegerVar()

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:

pyAgrum.IntegerVar

asLabelizedVar()

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:

pyAgrum.LabelizedVar

asNumericalDiscreteVar()

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:

pyAgrum.NumericalDiscreteVar

asRangeVar()

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:

pyAgrum.RangeVar

belongs(x)
changeLabel(pos, aLabel)

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

closestIndex(val)
Parameters:

val (float)

Return type:

int

closestLabel(val)
Parameters:

val (float)

Return type:

str

description()
Returns:

the description of the variable

Return type:

str

domain()
Returns:

the domain of the variable as a string

Return type:

str

domainSize()
Returns:

the number of modalities in the variable domain

Return type:

int

empty()
Returns:

True if the domain size < 2

Return type:

bool

eraseLabels()

Erase all the labels from the variable.

Return type:

None

index(label)
Parameters:

label (str) – a label

Returns:

the indice of the label

Return type:

int

integerDomain()
isEmpirical()
isLabel(aLabel)

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

isTick(x)
isValue(x)
label(i)
Parameters:

i (int) – the index of the label we wish to return

Returns:

the indice-th label

Return type:

str

Raises:

pyAgrum.OutOfBounds – If the variable does not contain the label

labels()
Returns:

a tuple containing the labels

Return type:

tuple

maxVal()
minVal()
name()
Returns:

the name of the variable

Return type:

str

numerical(index)
Parameters:
  • indice (int) – an index

  • index (int)

Returns:

the numerical representation of the indice-th value

Return type:

float

numericalDomain()
posLabel(label)
Parameters:

label (str)

Return type:

int

setDescription(theValue)

set the description of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

setName(theValue)

sets the name of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

stype()
Returns:

a description of its type

Return type:

str

tick(x)
ticks()
toDiscretizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toFast()
Return type:

str

toIntegerVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toLabelizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toNumericalDiscreteVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toRangeVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toStringWithDescription()
Returns:

a description of the variable

Return type:

str

varType()

returns the type of variable

Returns:

the type of the variable.

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

Return type:

int

DiscretizedVariable

class pyAgrum.DiscretizedVariable(*args)

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:
  • aDDRV (pyAgrum.DiscretizedVariable) – the pyAgrum.DiscretizedVariable that will be copied

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
addTick(*args)
Parameters:

aTick (float) – the Tick to be added

Returns:

the discretized variable

Return type:

pyAgrum.DiscretizedVariable

Raises:

pyAgrum.DefaultInLabel – If the tick is already defined

asDiscretizedVar()

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:

pyAgrum.DiscretizedVar

asIntegerVar()

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:

pyAgrum.IntegerVar

asLabelizedVar()

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:

pyAgrum.LabelizedVar

asNumericalDiscreteVar()

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:

pyAgrum.NumericalDiscreteVar

asRangeVar()

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:

pyAgrum.RangeVar

belongs(x)
closestIndex(val)
Parameters:

val (float)

Return type:

int

closestLabel(val)
Parameters:

val (float)

Return type:

str

description()
Returns:

the description of the variable

Return type:

str

domain()
Returns:

the domain of the variable as a string

Return type:

str

domainSize()
Returns:

the number of modalities in the variable domain

Return type:

int

empty()
Returns:

True if the domain size < 2

Return type:

bool

eraseTicks()

erase all the Ticks

Return type:

None

index(*args)
Parameters:

label (str) – a label

Returns:

the indice of the label

Return type:

int

integerDomain()
isEmpirical()
Return type:

bool

isLabel(s)
isTick(aTick)
Parameters:

aTick (float) – the Tick to be tested

Returns:

True if the Tick already exists

Return type:

bool

isValue(x)
label(i)
Parameters:

i (int) – the index of the label we wish to return

Returns:

the indice-th label

Return type:

str

Raises:

pyAgrum.OutOfBounds – If the variable does not contain the label

labels()
Returns:

a tuple containing the labels

Return type:

tuple

maxVal()
minVal()
name()
Returns:

the name of the variable

Return type:

str

numerical(indice)
Parameters:

indice (int) – an index

Returns:

the numerical representation of the indice-th value

Return type:

float

numericalDomain()
posLabel(s)
setDescription(theValue)

set the description of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

setEmpirical(state)
Parameters:

state (bool)

Return type:

None

setName(theValue)

sets the name of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

stype()
Returns:

a description of its type

Return type:

str

tick(i)

Indicate the index of the Tick

Parameters:

i (int) – the index of the Tick

Returns:

aTick – the index-th Tick

Return type:

float

Raises:

pyAgrum.NotFound – If the index is greater than the number of Ticks

ticks()
Returns:

a tuple containing all the Ticks

Return type:

tuple

toDiscretizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toFast()
Return type:

str

toIntegerVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toLabelizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toNumericalDiscreteVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toRangeVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toStringWithDescription()
Returns:

a description of the variable

Return type:

str

varType()

returns the type of variable

Returns:

the type of the variable.

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

Return type:

int

IntegerVariable

class pyAgrum.IntegerVariable(*args)

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[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')
addValue(*args)

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

Parameters:

value (int) – the new value

Returns:

the Integer variable

Return type:

pyAgrum.IntegerVariable

Raises:

pyAgrum.DuplicateElement – If the variable already contains the value

asDiscretizedVar()

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:

pyAgrum.DiscretizedVar

asIntegerVar()

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:

pyAgrum.IntegerVar

asLabelizedVar()

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:

pyAgrum.LabelizedVar

asNumericalDiscreteVar()

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:

pyAgrum.NumericalDiscreteVar

asRangeVar()

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:

pyAgrum.RangeVar

belongs(x)
changeValue(old_value, new_value)
Parameters:
  • old_value (int) – the value to be changed

  • new_value (int) – the new value

Return type:

None

closestIndex(val)
Parameters:

val (float)

Return type:

int

closestLabel(val)
Parameters:

val (float)

Return type:

str

description()
Returns:

the description of the variable

Return type:

str

domain()
Returns:

the domain of the variable

Return type:

str

domainSize()
Returns:

the number of modalities in the variable domain

Return type:

int

empty()
Returns:

True if the domain size < 2

Return type:

bool

eraseValue(value)
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

eraseValues()

Remove all the domain.

Return type:

None

index(label)
Parameters:

label (str) – a label

Returns:

the indice of the label

Return type:

int

integerDomain()
Returns:

the tuple of integer values that form the domain of this variable

Return type:

Tuple[int]

isEmpirical()
isLabel(s)
isTick(x)
isValue(value)
Parameters:

value (int) – the value to look at.

Returns:

True if the value is in the domain.

Return type:

bool

label(index)
Parameters:
  • i (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

labels()
Returns:

a tuple containing the labels

Return type:

tuple

maxVal()
minVal()
name()
Returns:

the name of the variable

Return type:

str

numerical(index)
Parameters:
  • indice (int) – an index

  • index (int)

Returns:

the numerical representation of the indice-th value

Return type:

float

numericalDomain()
posLabel(s)
setDescription(theValue)

set the description of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

setName(theValue)

sets the name of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

stype()
Returns:

a description of its type

Return type:

str

tick(x)
ticks()
toDiscretizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toFast()
Return type:

str

toIntegerVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toLabelizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toNumericalDiscreteVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toRangeVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toStringWithDescription()
Returns:

a description of the variable

Return type:

str

varType()

returns the type of variable

Returns:

the type of the variable.

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

Return type:

int

RangeVariable

class pyAgrum.RangeVariable(*args)

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')
asDiscretizedVar()

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:

pyAgrum.DiscretizedVar

asIntegerVar()

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:

pyAgrum.IntegerVar

asLabelizedVar()

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:

pyAgrum.LabelizedVar

asNumericalDiscreteVar()

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:

pyAgrum.NumericalDiscreteVar

asRangeVar()

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:

pyAgrum.RangeVar

belongs(val)
Parameters:

val (int) – the value to be tested

Returns:

True if the value in parameters belongs to the variable’s interval.

Return type:

bool

closestIndex(val)
Parameters:

val (float)

Return type:

int

closestLabel(val)
Parameters:

val (float)

Return type:

str

description()
Returns:

the description of the variable

Return type:

str

domain()
Returns:

the domain of the variable

Return type:

str

domainSize()
Returns:

the number of modalities in the variable domain

Return type:

int

empty()
Returns:

True if the domain size < 2

Return type:

bool

index(arg2)
Parameters:

arg2 (str) – a label

Returns:

the indice of the label

Return type:

int

integerDomain()
isEmpirical()
isLabel(s)
isTick(x)
isValue(x)
label(index)
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

labels()
Returns:

a tuple containing the labels

Return type:

tuple

maxVal()
Returns:

the upper bound of the variable.

Return type:

int

minVal()
Returns:

the lower bound of the variable

Return type:

int

name()
Returns:

the name of the variable

Return type:

str

numerical(index)
Parameters:
  • indice (int) – an index

  • index (int)

Returns:

the numerical representation of the indice-th value

Return type:

float

numericalDomain()
posLabel(s)
setDescription(theValue)

set the description of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

setMaxVal(maxVal)

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.

setMinVal(minVal)

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.

setName(theValue)

sets the name of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

stype()
Returns:

a description of its type

Return type:

str

tick(x)
ticks()
toDiscretizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toFast()
Return type:

str

toIntegerVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toLabelizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toNumericalDiscreteVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toRangeVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toStringWithDescription()
Returns:

a description of the variable

Return type:

str

varType()

returns the type of variable

Returns:

the type of the variable.

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

Return type:

int

NumericalDiscreteVariable

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[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})
addValue(*args)

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

Parameters:

value (float) – the new value

Returns:

the Integer variable

Return type:

pyAgrum.IntegerVariable

Raises:

pyAgrum.DuplicateElement – If the variable already contains the value

asDiscretizedVar()

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:

pyAgrum.DiscretizedVar

asIntegerVar()

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:

pyAgrum.IntegerVar

asLabelizedVar()

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:

pyAgrum.LabelizedVar

asNumericalDiscreteVar()

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:

pyAgrum.NumericalDiscreteVar

asRangeVar()

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:

pyAgrum.RangeVar

belongs(x)
changeValue(old_value, new_value)
Parameters:
  • old_value (int) – the value to be changed

  • new_value (int) – the new value

Return type:

None

closestIndex(val)
Parameters:

val (float)

Return type:

int

closestLabel(val)
Parameters:

val (float)

Return type:

str

description()
Returns:

the description of the variable

Return type:

str

domain()
Returns:

the domain of the variable

Return type:

str

domainSize()
Returns:

the number of modalities in the variable domain

Return type:

int

empty()
Returns:

True if the domain size < 2

Return type:

bool

eraseValue(value)
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

eraseValues()

Remove all the domain.

Return type:

None

index(label)
Parameters:

label (str) – a label

Returns:

the indice of the label

Return type:

int

integerDomain()
isEmpirical()
isLabel(s)
isTick(x)
isValue(value)
Parameters:

value (int) – the value to look at.

Returns:

True if the value is in the domain.

Return type:

bool

label(index)
Parameters:
  • i (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

labels()
Returns:

a tuple containing the labels

Return type:

tuple

maxVal()
minVal()
name()
Returns:

the name of the variable

Return type:

str

numerical(index)
Parameters:
  • indice (int) – an index

  • index (int)

Returns:

the numerical representation of the indice-th value

Return type:

float

numericalDomain()
Returns:

the tuple of float values that form the domain of this variable

Return type:

Tuple[float]

posLabel(s)
setDescription(theValue)

set the description of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

setName(theValue)

sets the name of the variable.

Parameters:

theValue (str) – the new description of the variable

Return type:

None

stype()
Returns:

a description of its type

Return type:

str

tick(x)
ticks()
toDiscretizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toFast()
Return type:

str

toIntegerVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toLabelizedVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toNumericalDiscreteVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toRangeVar()

Deprecated method in gum.DiscreteVariable for pyAgrum>1.5.2

toStringWithDescription()
Returns:

a description of the variable

Return type:

str

varType()

returns the type of variable

Returns:

the type of the variable.

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

Return type:

int