pub struct Trainer { /* private fields */ }Expand description
Trains a strategy for one game with counterfactual regret minimization.
A trainer owns the regret and strategy tables. The game itself
(SolverGame) is immutable and shared through Trainer::game, so a
Policy snapshot can be read while training continues.
§Examples
use native_solver::{build_tree, Card, CardSet, Chips, GameConfig, Player, Range, Trainer, TrainerOptions};
let board = ["Ks", "Th", "7s", "4d", "2s"]
.iter()
.map(|card| card.parse())
.collect::<Result<Vec<Card>, _>>()?;
let dead = CardSet::from_cards(&board);
let oop = "AA,KQs".parse::<Range>()?.combos(dead);
let ip = "QQ,JJ".parse::<Range>()?.combos(dead);
let config = GameConfig::new(board, Chips::whole(100), Chips::whole(100)).with_bet_sizes([1.0]);
let mut trainer = Trainer::new(build_tree(&config)?, [oop, ip], TrainerOptions::default())?;
trainer.train(200);
assert_eq!(trainer.iterations_completed(), 200);
// Node 0 is OOP's first decision: one row per action, one column per OOP combo.
let strategy = trainer.average_strategy(0);
assert_eq!(strategy[0].len(), trainer.game().combos(Player::Oop).len());
// How much a best response could still gain, in chips.
assert!(trainer.exploitability().total < 1.0);Implementations§
Source§impl Trainer
impl Trainer
Sourcepub fn new(
tree: Tree,
combos: [Vec<Combo>; 2],
options: TrainerOptions,
) -> Result<Self, TrainerError>
pub fn new( tree: Tree, combos: [Vec<Combo>; 2], options: TrainerOptions, ) -> Result<Self, TrainerError>
Builds a trainer for tree and both players’ combos.
The combo order is kept and is the combo axis of every per-combo result.
options selects the update rule, the update order (fixed for this
trainer’s lifetime; an alternating iteration is an OOP pass followed by an
IP pass), and per-street card abstraction.
Trees with grouped chance cards (suit isomorphism) need ranges closed
under every suit swap that fixes the board, with equal weights for
swapped combos; flop and turn buckets need the swapped combos to exist.
Ranges from Range::combos satisfy both when
dead is exactly the tree’s board.
§Errors
Returns a TrainerError if the tree’s board is illegal, the tree
does not continue from it or is malformed, a range is empty or holds
invalid, repeated, or board-blocked combos, no deal is possible, an
abstraction asks for zero buckets, or a range is not suit-symmetric as
required above.
Sourcepub fn algorithm(&self) -> SolverAlgorithm
pub fn algorithm(&self) -> SolverAlgorithm
The fixed update policy selected at construction.
Sourcepub fn update_schedule(&self) -> UpdateSchedule
pub fn update_schedule(&self) -> UpdateSchedule
The fixed player-update order selected at construction.
Sourcepub fn iterations_completed(&self) -> u64
pub fn iterations_completed(&self) -> u64
Iterations completed across all calls to train.
An alternating iteration counts once, though it makes two passes. DCFR uses this count as its discounting clock.
Sourcepub fn train(&mut self, iterations: u32) -> [f64; 2]
pub fn train(&mut self, iterations: u32) -> [f64; 2]
Runs iterations more training iterations.
Returns the root [OOP, IP] raw range-weighted values under the last
iteration’s current strategy. They are a progress signal, not EVs, and say
nothing about convergence; use exploitability for
that and average_strategy for the result. With
alternating updates the values come from the final IP pass.
§Panics
Panics if the total iteration count would overflow u64.
Sourcepub fn game(&self) -> &Arc<SolverGame> ⓘ
pub fn game(&self) -> &Arc<SolverGame> ⓘ
The shared, immutable game definition.
Sourcepub fn evaluate(&self) -> Evaluation
pub fn evaluate(&self) -> Evaluation
SolverGame::evaluate under the current average strategy.
Sourcepub fn exploitability(&self) -> Exploitability
pub fn exploitability(&self) -> Exploitability
SolverGame::exploitability under the current average strategy.
Sourcepub fn average_strategy(&self, node_id: usize) -> Vec<Vec<f64>>
pub fn average_strategy(&self, node_id: usize) -> Vec<Vec<f64>>
The trained average strategy for one decision node, as
[action][combo] (see SolverGame::average_strategy).
§Panics
Panics if node_id is not below SolverGame::num_decision_nodes.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Trainer
impl Freeze for Trainerwhere
*const ArcInner<SolverGame> is !null: Freeze,
PhantomData<ArcInner<SolverGame>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Mutex<NodeData>>: Freeze,
impl Move for Trainer
impl RefUnwindSafe for Trainer
impl Send for Trainer
impl Sync for Trainer
impl Unpin for Trainer
impl UnsafeUnpin for Trainerwhere
*const ArcInner<SolverGame> is !null: UnsafeUnpin,
PhantomData<ArcInner<SolverGame>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Mutex<NodeData>>: UnsafeUnpin,
impl UnwindSafe for Trainer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more