Getting started

Installation

Stochastic Program IR requires Python 3.10 or newer:

pip install stoch-ir

The package is in alpha. Pin an exact prerelease version when reproducibility matters.

Build a graph

Distribution constructors return immutable symbolic expressions:

from stoch_ir import Normal, sampling_phase, softplus

with sampling_phase("latent"):
    row_effect = Normal(0.0, 1.0, plates="row")

with sampling_phase("observation"):
    observation = Normal(
        mu=row_effect,
        sigma=softplus(row_effect) + 0.1,
        plates=("row", "replicate"),
    )

row_score = observation.mean("replicate").check_plates("row")

No sample is drawn while this graph is authored.

Realize a value

value = row_score.realize(
    seed=10,
    plate_sizes={"row": 4, "replicate": 32},
)

print(value.data)
print(value.plates)

The result is a stoch_ir.ConcreteValue with immutable canonical NumPy storage.

Distributions

v0.1 exposes:

Stochastic Program IR is a forward-sampling library. It does not implement conditioning or posterior inference.