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 small causal analysis helper that builds and queries a marketing signups model. The helper must make it easy to compare the observed data distribution to interventional and newly observed scenarios, and expose the model graph for inspection.
organic_visits, campaign_spend, and signups, construct a causal model where signups depend on both drivers and campaign_spend depends on organic_visits as a confounder. Return a fitted model handle and posterior samples for later reuse. Accept an optional random seed so repeated runs match. @testorganic_visits, campaign_spend, and signups, and directed edges reflecting the dependency structure. Graph outputs should be reproducible given the same model. @test@generates
from typing import Any, Mapping, Sequence, Tuple
def build_campaign_model(data: Mapping[str, Sequence[float]], draws: int = 500, random_seed: int | None = None) -> Tuple[Any, Any]:
"""
Create and sample a causal model for marketing signups. Returns a tuple of (model, posterior_samples/trace).
"""
def sample_observational(model: Any, trace: Any, draws: int = 500, random_seed: int | None = None) -> Mapping[str, Any]:
"""
Produce posterior predictive signups for the observed dataset using the fitted model.
"""
def sample_with_intervention(model: Any, trace: Any, spend_value: float, draws: int = 500, random_seed: int | None = None) -> Mapping[str, Any]:
"""
Generate posterior predictive signups when campaign_spend is intervened to spend_value (do-scenario), returning samples and summary statistics.
"""
def sample_with_observation(model: Any, trace: Any, organic_value: float, draws: int = 500, random_seed: int | None = None) -> Mapping[str, Any]:
"""
Generate posterior predictive signups conditioned on observing organic_visits at organic_value without altering other structure.
"""
def export_graphs(model: Any) -> Mapping[str, Any]:
"""
Return both Graphviz DOT text and Mermaid text (and optionally a lightweight in-memory graph object) representing nodes and directed edges: organic_visits -> campaign_spend -> signups with organic_visits also affecting signups.
"""Provides probabilistic causal modeling, interventions/observations, and graph exporting utilities.
docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10