Convolutional Modules¶
Convolutional layers for modeling spatial structure in image data with probabilistic circuits.
SumConv¶
Convolutional sum layer that applies learned weighted sums over input channels within spatial patches. Enables mixture modeling with spatial structure.
- class spflow.modules.conv.SumConv(inputs, out_channels, kernel_size, num_repetitions=1)[source]¶
Bases:
ModuleConvolutional sum layer for probabilistic circuits.
Applies weighted sum over input channels within spatial patches. Weights are learned and normalized to sum to one per patch position, maintaining valid probability distributions. Useful for modeling spatial structure in image data.
The layer expects input with spatial structure and applies shared weights across all spatial patches of the same position within the kernel.
- inputs¶
Input module providing log-likelihoods.
- Type:
Module
- logits¶
Unnormalized log-weights for gradient optimization.
- Type:
Parameter
- __init__(inputs, out_channels, kernel_size, num_repetitions=1)[source]¶
Create a SumConv module for spatial mixture modeling.
- Parameters:
- Raises:
ValueError – If out_channels < 1 or kernel_size < 1.
- log_likelihood(data, cache=None)[source]¶
Compute log likelihood using convolutional weighted sum.
Applies weighted sum over input channels within spatial patches. Each kernel position gets its own set of mixture weights. Uses logsumexp for numerical stability.
- marginalize(marg_rvs, prune=True, cache=None)[source]¶
Marginalize out specified random variables.
- Parameters:
- Returns:
Marginalized module or None if fully marginalized.
- Return type:
SumConv | Module | None
ProdConv¶
Convolutional product layer that computes products over spatial patches, reducing spatial dimensions by the kernel size factor. Aggregates scopes within patches while maintaining proper probabilistic semantics.
- class spflow.modules.conv.ProdConv(inputs, kernel_size_h, kernel_size_w, padding_h=0, padding_w=0)[source]¶
Bases:
ModuleConvolutional product layer for probabilistic circuits.
Computes products over spatial patches, reducing spatial dimensions by the kernel size factor. This is equivalent to summing log-likelihoods within patches. No learnable parameters.
Scopes are aggregated per patch: a 2×2 patch containing Scope(0), Scope(1), Scope(2), Scope(3) produces Scope([0,1,2,3]).
- inputs¶
Input module providing log-likelihoods.
- Type:
Module
- __init__(inputs, kernel_size_h, kernel_size_w, padding_h=0, padding_w=0)[source]¶
Create a ProdConv module for spatial product operations.
- Parameters:
inputs (
Module) – Input module providing log-likelihoods with spatial structure.kernel_size_h (
int) – Height of the pooling kernel.kernel_size_w (
int) – Width of the pooling kernel.padding_h (
int) – Padding in height dimension (added on both sides).padding_w (
int) – Padding in width dimension (added on both sides).
- Raises:
ValueError – If kernel sizes are < 1.
- log_likelihood(data, cache=None)[source]¶
Compute log likelihood by summing within patches.
Uses depthwise convolution with ones kernel to efficiently sum log-probabilities within patches.