Random and Tensorized Sum-Product Networks (RAT-SPN)¶
Random and Tensorized Sum-Product Networks (RAT-SPNs) provide a principled approach to building deep probabilistic models through randomized circuit construction. They combine interpretability with expressiveness through tensorized operations.
Reference¶
RAT-SPNs are described in the NeurIPS 2020 paper:
Overview¶
RAT-SPNs consist of alternating sum (region) and product (partition) layers that recursively partition the input space. The random construction prevents overfitting while maintaining tractable exact inference.
Key features:¶
Randomized structure: Region and partition layers are constructed using random permutations and splits.
Tensorized evaluation: Operations are mapped to efficient tensor contractions.
Scalable training: Supports training via EM or Gradient Descent.
Implementation¶
The RAT-SPN implementation in SPFlow provides a high-level spflow.zoo.rat.RatSPN module that automates the construction of the circuit based on architectural hyperparameters.
- class spflow.zoo.rat.RatSPN(leaf_modules, n_root_nodes, n_region_nodes, num_repetitions, depth, outer_product=False, split_mode=None, num_splits=2)[source]¶
Bases:
Module,ClassifierRandom and Tensorized Sum-Product Network (RAT-SPN).
Scalable deep probabilistic model with randomized circuit construction. Consists of alternating sum (region) and product (partition) layers that recursively partition input space. Random construction prevents overfitting while maintaining tractable exact inference.
- leaf_modules¶
Leaf distribution modules.
- Type:
list[LeafModule]
- scope¶
Combined scope of all leaf modules.
- Type:
Scope
- Reference:
Peharz, R., et al. (2020). “Random Sum-Product Networks: A Simple and Effective Approach to Probabilistic Deep Learning.” NeurIPS 2020.
- __init__(leaf_modules, n_root_nodes, n_region_nodes, num_repetitions, depth, outer_product=False, split_mode=None, num_splits=2)[source]¶
Initialize RAT-SPN with specified architecture parameters.
Creates a Random and Tensorized SPN by recursively constructing layers of sum and product nodes. Circuit structure is fixed after initialization.
- Parameters:
leaf_modules (
list[LeafModule]) – Leaf distributions forming the base layer.n_root_nodes (
int) – Number of root sum nodes in final mixture.n_region_nodes (
int) – Number of sum nodes in each region layer.num_repetitions (
int) – Number of parallel circuit instances.depth (
int) – Number of partition/region layers.outer_product (
bool | None, optional) – Use outer product instead of elementwise product for partitions. Defaults to False.split_mode (
SplitMode | None, optional) – Split configuration. Use SplitMode.consecutive() or SplitMode.interleaved(). Defaults to SplitMode.consecutive(num_splits) if not specified.num_splits (
int | None, optional) – Number of splits in each partition. Must be at least 2. Defaults to 2.
- Raises:
ValueError – If architectural parameters are invalid.
- create_spn()[source]¶
Create the RAT-SPN architecture.
Builds the RAT-SPN circuit structure from bottom to top based on the provided architectural parameters. Architecture is constructed recursively from leaves to root using alternating layers of sum and product nodes, and the final structure depends on depth and branching parameters.
- log_posterior(data, cache=None)[source]¶
Compute log-posterior probabilities for multi-class models.
- predict_proba(data)[source]¶
Classify input data using RAT-SPN.
- Parameters:
data (
Tensor) – Input data tensor.- Returns:
Predicted class labels.
- sample(num_samples=None, data=None, is_mpe=False, cache=None)[source]¶
Generate samples from the RAT-SPN.
- Parameters:
- Return type:
- Returns:
Sampled values.