Route model: correct for reporting bias
- core/atlas/bias.py: for each rare roll (shadow, meadow Blue) and each source group, the factor by which the group over-reports the rare outcome relative to complete logging (bot, bulk logs), with a 90% range; rare outcomes from biased groups count 1/rho; a roll the complete logs have (almost) never shown is learned from them only - planner/policy.yaml: groups, rolls and thresholds; estimates published in policy.json under model.reportingBias - fit_alpha: a roll seen only one way is pooled fully - docs: goal accounts follow the best route, research accounts use Thompson sampling (decisionMode atlas_thompson) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UCzTd31GphpMXDhQqWrCMQ
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c0355616b6
commit
2271fe0976
+17
-4
@@ -148,21 +148,30 @@ def ctx_key(v, names):
|
||||
|
||||
# ---------------------------------------------------------------- 2. counts
|
||||
|
||||
def count_tables(prepared):
|
||||
"""Counts for every chance event at every back-off level, plus each encounter's outcomes."""
|
||||
def count_tables(prepared, weights=None):
|
||||
"""Counts for every chance event at every back-off level, plus each encounter's outcomes. weights: per run,
|
||||
{chance event: weight of the outcome it observed} (reporting-bias corrections, core/atlas/bias.py)."""
|
||||
T = {}
|
||||
for node, sp in CHANCE.items():
|
||||
t = T[node] = {}
|
||||
for v in prepared:
|
||||
for i, v in enumerate(prepared):
|
||||
y = OBSERVE[node](v)
|
||||
if not y:
|
||||
continue
|
||||
w = weights[i].get(node, 1) if weights else 1
|
||||
if w == 0:
|
||||
continue
|
||||
for L in range(len(sp["context"]) + 1):
|
||||
names = sp["context"][:L]
|
||||
if any(v.get(k) is None for k in names):
|
||||
break
|
||||
c = t.setdefault(f"{L}:{ctx_key(v, names)}", {})
|
||||
c[y] = c.get(y, 0) + 1
|
||||
c[y] = c.get(y, 0) + w
|
||||
for t in T.values(): # weighted counts are fractions: keep them short and stable
|
||||
for c in t.values():
|
||||
for k, x in c.items():
|
||||
if isinstance(x, float):
|
||||
c[k] = round(x, 4)
|
||||
enc = T["encounter"] = {}
|
||||
for v in prepared:
|
||||
if not v.get("encCtx"):
|
||||
@@ -261,6 +270,10 @@ def fit_alpha(T, node):
|
||||
pairs.append(([t[key].get(k, 0) for k in cats], pooled(parent)))
|
||||
if not pairs:
|
||||
return {"alpha": ALPHA, "logLik": None}
|
||||
# a roll that has only ever come out one way says nothing about whether routes differ: pool fully (the fit
|
||||
# would otherwise drive every route's chance of the unseen outcome to zero)
|
||||
if sum(1 for k in cats if t.get("0:", {}).get(k, 0) > 0) < 2:
|
||||
return {"alpha": max(ALPHA_GRID), "logLik": None}
|
||||
best_a, best_ll, lls = ALPHA, -math.inf, {}
|
||||
for a in ALPHA_GRID:
|
||||
ll = 0
|
||||
|
||||
Reference in New Issue
Block a user