The print_operand_tree function#

Aliases#

halerium.core.print_operand_tree
print_operand_tree(operator, extractor=<function <lambda>>, stop_criterion=None)#

Print operand tree.

Prints the operator, all its operands, all the operands of these operands, and so on in a tree-like structure for quick visual inspection. When a (Static)Variable is encountered, the parameters of its distribution are considered its operands. What information is to be printed for each operand can be controlled by the extractor argument.

Parameters:
  • operator – The operator whose operand tree to print.

  • extractor (callable) – The extractor function controlling what information is to be printed for each operand. It must take one operand as argument and return what is to be printed for that operand. The default is the identity function, which just returns the operand as is.

  • stop_criterion (callable, None) – A stopping criterion. When applying it to an operand in the tree yields True, stop going deeper into the branch of that operand.

Examples

>>> from halerium.core import Variable
>>> from halerium.core.utilities.print import print_operand_tree
>>>
>>> v = Variable("v", mean=0, variance=1)
>>> w = 2 * v + 1
>>>
>>> print_operand_tree(w)

<halerium.Add ‘Add’> ├─<halerium.Mul ‘Mul’> │ ├─<halerium.Const ‘Const’> │ └─<halerium.Variable ‘v’> │ ├─<halerium.Const ‘v/Const’> │ └─<halerium.Const ‘v/Const’> └─<halerium.Const ‘Const’>