Tutorial 1c: Building the SPN Graph Using A Generator

In [1]:
import libspn as spn

Build

In [2]:
iv_x = spn.IVs(num_vars=2, num_vals=2, name="iv_x")
gen=spn.DenseSPNGenerator(num_decomps=1, num_subsets=2, num_mixtures=2)
root=gen.generate(iv_x, root_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())
16
[Scope({iv_x:1, iv_x:0, iv_y:0})]
True

Visualize the SPN Graph

In [4]:
spn.display_spn_graph(root)