Region graphs

The region graph utilities can be made to create SPNs by explicitly defining the region structure. This can be used to e.g. conveniently express some learned structure.

For some examples on how to use region graphs check out this tutorial.

class libspn_keras.RegionVariable(index)

Represents a region in the SPN.

Regions graphs are DAGs just like SPNs, but they do not represent sums and products. They are merely used for defining the scope structure of the SPN.

A RegionVariable is a leaf node without children, as opposed to a RegionNode which is a node with children.

Parameters

index (int) – Index of the variable

class libspn_keras.RegionNode(children)

Represents a region in the SPN.

Regions graphs are DAGs just like SPNs, but they do not represent sums and products. They are merely used for defining the scope structure of the SPN.

A RegionNode is a node with children, as opposed to a RegionVariable, which is a leaf node.

Parameters

children (list of RegionNode or RegionVariable) – children of this node. Scope of the resulting node is the union of the scopes of its children. The scopes of these children must not overlap (pairwise disjoint)

libspn_keras.region_graph_to_dense_spn(region_graph_root, leaf_node, num_sums_iterable, return_weighted_child_logits, logspace_accumulators=False, accumulator_initializer=None, linear_accumulator_constraint=None, product_first=True, num_classes=None, with_root=True, sum_op=None)

Convert a region graph (built from RegionNode and RegionVar) to a dense SPN.

Parameters
  • region_graph_root (RegionNode) – Root of the region graph

  • leaf_node (BaseLeaf) – Node to insert at the leaf of the SPN

  • num_sums_iterable (Iterator[int]) – Number of sums for all but the last root sum layer from bottom to top

  • logspace_accumulators (bool) – Whether to represent accumulators of weights in logspace or not

  • accumulator_initializer (Optional[Initializer]) – Initializer for accumulators

  • linear_accumulator_constraint (Optional[Constraint]) – Constraint for linear accumulator, default: GreaterThanEpsilon

  • product_first (bool) – Whether to start with a product layer

  • num_classes (Optional[int]) – Number of classes at output. If None, will not use ‘latent’ sums at the end but will instead directly connect the root to the final layer of the dense stack. This means if set to None the SPN cannot be used for classification.

  • with_root (bool) – If True, sets a RootSum as the final layer.

  • return_weighted_child_logits (bool) – Whether to return weighted child logits.

  • sum_op (Optional[SumOpBase]) – SumOpBase instance to use for sum layers.

Return type

Sequential

Returns

A Sum-Product Network as a tf.keras.Sequential model.