Tutorial 1b: Building the SPN Graph Using Multi-Op Nodes

In [1]:
import libspn as spn

Build

In [2]:
iv_x = spn.IVs(num_vars=2, num_vals=2, name="iv_x")
sums_1 = spn.ParSums((iv_x, [0,1]), num_sums=2, name="sums_1")
sums_2 = spn.ParSums((iv_x, [2,3]), num_sums=2, name="sums_2")
prods_1 = spn.PermProducts(sums_1, sums_2, name="prods_1")
root = spn.Sum(prods_1, name="root")
iv_y = root.generate_ivs(name="iv_y") # Can be added manually
spn.generate_weights(root, init_value=spn.ValueType.RANDOM_UNIFORM(0, 1)) # Can be added manually

Inspect

In [3]:
print(root.get_num_nodes())
print(root.get_scope())
print(root.is_valid())
9
[Scope({iv_x:0, iv_x:1, iv_y:0})]
True

Visualize the SPN Graph

In [4]:
spn.display_spn_graph(root)