Tensor.fillFromExpression

Tensor.fillFromExpression(s_fn)

Automatically fills the tensor with the evaluation of the expression s_fn (no matter if is a CPT or not).

The symbolic expression s_fn gives a value for each parameters of the Tensor

Parameters:

s_fn (str) – a symbolic expression using the name of the variables of the Tensor and giving a value to the first variable of the Tensor. This evaluation is done in a context that inclides ‘math’ module.

Warning

The expression may have any numerical values, but will be then transformed to the closest correct value for the range of the variable.

Returns:

a reference to the modified tensor

Return type:

pyagrum.Tensor

Example

import pyagrum as gum

bn = gum.fastBN("A[3]->B[3]")
bn.cpt("B").fillFromExpression("A*B")
print(bn.cpt("B"))
#
#       ║  B                          │
# A     ║0        │1        │2        │
# ──────║─────────│─────────│─────────│
# 0     ║ 0.0000  │ 0.0000  │ 0.0000  │
# 1     ║ 0.0000  │ 1.0000  │ 2.0000  │
# 2     ║ 0.0000  │ 2.0000  │ 4.0000  │

Class

Tensor