Probabilistic Programming in Python: Bayesian Modeling and Probabilistic Machine Learning with Theano
Agent Success
Agent success rate when using this tile
68%
Improvement
Agent success rate improvement when using this tile compared to baseline
0.94x
Baseline
Agent success rate without this tile
72%
Implement a helper that builds a small Poisson switch model and runs sampling with explicit blocking: the two continuous rate variables are updated together in one block, and a discrete switch variable is updated with a caller-chosen random-walk proposal instead of relying on automatic step assignment.
[2, 4, 6, 9, 3, 5] with default arguments returns acceptance entries for both "rates" and "switch" blocks, each between 0 and 1, and block_assignments lists ["rate_a", "rate_b"] under "rates" and ["switch"] under "switch". @testproposal="gaussian" runs the sampler and yields a result whose proposal field is "gaussian" while keeping both blocks present in block_assignments. @test"heavy-tailed" or "gaussian" raises a ValueError that mentions the allowed options. @testrun_blocked_sampler twice with seed=7 on counts [2, 4, 6, 9, 3, 5] yields identical posterior_means for "rate_a" and "rate_b" to within 1e-6. @test@generates
from typing import Dict, List, Literal, Optional, TypedDict
class BlockedSamplingResult(TypedDict):
posterior_means: Dict[str, float]
acceptance: Dict[str, float]
block_assignments: Dict[str, List[str]]
proposal: Literal["heavy-tailed", "gaussian"]
def run_blocked_sampler(
counts: List[int],
draws: int = 500,
tune: int = 300,
proposal: Literal["heavy-tailed", "gaussian"] = "heavy-tailed",
seed: Optional[int] = None,
) -> BlockedSamplingResult:
"""
Build and sample a Poisson-rate switch model with manual blocked steps.
Returns posterior means computed from the retained draws, acceptance rates
for each sampling block, the variable grouping per block, and the proposal
label actually used for the discrete switch.
"""Probabilistic programming library used to define the model and run custom blocked sampling with user-chosen proposals.
Used for numerical inputs, random seeding, and summary statistics.
docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10