Files
pokerfreak/arena/exploit/tests/curve.rs
T

99 lines
3.8 KiB
Rust

//! The key deliverable: exploitability of a heads-up blueprint falls as the blueprint trains
//! (1k -> 30k -> 300k iterations), measured by trained best responses (duplicate + AIVAT) and,
//! on the same targets, by LBR. Prints the table used in RESULTS.md.
//!
//! Two exploiters: `same` (target's buckets and menu) and `fine` (hand-strength-refined buckets
//! and a bigger bet menu, translated into the target's menu).
use bench::bp::CoarseBucketer;
use exploit::abr::{AbrConfig, Buck, Exploiter, Extract};
use exploit::buckets::Refined;
use exploit::eval::evaluate;
use exploit::game::ActionSpace;
use exploit::{blueprint_target, lbr, train_blueprint};
use nlhe::abstraction::{BetSizing, Menu};
use nlhe::GameConfig;
use std::sync::Arc;
use std::time::Instant;
fn env(name: &str, d: u64) -> u64 {
std::env::var(name)
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(d)
}
fn fine_menu() -> BetSizing {
let t = [Menu::new(&[0.33, 0.66, 1.0, 1.5], true)];
BetSizing::new([&t, &t, &t, &t], [3, 3, 3, 3])
}
#[test]
fn exploitability_decreases_with_blueprint_training() {
let cfg = GameConfig::new(2);
let b: Buck = Arc::new(CoarseBucketer);
let fine_b: Buck = Arc::new(Refined::new(b.clone(), 12));
let tiny: Arc<dyn ActionSpace> = Arc::new(BetSizing::tiny());
let big: Arc<dyn ActionSpace> = Arc::new(fine_menu());
let (abr_iters, deals, lbr_deals) = (
env("ABR_ITERS", 150_000),
env("EVAL_DEALS", 15_000),
env("LBR_DEALS", 300),
);
println!(
"{:>8} | {:>17} | {:>17} | {:>17} | {:>17}",
"bp iters", "ABR same", "ABR fine", "strong LBR", "weak LBR"
);
let mut rows = vec![];
for bp_iters in [1_000u64, 30_000, 300_000] {
let store = train_blueprint(2, bp_iters, 11);
let (target, pol) = blueprint_target("toy", store, b.clone(), BetSizing::tiny());
let mut res = vec![];
for (space, lb, iters) in [
(tiny.clone(), b.clone(), abr_iters),
(big.clone(), fine_b.clone(), env("FINE_ITERS", 50_000)),
] {
let t = Instant::now();
let mut c = AbrConfig::new(cfg, vec![0, 1], iters, 5);
c.capacity = 1 << 24;
c.max_infosets = 1 << 21;
let ex = Exploiter::new(c, space, tiny.clone(), target.clone(), b.clone(), lb);
ex.train(|_, _, _| {});
let secs = t.elapsed().as_secs_f32();
let ep = ex.policy("abr", Extract::Average);
let r = evaluate(&cfg, ep.clone(), pol.clone(), &[0, 1], deals, 1234);
eprintln!(
" abr {secs:.1}s, {} infosets, miss rate {:.3}",
ex.store.infosets(),
ep.miss_rate()
);
res.push(r.avg);
}
let l = lbr::run(&cfg, pol, lbr_deals, 300, 77);
println!(
"{bp_iters:>8} | {:>17} | {:>17} | {:>17} | {:>17}",
res[0].to_string(),
res[1].to_string(),
l.strong.lbr.to_string(),
l.weak.lbr.to_string()
);
rows.push((res, l));
}
// Abstract-game exploitability (the exploiter sees what the target sees) falls as the
// blueprint converges. The fine exploiter additionally exploits the target's *abstraction*
// (9 hand-category buckets), which more training cannot remove, so it is not monotone.
let a: Vec<f64> = rows.iter().map(|r| r.0[0].mbb).collect();
assert!(
a[0] > a[1] && a[1] > a[2],
"exploitability must fall as the target trains: {a:?}"
);
for (e, l) in &rows {
let best = e[0].mbb.max(e[1].mbb);
assert!(
best + 1.96 * e[0].se >= l.best_mbb() - 1.96 * l.strong.lbr.se,
"exploiter {best} < LBR {}",
l.best_mbb()
);
}
}