Skip to main content

ReferenceEvaluator

Struct ReferenceEvaluator 

Source
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>

Source

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.

Source

pub fn evaluate<F>(&self, strategy: F) -> Result<StrategyQuality, QualityError>
where F: FnMut(usize) -> Vec<Vec<f64>>,

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§

Source§

impl Debug for ReferenceEvaluator<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

A summary: board, range sizes, decisions, and joint mass.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.