Tabellen statt Netze: je Knoten (Strasse, Topf, Vorflop-Aggressor, Position, Linie mit Groessenklassen, Textur, 12 Spielertypen) Range ueber Brett-Perzentil-Faecher, Aktionen, Strategie je Zelle und Fold-Range als Rest; Muck per IPW, hierarchische Glaettung. Holdout versiegelter Spieler: kalibriert, besser als BETTOR (River jede Groesse) und VORFLOP_BAND. Loader exploit::ranges_echt hinter RANGES_ECHT (aus). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
5.6 KiB
Python
128 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
|
"""ranges_echt, Vergleich mit VORFLOP_BAND (Holdout, einmal): Range am Flop vor der ersten Aktion im Topf
|
|
Small Blind gegen Big Blind (alle anderen gefoldet, Tisch >= 3 Spieler), gezeigte Haende versiegelter Spieler.
|
|
|
|
Linien:
|
|
open SB erhoeht, BB callt (topf S, pfa SB): SB-Band [0, r_sb], BB-Band [r_bbo, r_bbo + c_bbo]
|
|
limp SB limpt, BB checkt (topf L): SB-Band [r_sb, r_sb + c_sb], BB-Band [r_bbl, r_bbl + c_bbl]
|
|
Bander in Vorflop-Perzentil (0 = AA, `preflop::hand_percentile`), wie `exploit::vorflop_band`; je Spieler die
|
|
Tabelle seiner vpip-Stufe (`nach_vpip`), sonst Pool. Das Band ergibt je Brett eine Zellenverteilung
|
|
(`pokerbench-ranges-zellen band`). Gegen: R-Modell am Flop-Anfang (`f S|L pfa pos . textur typ`).
|
|
|
|
python -I -X utf8 messung/ranges_echt/vorflop.py <wurzel> <vorflop-phh-vpip.json> <exe> <aus.json> [--max 4000]
|
|
"""
|
|
import collections
|
|
import json
|
|
import math
|
|
import os
|
|
import random
|
|
import subprocess
|
|
import sys
|
|
|
|
import numpy as np
|
|
|
|
_hier = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, _hier)
|
|
import tabellen as T # noqa: E402
|
|
|
|
|
|
def baender(knoten):
|
|
sb, bbo, bbl = knoten["sb"], knoten["bb_open"], knoten["bb_limp"]
|
|
return {
|
|
("open", 0): (0.0, sb["r"]),
|
|
("open", 1): (bbo["r"], bbo["r"] + bbo["c"]),
|
|
("limp", 0): (sb["r"], sb["r"] + sb["c"]),
|
|
("limp", 1): (bbl["r"], bbl["r"] + bbl["c"]),
|
|
}
|
|
|
|
|
|
def main(wurzel, vf_pfad, exe, aus, maxn):
|
|
vf = json.load(open(vf_pfad, encoding="utf-8"))
|
|
pool = baender(vf["knoten"])
|
|
stufen = [(s["vpip"], baender(s["knoten"]), min(v["n"] for v in s["knoten"].values() if "n" in v)) for s in vf["nach_vpip"]]
|
|
tz = __import__("numpy").load(os.path.join(wurzel, "typen.npz"))
|
|
Z = tz["z"]
|
|
vp = dict(zip(tz["pid"].tolist(), (Z[:, 1] / np.maximum(Z[:, 0], 1)).tolist()))
|
|
hn = dict(zip(tz["pid"].tolist(), Z[:, 0].tolist()))
|
|
T._ranges_init(wurzel)
|
|
R = __import__("pickle").load(open(os.path.join(wurzel, "ranges.pkl"), "rb"))
|
|
kj = json.load(open(os.path.join(wurzel, "kappa.json")))
|
|
rm = T.r_modell(T.zusammen(R["train"], R["dev"]), kj["R"])
|
|
obs = []
|
|
for tag in T.tage(wurzel):
|
|
Zc = None
|
|
for ri, rec in enumerate(T.lesen(tag)):
|
|
if rec["n"] < 3 or rec["pos"] != ["SB", "BB"] or not rec["sd"]:
|
|
continue
|
|
if rec["vr"] == 1 and rec["pfa"] == 0:
|
|
linie = "open"
|
|
elif rec["vr"] == 0:
|
|
linie = "limp"
|
|
else:
|
|
continue
|
|
for x in (0, 1):
|
|
if not rec["h"][x] or not rec["sg"][x]:
|
|
continue
|
|
if Zc is None:
|
|
Zc = T.zellen_lesen(tag)
|
|
z = Zc.get("%d:%d" % (ri, x))
|
|
if z is None or z[0] < 0:
|
|
continue
|
|
acts, bretter, tex, ragg, allin = T.zerlegen(rec)
|
|
dec = T.entscheidungen(acts)
|
|
typs = [T._RM["tk"].get(rec["pid"][y], "?") for y in (0, 1)]
|
|
W = T.gewichte(rec, x, acts, dec, tex, typs, ragg, allin)
|
|
if W[0] <= 0:
|
|
continue
|
|
pid = rec["pid"][x]
|
|
b = pool[(linie, x)]
|
|
quelle = "pool"
|
|
if hn.get(pid, 0) >= 100:
|
|
for (lo, hi), bd, n in stufen:
|
|
if lo <= vp[pid] < hi:
|
|
b = bd[(linie, x)]
|
|
quelle = "vpip"
|
|
k = T.schluessel(rec, x, 0, ".", tex[0], typs[x])
|
|
obs.append((linie, x, rec["b"][:6], z[0], W[0], b, k, quelle))
|
|
random.Random(7).shuffle(obs)
|
|
obs = obs[:maxn]
|
|
# Band-Verteilungen je (Band, Brett)
|
|
je_band = collections.defaultdict(list)
|
|
for i, o in enumerate(obs):
|
|
je_band[o[5]].append((i, o[2]))
|
|
vert = {}
|
|
for (lo, hi), L in je_band.items():
|
|
ein = "\n".join("%d %s" % (i, b) for i, b in L) + "\n"
|
|
r = subprocess.run([exe, "band", repr(lo), repr(hi)], input=ein, capture_output=True, text=True, check=True)
|
|
for z in r.stdout.splitlines():
|
|
t = z.split()
|
|
vert[int(t[0])] = np.array([float(x) for x in t[1:]])
|
|
erg = collections.defaultdict(lambda: collections.defaultdict(float))
|
|
for i, (linie, x, brett, c, w, b, k, quelle) in enumerate(obs):
|
|
g = "%s %s" % (linie, "SB" if x == 0 else "BB")
|
|
pm = T.r_vorhersage(rm, k)[:40]
|
|
pb = vert[i]
|
|
pb = 0.98 * pb + 0.02 / 40 # Band hat harte Raender: Mindestmasse, sonst unendlicher Verlust
|
|
for gg in (g, "alle"):
|
|
e = erg[gg]
|
|
e["w"] += w
|
|
e["n"] += 1
|
|
e["modell"] += -w * math.log(max(pm[c], 1e-9))
|
|
e["vorflop_band"] += -w * math.log(max(pb[c], 1e-9))
|
|
e["anteil_vpip_stufe"] += (quelle == "vpip")
|
|
e["modell_top10"] += w * pm[[j for j in range(40) if j % 20 >= 18]].sum()
|
|
e["band_top10"] += w * pb[[j for j in range(40) if j % 20 >= 18]].sum()
|
|
e["beob_top10"] += w * (c % 20 >= 18)
|
|
out = {g: {"n": e["n"], "w": e["w"], "logloss_modell": e["modell"] / e["w"], "logloss_vorflop_band": e["vorflop_band"] / e["w"],
|
|
"anteil_vpip_stufe": e["anteil_vpip_stufe"] / e["n"],
|
|
"top10_modell": e["modell_top10"] / e["w"], "top10_band": e["band_top10"] / e["w"], "top10_beob": e["beob_top10"] / e["w"]}
|
|
for g, e in erg.items()}
|
|
json.dump(out, open(aus, "w", encoding="utf-8"), indent=1)
|
|
print(json.dumps(out, indent=1))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
a = sys.argv[1:]
|
|
mx = int(a[a.index("--max") + 1]) if "--max" in a else 4000
|
|
main(a[0], a[1], a[2], a[3], mx)
|