SPPL (Sum-Product Probabilistic Language)
raw JSON → 2.0.4 verified Sat May 09 auth: no python
SPPL is a probabilistic programming language for specifying and manipulating sum-product expressions. Version 2.0.4 targets Python >=3.8. The library enables concise modeling of discrete and continuous random variables with automatic inference.
pip install sppl Common errors
error ImportError: cannot import name 'SPPLDistribution' from 'sppl' ↓
cause Trying to import SPPLDistribution from the top-level sppl package instead of the submodule.
fix
Use 'from sppl.distributions import SPPLDistribution'
error AttributeError: 'Variable' object has no attribute 'distribution' ↓
cause Accessing .distribution attribute that was renamed or restructured.
fix
Use the new API: see the documentation for accessing the distribution from a Variable.
error TypeError: __init__() missing 1 required positional argument: 'dist' ↓
cause Creating Variable without providing the distribution argument correctly.
fix
Ensure you pass the distribution as the second argument to Variable: Variable('name', distribution).
Warnings
breaking In version 2.0.0, the package structure changed: distributions are now in 'sppl.distributions' submodule, not directly under 'sppl'. ↓
fix Update imports: use 'from sppl.distributions import SPPLDistribution' instead of 'from sppl import SPPLDistribution'.
deprecated The function 'sppl.distributions.Distribution' is deprecated in favor of 'SPPLDistribution'. ↓
fix Replace 'Distribution' with 'SPPLDistribution' in your code.
gotcha Model variables must be defined inside a 'with model:' block, otherwise they are not added to the model. ↓
fix Always use 'with model:' context manager when defining variables.
Imports
- SPPLDistribution wrong
from sppl import SPPLDistributioncorrectfrom sppl.distributions import SPPLDistribution - Model
from sppl import Model - Variable
from sppl import Variable
Quickstart
from sppl import Model, Variable
from sppl.distributions import SPPLDistribution
import os
# Define a simple model: flip a fair coin
model = Model()
with model:
x = Variable('x', SPPLDistribution.bernoulli(0.5))
# Check the model structure
print(model)