Tensor.fillFromFunction

Tensor.fillFromFunction(s_fn)

Automatically fills the tensor as a deterministic CPT with the evaluation of the expression s_fn.

The symbolic expression s_fn gives a value for the first variable, depending on the following variables. The computed CPT is deterministic.

Parameters:

s_fn (str) – a symbolic expression using the name of the second and following 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

Raises:

pyagrum.InvalidArgument – If the first variable is Labelized.

Example

import pyagrum as gum

bn = gum.fastBN("A[3]->B[3]<-C[3]")
bn.cpt("B").fillFromFunction("(A+C)/2")
bn.cpt("B")[{"A": 2, "C": 2}].tolist()
# [0.0, 0.0, 1.0]
bn.cpt("B")[{"A": 0, "C": 2}].tolist()
# [0.0, 1.0, 0.0]

Class

Tensor