CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-pymc3

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%

Overview
Eval results
Files

task.mdevals/scenario-8/

Marketing Causal Interventions

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.

Capabilities

Build baseline model

  • Given arrays for 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. @test

Interventional predictions

  • Provide a function that generates posterior predictive signups when campaign_spend is forcibly set to a supplied value (an intervention), leaving other relationships intact. Return both samples and a mean/median summary for the intervened scenario. @test

Observational conditioning

  • Provide a function that conditions the model on a new organic_visits value without rebuilding the graph, returning posterior predictive signups that reflect the new observation. @test

Graph exports

  • Provide graph exports for the fitted model in Graphviz DOT and Mermaid text formats, with nodes labeled organic_visits, campaign_spend, and signups, and directed edges reflecting the dependency structure. Graph outputs should be reproducible given the same model. @test

Implementation

@generates

API

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.
    """

Dependencies { .dependencies }

pymc { .dependency }

Provides probabilistic causal modeling, interventions/observations, and graph exporting utilities.

tile.json