Files
mmintelandClaude Opus 4.8 2a05653f40 Stufe 0: Uebung-Live-Test - Gesamt-bb/100 mit 95%-CI + stufe0-Bericht + Runbook
Der Uebung-Loop existiert schon (spielplan.json modus=uebung -> Practice Games,
spielgeld-gesperrt, Engine spielt, Haende in statistik). Was fehlte, ist die Messung:

- statistik._gruppe liefert jetzt Gesamt-bb/100 mit 95%-Spanne (unten/oben), auch in STATS.md.
- betrieb/stufe0.py: Uebung-Bericht - schlaegt es die Null (Spanne>0), Stil sane (VPIP/PFR/
  Showdown, PFR<=VPIP), Loop-Gesundheit (Abbrueche/Timeouts/Abstains), Sim-to-Real-Band.
- Specs: tests/stufe0_spec.py (16) + statistik_spec (21, Regression ok).
- docs/notizen/BEFUND-stufe0-uebung.md: Befund, Runbook, Varianz-Mathematik.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-12 15:57:13 +01:00

180 lines
8.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Stufe-0-Bericht (Übung): schlägt die Engine live die Null, spielt sie sane, läuft der Loop sauber?
Liest den Statistik-Speicher einer Übungs-Sitzung (betrieb/statistik.py: haende.jsonl +
ereignisse.jsonl) und - wenn angegeben - das Schattenlog des Läufers (runner: shadow*.jsonl) für
die Loop-Gesundheit. Das Urteil sagt NUR, was die Stichprobe hergibt:
* live bb/100 mit 95-%-Spanne (statistik.spanne_bb_pro_100): ist die Untergrenze > 0, schlägt die
Engine die Null MIT 95 % Sicherheit. Überlappt die Spanne die Null, ist es Zufall, kein Beweis
(dieselbe Regel wie statistik.bestes_format).
* Spielstil (VPIP/PFR/Showdown): eine degenerierte Engine (VPIP 2 % oder 95 %, PFR > VPIP) fällt
auf, bevor man Micro-Geld riskiert.
* Loop-Gesundheit: Abbrüche (Invariantenbruch), Timeouts (Uhr abgelaufen -> Server-Sitout),
Abstains (der Kern gab keine Aktion). Null Abbrüche und null Timeouts = der Loop trägt.
python3 betrieb/stufe0.py # STATS_DIR / archiv/lauf
python3 betrieb/stufe0.py --pfad DIR --shadow shadow.jsonl
python3 betrieb/stufe0.py --erwartung 80 300 --json # Sim-to-Real-Band vergleichen
VARIANZ (ehrlich): live kann KEINE Karten paaren wie die Synthetik-Leiter - jede Hand wird einmal
ausgeteilt, die volle Varianz (σ ≈ 90 bb/100) bleibt. Übung löst darum nur GROBE Dinge auf:
gewinnt es überhaupt, läuft der Loop, ist der Stil sane. Feine A/B-Deltas (1-9 bb/100) brauchen
>100k Hände je Arm und gehören nach Stufe 2 (mit All-in-EV/AIVAT-Varianzreduktion), nicht hierher.
"""
import os as _os, sys as _sys
_w = _os.path.dirname(_os.path.abspath(__file__))
while _w != "/" and not _os.path.isdir(_os.path.join(_w, "betrieb")):
_w = _os.path.dirname(_w)
WURZEL = _w
for _u in ("lesen", "betrieb"):
_q = _os.path.join(_w, _u)
if _os.path.isdir(_q) and _q not in _sys.path:
_sys.path.insert(0, _q)
import argparse
import json
import statistik
# Stil-Band: ausserhalb ist eine Engine degeneriert (nicht spielbar), nicht nur ausbeutbar.
VPIP_MIN, VPIP_MAX = 0.05, 0.90
SHOWDOWN_MIN = 0.02
def _urteil_null(unten, oben, n):
"""Schlägt die Engine die Null? Nur mit der 95-%-Spanne - Überlappung heisst Zufall."""
if n < 2 or unten is None or oben is None:
return "zu wenig Hände für ein Urteil"
if unten > 0:
return "gewinnt mit 95 % Sicherheit"
if oben < 0:
return "verliert mit 95 % Sicherheit"
return "noch Zufall (die 95-%-Spanne überlappt die Null)"
def _stil(gesamt):
"""VPIP/PFR/Showdown und ob sie in einem spielbaren Band liegen (PFR <= VPIP, kein Extrem)."""
vpip, pfr, sd = gesamt.get("vpip"), gesamt.get("pfr"), gesamt.get("showdown")
hinweise = []
if vpip is None:
hinweise.append("keine Hände")
else:
if not (VPIP_MIN <= vpip <= VPIP_MAX):
hinweise.append(f"VPIP {vpip*100:.0f} % ausserhalb {VPIP_MIN*100:.0f}-{VPIP_MAX*100:.0f} %")
if pfr is not None and pfr > vpip + 1e-9:
hinweise.append(f"PFR {pfr*100:.0f} % > VPIP {vpip*100:.0f} % (unmöglich - Lesefehler)")
if sd is not None and sd < SHOWDOWN_MIN:
hinweise.append(f"Showdown {sd*100:.1f} % sehr niedrig")
return {"vpip": vpip, "pfr": pfr, "showdown": sd, "sane": not hinweise,
"hinweise": hinweise}
def _loop(ereignisse, shadow):
"""Loop-Gesundheit: Abbrüche/Timeouts/Abstains/Sitouts. Abbruch oder Timeout = der Loop hakt."""
abbruch = sum(1 for e in shadow if e.get("ereignis") == "abbruch")
abstain = sum(1 for e in shadow
if isinstance(e.get("antwort"), dict)
and (e["antwort"].get("action") or "").upper() == "ABSTAIN")
timeouts = (sum(1 for e in ereignisse if e.get("grund") == "timeout")
+ sum(1 for e in shadow if e.get("ereignis") == "timeout"
or (e.get("grund") == "timeout")))
sitouts = sum(1 for e in ereignisse if e.get("art") in statistik.AUSZEIT_ARTEN)
return {"abbruch": abbruch, "timeouts": timeouts, "abstains": abstain, "sitouts": sitouts,
"sauber": abbruch == 0 and timeouts == 0}
def _sim_to_real(unten, oben, erwartung):
"""Live-Spanne gegen ein erwartetes Band (lo, hi) aus der Synthetik - Überlappung = im Rahmen."""
if erwartung is None:
return None
lo_e, hi_e = erwartung
if unten is None or oben is None:
urteil = "zu wenig Hände"
elif unten > hi_e:
urteil = "besser als erwartet (live-Spanne über dem Band)"
elif oben < lo_e:
urteil = "schlechter als erwartet (live-Spanne unter dem Band)"
else:
urteil = "im erwarteten Bereich (Spannen überlappen)"
return {"erwartet_unten": lo_e, "erwartet_oben": hi_e, "urteil": urteil}
def bericht(haende, ereignisse=(), shadow=(), erwartung=None):
"""Der ganze Stufe-0-Bericht als reines dict (JSON-fähig). `erwartung`: (lo, hi) bb/100-Band
aus der Synthetik für den Sim-to-Real-Vergleich, oder None."""
haende = list(haende)
kz = statistik.kennzahlen_aus(haende, list(ereignisse))
g = kz["gesamt"]
n = g["haende"]
unten, oben = g.get("unten"), g.get("oben")
return {
"haende": n,
"von": kz["von"], "bis": kz["bis"],
"bb_pro_100": g["bb_pro_100"], "unten": unten, "oben": oben,
"schlaegt_null": bool(unten is not None and unten > 0),
"urteil": _urteil_null(unten, oben, n),
"stil": _stil(g),
"loop": _loop(list(ereignisse), list(shadow)),
"sim_to_real": _sim_to_real(unten, oben, erwartung),
}
def _spanne_text(unten, oben):
return f"{unten:.1f} bis {oben:.1f}" if unten is not None else "- (zu wenig Hände)"
def text(b):
"""Der Bericht als kompakter Text fürs Terminal."""
z = ["=== Stufe-0-Bericht (Übung) ===",
f"Hände: {b['haende']}" + (f" ({b['von']} bis {b['bis']})" if b["von"] else "")]
bb = "-" if b["bb_pro_100"] is None else f"{b['bb_pro_100']:+.1f}"
z.append(f"bb/100: {bb} 95-%-Spanne: {_spanne_text(b['unten'], b['oben'])}")
z.append(f" -> {b['urteil']}")
s = b["stil"]
def _p(x):
return "-" if x is None else f"{x*100:.0f} %"
z.append(f"Stil: VPIP {_p(s['vpip'])} PFR {_p(s['pfr'])} Showdown {_p(s['showdown'])}"
+ (" [sane]" if s["sane"] else " [PROBLEM: " + "; ".join(s["hinweise"]) + "]"))
lp = b["loop"]
z.append(f"Loop: Abbrüche {lp['abbruch']} Timeouts {lp['timeouts']} Abstains {lp['abstains']}"
f" Sitouts {lp['sitouts']} -> " + ("sauber" if lp["sauber"] else "HAKT (Abbruch/Timeout)"))
if b["sim_to_real"]:
st = b["sim_to_real"]
z.append(f"Sim-to-Real: erwartet {st['erwartet_unten']:.0f} bis {st['erwartet_oben']:.0f} bb/100"
f" -> {st['urteil']}")
return "\n".join(z)
def _shadow_lesen(pfad):
if not pfad or not _os.path.exists(pfad):
return []
out = []
with open(pfad, encoding="utf-8") as f:
for zeile in f:
try:
d = json.loads(zeile)
except ValueError:
continue
if isinstance(d, dict):
out.append(d)
return out
def main(argv=None):
p = argparse.ArgumentParser(description="Stufe-0-Bericht (Übung): schlägt es die Null, Loop sauber?")
p.add_argument("--pfad", help="Statistik-Ordner (Vorgabe: STATS_DIR oder archiv/lauf)")
p.add_argument("--shadow", help="Schattenlog des Läufers (shadow*.jsonl) für die Loop-Gesundheit")
p.add_argument("--erwartung", nargs=2, type=float, metavar=("UNTEN", "OBEN"),
help="erwartetes bb/100-Band aus der Synthetik (Sim-to-Real)")
p.add_argument("--json", action="store_true", help="als JSON statt Text")
a = p.parse_args(argv)
st = statistik.Statistik(a.pfad)
b = bericht(st.haende(), st.ereignisse(), _shadow_lesen(a.shadow),
tuple(a.erwartung) if a.erwartung else None)
print(json.dumps(b, indent=1, ensure_ascii=False) if a.json else text(b))
return 0
if __name__ == "__main__":
_sys.exit(main())