import numpy as np
import pandas as pd
from ergodic import dag
from ergodic.decision import decide

rng = np.random.default_rng(8)
n = 4000
z = rng.uniform(-1, 1, n)
a = rng.integers(0, 3, n)
labels = np.array(["none", "small", "large"])[a]
y = z + a * (1 + .5 * z) + rng.normal(0, .2, n)
context = pd.DataFrame({"z": z, "action": labels, "outcome": y})
result = decide(
    dag(["z -> outcome", "action -> outcome"]),
    context,
    target="outcome",
    interventions={"action": {"baseline": "none", "values": ("small", "large")}},
    rows=pd.DataFrame({"z": [-.5, .5]}),
    seed=8,
)
for action in result["population"]:
    print(action["value"], round(action["effect"], 2))
print("query best actions:", [row["interventions"][0]["value"] for row in result["individual"]])
print("skipped:", len(result["skipped"]))
