pub struct ReferenceEvaluator<'a> { /* private fields */ }Expand description
An independent, exact evaluator of strategy quality for small trees.
It shares no traversal code with Trainer, so it can check
the trainer’s results. Showdown comparisons are cached once per evaluator.
Time and memory grow with the tree size times the number of private-hand
pairs, so use it for small trees: tests, fixtures, and quality benchmarks.
§Examples
use native_solver::solver::quality::ReferenceEvaluator;
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 config = GameConfig::new(board.clone(), Chips::whole(100), Chips::whole(100)).with_bet_sizes([1.0]);
let ranges = ["AA,KQs", "QQ,JJ"].map(|r| r.parse::<Range>().unwrap().combos(dead));
let mut trainer = Trainer::new(build_tree(&config)?, ranges, TrainerOptions::default())?;
trainer.train(200);
// Check the trainer's exploitability against the independent reference.
let game = trainer.game();
let reference = ReferenceEvaluator::new(game.tree(), &board, Player::ALL.map(|p| game.combos(p)))?;
let quality = reference.evaluate(|node| trainer.average_strategy(node))?;
assert!((quality.exploitability - trainer.exploitability().total).abs() < 1e-9);Implementations§
Source§impl<'a> ReferenceEvaluator<'a>
impl<'a> ReferenceEvaluator<'a>
Sourcepub fn new(
root: &'a Node,
initial_board: &'a [Card],
combos: [&'a [Combo]; 2],
) -> Result<Self, QualityError>
pub fn new( root: &'a Node, initial_board: &'a [Card], combos: [&'a [Combo]; 2], ) -> Result<Self, QualityError>
Validate the board, ranges, and complete unreduced tree.
Finite nonnegative weights need not sum to one or be at most one. Board-blocked combos are accepted but excluded, as are conflicting private pairs and zero-weight combos. Decision IDs must be unique public histories. Terminal payoffs and action labels define the supplied game; this checks structural integrity, not whether the betting sequence follows NLHE rules.
§Errors
Returns a QualityError for a board that is not 3–5 distinct cards,
duplicate or reversed combos, a combo holding one card twice,
nonfinite or negative weights, zero or nonfinite legal joint mass, a
malformed tree, or a suit-reduced chance node.
Sourcepub fn evaluate<F>(&self, strategy: F) -> Result<StrategyQuality, QualityError>
pub fn evaluate<F>(&self, strategy: F) -> Result<StrategyQuality, QualityError>
Measures the profile given by strategy: its EVs and exploitability.
strategy is called once per decision node and returns
[action][combo] probabilities in the input range order, for example
|id| trainer.average_strategy(id).
Every column, including unreachable/blocked columns, must have finite probabilities in [0, 1] summing to one within 1e-10. Accepted roundoff is normalized to exactly one. The callback is not consulted during BR search, and no trainer state or regret tables are read or modified.
§Errors
Returns QualityError::InvalidStrategy for a strategy with the
wrong shape or a column that is not a distribution, and
QualityError::NonFiniteResult if evaluation overflows.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ReferenceEvaluator<'a>
impl<'a> RefUnwindSafe for ReferenceEvaluator<'a>
impl<'a> Send for ReferenceEvaluator<'a>
impl<'a> Sync for ReferenceEvaluator<'a>
impl<'a> Unpin for ReferenceEvaluator<'a>
impl<'a> UnsafeUnpin for ReferenceEvaluator<'a>
impl<'a> UnwindSafe for ReferenceEvaluator<'a>
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