Fix player key sign for counters, add type posterior output per type division

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Marc Mintel
2026-12-06 01:14:07 +01:00
co-authored by Claude Opus 5.5
parent 49b32f1184
commit ce0908ca76
4 changed files with 109 additions and 0 deletions
+2
View File
@@ -158,6 +158,8 @@ def ereignisse_aus_handsatz(h: dict, limit_bb: float, hand_nr: int = 0, held: Op
pid = ids[i] if i < len(ids) else ""
try:
spieler = int(pid, 16) if pid and len(pid) == 16 else 0
if spieler >= 1 << 63:
spieler -= 1 << 64 # wie die Zaehler (int64-Bitmuster)
except ValueError:
spieler = 0
kt = karten.get(str(i))
+82
View File
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
# Typ-Wahl: Spielerschluessel -> Posterior-Typ je Typ-Einteilung (Kandidaten fuer "genau EINE Typ-Einteilung").
# Einteilungen: vpip3 (hart: < 22 % / < 45 % / sonst, ab 30 Haenden, wie limp-ranges), vpip4_kurve (0 unbekannt + dieselben drei Klassen, wie die Antwortkurve),
# latent8 (Posterior der 8 latenten Typen des Gedaechtnisses ohne Dateien 308-385, Zaehler 0-307). Die 48 Typen von v4 fehlen (kein Spielerbezug im Export).
# Die Ausgabe traegt Spielerschluessel: sie liegt NUR auf der SSD (Standard .../gegnermodell/typen-<datum>/), nie im Git, nie in der Karte.
# python3 messung/gegnermodell/typen.py [--ziel ORDNER]
import sys; sys.dont_write_bytecode = True
import argparse
import gzip
import json
import os
import time
HIER = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HIER)
import knoten_abbild as KN # noqa: E402
VPIP_KANTEN = (0.22, 0.45)
HAENDE_MIN = 30
def vpip_aus_zaehlern(fein):
"""(VPIP, Zahl Haende) aus den Vorflop-Zaehlern eines Spielers. Erste Entscheidung je Hand (eigen 0); VPIP = Call/Raise, nicht der Gratis-Check der Big Blind."""
haende = vpip = 0
for c, z in fein.items():
if c >= KN.VORFLOP_MAX:
continue
t = KN.teile(c)
if t["eigen"] != 0:
continue
n = int(z.sum())
haende += n
freiwillig = int(z[2:].sum()) + (0 if (t["pos"] == 1 and t["lage"] <= 1) else int(z[1]))
vpip += freiwillig
return (vpip / haende if haende else None), haende
def vpip_klasse(vpip, haende):
"""0 unbekannt, 1 eng, 2 mittel, 3 locker."""
if vpip is None or haende < HAENDE_MIN:
return 0
return 1 + sum(1 for k in VPIP_KANTEN if vpip >= k)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--hhd", default="/Volumes/Alpha SSD/pokerfreak-daten/gedaechtnis2/hhd")
ap.add_argument("--zaehler", default="/Volumes/Alpha SSD/pokerfreak-daten/welt_v4/zaehler")
ap.add_argument("--modell", default="/Volumes/Alpha SSD/pokerfreak-daten/gedaechtnis3/modell-ohne-308-385-kanonisch/modell.json")
ap.add_argument("--ziel", default="/Volumes/Alpha SSD/pokerfreak-daten/gegnermodell/typen-%s" % time.strftime("%Y-%m-%d"))
a = ap.parse_args()
from zaehlstand import Zaehlstand, tagesdateien
from kand_gedaechtnis import GedaechtnisModell
import numpy as np
dateien = tagesdateien(a.hhd)
z = Zaehlstand.lade(a.zaehler, dateien, 0, 307)
m = GedaechtnisModell(a.modell)
aus = os.path.join(a.ziel, "typ-posterior.jsonl.gz")
zeilen = []
for pid in z.alle_spieler():
fein, mittel, _ = z.spieler(pid)
v, h = vpip_aus_zaehlern(fein)
k = vpip_klasse(v, h)
zeilen.append(json.dumps({"spieler": "%016x" % (pid & 0xFFFFFFFFFFFFFFFF), "haende": h, "vpip": None if v is None else round(v, 4), "vpip3": k - 1 if k else None,
"vpip4_kurve": k, "latent8": [round(float(x), 5) for x in m.typ_gewichte(mittel)]}))
import io
puffer = io.BytesIO()
with gzip.GzipFile(fileobj=puffer, mode="wb", mtime=0) as g:
g.write(("\n".join(zeilen) + "\n").encode())
os.makedirs(a.ziel, exist_ok=True)
tmp = aus + ".tmp"
with open(tmp, "wb") as f:
f.write(puffer.getvalue())
if os.path.exists(aus):
os.unlink(tmp); sys.exit("%s existiert schon" % aus)
os.replace(tmp, aus)
print("%d Spieler -> %s (Dateien 0-307; vpip3: 0 eng, 1 mittel, 2 locker, None unbekannt; vpip4_kurve: 0 unbekannt)" % (len(zeilen), aus))
if __name__ == "__main__":
main()
+3
View File
@@ -60,6 +60,9 @@ class Zaehlstand:
z += self.pool_summe[c]
return out
def alle_spieler(self):
return [int(x) for x in self._pid]
def spieler(self, pid):
"""Zaehler eines Spielers: (fein {code: [6]}, mittel {code: [6]}, grob {code: [6]}) oder None; Ergebnis wird gemerkt."""
if pid in self._cache:
+22
View File
@@ -212,6 +212,22 @@ class OffenUndKalibrierung(unittest.TestCase):
self.assertIn("eine Achse allein", md)
class Typen(unittest.TestCase):
def test_vpip_klassen_und_gratis_check_der_big_blind(self):
import typen as TY
import knoten_abbild as KN
kb = ((((1 * 5 + 1) * 3 + 0) * 2 + 0) * 5 + 0) # BB nach Limp, erste Entscheidung
utg = ((((2 * 5 + 0) * 3 + 0) * 2 + 0) * 5 + 0) # UTG ungeoeffnet
fein = {kb: np.array([0, 10, 0, 0, 0, 0]), utg: np.array([60, 0, 30, 0, 0, 0])}
v, h = TY.vpip_aus_zaehlern(fein)
self.assertEqual(h, 100)
self.assertAlmostEqual(v, 0.30) # 30 Erhoehungen, die 10 Checks zaehlen nicht
self.assertEqual(TY.vpip_klasse(v, h), 2)
self.assertEqual(TY.vpip_klasse(0.1, 100), 1)
self.assertEqual(TY.vpip_klasse(0.6, 100), 3)
self.assertEqual(TY.vpip_klasse(0.1, 29), 0)
class NeueDateien(unittest.TestCase):
def test_schreibe_neu_ueberschreibt_nie(self):
with tempfile.TemporaryDirectory() as d:
@@ -249,6 +265,12 @@ class Ereignisse(unittest.TestCase):
self.assertTrue(flop_call.klasse.startswith("mitte/"))
self.assertEqual(flop_call.fach, 1)
def test_spielerkennung_ist_das_int64_bitmuster_der_zaehler(self):
h = AusgabeOhneSpielerschluessel()._hand(["fedcba9876543210", "0123456789abcdef"])
ev = EV.ereignisse_aus_handsatz(h, 0.02, 0)
self.assertEqual(ev[0].spieler, int("fedcba9876543210", 16) - (1 << 64))
self.assertEqual(ev[1].spieler, int("0123456789abcdef", 16))
def test_live_held_als_setzer(self):
h = AusgabeOhneSpielerschluessel()._hand(["", "0123456789abcdef"])
ev = EV.ereignisse_aus_handsatz(h, 0.02, 0, held=0)