Route model: first attempts are their own shadow roll; experiment plan and automated bot cycle
- game.yaml: `givens` (first or later attempt) and `distinct` levels that are not pooled; the shadow roll
depends on the attempt first. Form submissions show the shadow on 9% of first attempts and 0.3% of later ones.
- Reporting bias: a roll whose bias cannot be measured can borrow another roll's (`borrow: {shadow: meadow}`),
so form submissions inform the shadow again. An assumption, stated in planner/policy.yaml.
- policy.json: targets.<colour>.firstAttempt (this attempt, eventually). Black: about 1.4% on a first attempt,
0.07% on a later one.
- solver.js: advisor options `attempt`, `fix`, sampling "uniform"; assign() and armFor() for the plan.
- planner/experiments.yaml + build_experiments.py -> data/public/experiments.json (progress and status per
experiment, rebuilt from the bot's runs).
- python -m collection cycle: import bot runs, refit, re-plan, deliver the kit; .gitea/workflows/bot-cycle.yml.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014jqCC2LZ4x1WHQ1V57nTsv
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
ee07ee143e
commit
ab3664f369
+24
-5
@@ -28,6 +28,8 @@ ALONE = "(alone)"
|
||||
ALPHA = 20
|
||||
ALPHA_GRID = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 20000, 100000]
|
||||
ENC_CATS = G["encounter_outcomes"]
|
||||
GIVENS = G.get("givens") or {}
|
||||
DEFAULT_GIVEN = {k: g["default"] for k, g in GIVENS.items()}
|
||||
|
||||
|
||||
def enc_colour(ctx):
|
||||
@@ -62,6 +64,8 @@ def prepare_run(r):
|
||||
v = {"company": r["company"] if r["company"] in DECISIONS["company"] else None,
|
||||
"direction": r["direction"] if r["direction"] in DECISIONS["direction"] else None,
|
||||
"fs": r["first_sighting"] if r["first_sighting"] in ("Red", "Brown", "Green", "Orange") else None}
|
||||
# the givens (game.yaml): first or later attempt, from the run's attempt number
|
||||
v["attempt"] = r.get("attempt_group") if r.get("attempt_group") in GIVENS.get("attempt", {}).get("values", ()) else None
|
||||
lf = r.get("left_squadmates")
|
||||
known = lf is not None and not (isinstance(lf, float) and lf != lf) and lf != ""
|
||||
v["left"] = ALONE if v["company"] == "Alone" else (("Leave them" if lf is True or str(lf).lower() == "true" else "Stay together") if v["company"] and known else None)
|
||||
@@ -279,7 +283,7 @@ def fit_alpha(T, node):
|
||||
pairs = []
|
||||
for key in t:
|
||||
L = int(key.split(":")[0])
|
||||
if L == 0:
|
||||
if L <= CHANCE[node].get("distinct", 0): # the top level, and levels that are not pooled (game.yaml)
|
||||
continue
|
||||
ctx = key[key.index(":") + 1:].split("|")
|
||||
parent = f"{L - 1}:" + "|".join(ctx[:L - 1])
|
||||
@@ -368,10 +372,14 @@ class Params:
|
||||
In draw mode each world draws its numbers in the order its own walk of the game first needs them (a branch with
|
||||
probability exactly zero in that world is never walked), so call solver.draw_worlds() before using it.
|
||||
chance(node, state) -> {outcome: array(D)}; encounter(ctx) -> {outcome: array(D)}.
|
||||
|
||||
given: the run's givens (game.yaml `givens`, e.g. first or later attempt); having() gives the same worlds for
|
||||
other givens.
|
||||
"""
|
||||
|
||||
def __init__(self, T, mode="mean", seeds=(), alphas=None):
|
||||
def __init__(self, T, mode="mean", seeds=(), alphas=None, given=None):
|
||||
self.T, self.mode, self.alphas = T, mode, alphas or {}
|
||||
self.given = {**DEFAULT_GIVEN, **(given or {})}
|
||||
self.rngs = [Rng(s) for s in seeds] if mode == "draw" else []
|
||||
self.D = len(self.rngs) if mode == "draw" else 1
|
||||
self.memo = {} # (node, level key) or ("enc", ctx) -> array (K, D)
|
||||
@@ -379,6 +387,14 @@ class Params:
|
||||
self.world = None # while drawing one world (see draw_world), its index
|
||||
self._cache = {}
|
||||
|
||||
def having(self, **given):
|
||||
"""The same odds (and the same posterior draws) for a run with other givens."""
|
||||
import copy
|
||||
p = copy.copy(self)
|
||||
p.given = {**self.given, **given}
|
||||
p._cache = {}
|
||||
return p
|
||||
|
||||
def _levels(self, node, state):
|
||||
sp = CHANCE[node]
|
||||
out = []
|
||||
@@ -408,6 +424,7 @@ class Params:
|
||||
if not gate_open(node, state): # a closed gate: the roll always comes out the same way
|
||||
other = CHANCE[node]["otherwise"]
|
||||
return {k: np.full(self.D, 1.0 if k == other else 0.0) for k in CHANCE[node]["outcomes"]}
|
||||
state = {**self.given, **state}
|
||||
# once every world has been drawn, the answer depends only on the context values: cache it
|
||||
ck = (node, tuple(state.get(k) for k in CHANCE[node]["context"]))
|
||||
if self.world is None and ck in self._cache:
|
||||
@@ -419,13 +436,15 @@ class Params:
|
||||
|
||||
def _chance(self, node, state):
|
||||
cats = CHANCE[node]["outcomes"]
|
||||
al = self.alphas.get(node) or ALPHA
|
||||
fitted = self.alphas.get(node) or ALPHA
|
||||
distinct = CHANCE[node].get("distinct", 0)
|
||||
p = None
|
||||
for key in self._levels(node, state):
|
||||
for L, key in enumerate(self._levels(node, state)):
|
||||
c = self.T[node].get(key, {})
|
||||
parent = p
|
||||
al = 1.0 if L <= distinct else fitted # a level that is not pooled keeps a token prior of one run
|
||||
|
||||
def make_a(d, c=c, parent=parent):
|
||||
def make_a(d, c=c, parent=parent, al=al):
|
||||
if parent is None:
|
||||
return [c.get(k, 0) + 0.5 for k in cats]
|
||||
return [c.get(k, 0) + al * (parent[i] if d is None else parent[i][d]) for i, k in enumerate(cats)]
|
||||
|
||||
Reference in New Issue
Block a user