"""Pure aggregation of the score: spot losses -> bb per 100 hands per area, strength S, paired difference with a bootstrap interval. A spot result is a dict with `stratum` ("STREET|potart|art"), `id` and the loss values in chips. The loss of a stratum is the mean over its spots of the evaluated set; its weight is `je100[stratum]` = decisions of that stratum per 100 hands; so one area contributes `je100 * mean_loss_bb` bb per 100 hands. Strata without a spot are not measured and are listed, never counted as zero loss. """ import random CHIPS_PER_BB = 100.0 def area_street(stratum): return stratum.split("|")[0] def area_street_pot(stratum): return "|".join(stratum.split("|")[:2]) def area_all(stratum): return "gesamt" def weighted_bb100(spots, je100, value, area=area_all): """-> ({area: bb/100}, [strata of `je100` without a spot]); `value(spot)` in chips.""" by_stratum = {} for s in spots: by_stratum.setdefault(s["stratum"], []).append(value(s)) out = {} for st, vals in by_stratum.items(): a = area(st) out[a] = out.get(a, 0.0) + je100[st] * (sum(vals) / len(vals)) / CHIPS_PER_BB return out, sorted(set(je100) - set(by_stratum)) def strength(v, v0): """S = 100 * (1 - V / V0): 100 = no loss against the perfect opponent, 0 = as much loss as the calling station.""" return None if not v0 else 100.0 * (1.0 - v / v0) def bootstrap_diff(spots_a, spots_b, je100, value, draws=1000, seed=1): """Paired difference (a - b) of the total bb/100 on the SAME spots (matched by id), with the 2.5 / 97.5 percentile of a bootstrap over the spots within each stratum. Information about the sampling of the spot set only: it says nothing about the solver.""" b_by_id = {s["id"]: s for s in spots_b} pairs = [(s, b_by_id[s["id"]]) for s in spots_a if s["id"] in b_by_id] strata = {} for a, b in pairs: strata.setdefault(a["stratum"], []).append(value(a) - value(b)) point = sum(je100[st] * sum(d) / len(d) for st, d in strata.items()) / CHIPS_PER_BB rng = random.Random(seed) res = [] for _ in range(draws): tot = 0.0 for st, d in strata.items(): tot += je100[st] * sum(rng.choice(d) for _ in d) / len(d) res.append(tot / CHIPS_PER_BB) res.sort() return point, (res[int(0.025 * draws)], res[min(draws - 1, int(0.975 * draws))]), len(pairs)