Skip to content

Commit b9fcfce

Browse files
committed
preparation for mccfr abstractor + renames
1 parent 4037963 commit b9fcfce

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

src/clustering/abstractor.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use crate::cards::isomorphism::Isomorphism;
22
use crate::cards::observation::Observation;
3-
// use crate::cards::observation::Observation as Equivalence;
43
use crate::cards::street::Street;
54
use crate::clustering::abstraction::Abstraction;
65
use crate::clustering::histogram::Histogram;
7-
// use crate::clustering::progress::Progress;
86
use std::collections::BTreeMap;
97

108
/// this is the output of the clustering module
@@ -22,6 +20,9 @@ impl Abstractor {
2220
let mut map = BTreeMap::default();
2321
map.extend(Self::load(Street::Turn).0);
2422
map.extend(Self::load(Street::Flop).0);
23+
// TODO
24+
// extend map with preflop
25+
// alternatively, handle lossless preflop abstractions in Self::abstraction
2526
Self(map)
2627
}
2728

@@ -43,6 +44,15 @@ impl Abstractor {
4344
}
4445
/// lookup the pre-computed abstraction for the outer observation
4546
pub fn abstraction(&self, outer: &Isomorphism) -> Abstraction {
47+
// TODO
48+
// match on street
49+
// river => compute equity on the fly**
50+
// turn | flop => lookup
51+
// preflop => isomorphism into Hole
52+
//
53+
// ** this is expensive ?
54+
// ** could implement mc_equity to not iterate over villain cards exhaustively ?
55+
// ** should check benchmarks to see how much this matters
4656
self.0
4757
.get(outer)
4858
.cloned()

src/clustering/metric.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::clustering::abstraction::Abstraction;
22
use crate::clustering::histogram::Histogram;
3-
// use crate::clustering::progress::Progress;
43
use crate::clustering::xor::Pair;
54
use std::collections::BTreeMap;
65

src/clustering/sampling.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use super::abstractor::Abstractor;
33
use crate::cards::isomorphism::Isomorphism;
44
use crate::mccfr::bucket::Bucket;
55
use crate::mccfr::bucket::Path;
6-
use crate::mccfr::data::Vertex;
76
use crate::mccfr::edge::Edge;
87
use crate::mccfr::node::Node;
98
use crate::mccfr::player::Player;
109
use crate::mccfr::profile::Profile;
10+
use crate::mccfr::spot::Spot;
1111
use crate::play::game::Game;
1212
use crate::Probability;
1313
use rand::distributions::Distribution;
@@ -35,7 +35,7 @@ impl Sampler {
3535
/// compared to chance sampling, internal sampling, or full tree sampling.
3636
///
3737
/// i think this could also be modified into a recursive CFR calcuation
38-
pub fn sample(&self, node: &Node, profile: &Profile) -> Vec<(Vertex, Edge)> {
38+
pub fn sample(&self, node: &Node, profile: &Profile) -> Vec<(Spot, Edge)> {
3939
let mut children = self.children(node);
4040
// terminal nodes have no children and we sample all possible actions for the traverser
4141
if node.player() == profile.walker() || children.is_empty() {
@@ -68,7 +68,7 @@ impl Sampler {
6868

6969
/// produce the children of a Node.
7070
/// we may need some Trainer-level references to produce children
71-
fn children(&self, node: &Node) -> Vec<(Vertex, Edge)> {
71+
fn children(&self, node: &Node) -> Vec<(Spot, Edge)> {
7272
let ref game = node.datum().game();
7373
let ref past = node.history().into_iter().collect::<Vec<&Edge>>();
7474
game.children()
@@ -79,16 +79,16 @@ impl Sampler {
7979
}
8080
/// extend a path with an Edge
8181
/// wrap the (Game, Bucket) in a Data
82-
fn explore(&self, game: Game, edge: Edge, history: &Vec<&Edge>) -> (Vertex, Edge) {
82+
fn explore(&self, game: Game, edge: Edge, history: &Vec<&Edge>) -> (Spot, Edge) {
8383
let mut history = history.clone();
8484
history.push(&edge);
8585
(self.data(game, history), edge)
8686
}
8787
/// generate a Bucket from Game
8888
/// wrap the (Game, Bucket) in a Data
89-
fn data(&self, game: Game, path: Vec<&Edge>) -> Vertex {
89+
fn data(&self, game: Game, path: Vec<&Edge>) -> Spot {
9090
let bucket = self.bucket(&game, &path);
91-
Vertex::from((game, bucket))
91+
Spot::from((game, bucket))
9292
}
9393
/// inddd
9494
fn bucket(&self, game: &Game, path: &Vec<&Edge>) -> Bucket {

src/mccfr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
pub mod bucket;
2-
pub mod data;
32
pub mod edge;
43
pub mod info;
54
pub mod memory;
65
pub mod node;
76
pub mod player;
87
pub mod profile;
8+
pub mod spot;
99
pub mod trainer;
1010
pub mod tree;

src/mccfr/node.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::bucket::Bucket;
22
use super::player::Player;
3-
use crate::mccfr::data::Vertex;
43
use crate::mccfr::edge::Edge;
4+
use crate::mccfr::spot::Spot;
55
use crate::play::continuation::Transition;
66
use crate::Utility;
77
use petgraph::graph::DiGraph;
@@ -13,11 +13,11 @@ use std::ptr::NonNull;
1313
pub struct Node {
1414
graph: NonNull<DiGraph<Self, Edge>>,
1515
index: NodeIndex,
16-
datum: Vertex,
16+
datum: Spot,
1717
}
1818

19-
impl From<(NodeIndex, NonNull<DiGraph<Node, Edge>>, Vertex)> for Node {
20-
fn from((index, graph, datum): (NodeIndex, NonNull<DiGraph<Node, Edge>>, Vertex)) -> Self {
19+
impl From<(NodeIndex, NonNull<DiGraph<Node, Edge>>, Spot)> for Node {
20+
fn from((index, graph, datum): (NodeIndex, NonNull<DiGraph<Node, Edge>>, Spot)) -> Self {
2121
Self {
2222
index,
2323
graph,
@@ -28,7 +28,7 @@ impl From<(NodeIndex, NonNull<DiGraph<Node, Edge>>, Vertex)> for Node {
2828

2929
/// collection of these three is what you would get in a Node, which may be too restrictive for a lot of the use so we'll se
3030
impl Node {
31-
pub fn datum(&self) -> &Vertex {
31+
pub fn datum(&self) -> &Spot {
3232
&self.datum
3333
}
3434
pub fn index(&self) -> NodeIndex {

src/mccfr/data.rs renamed to src/mccfr/spot.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ use crate::mccfr::player::Player;
44
use crate::play::continuation::Transition;
55
use crate::play::game::Game;
66

7-
pub struct Vertex {
7+
pub struct Spot {
88
game: Game,
99
bucket: Bucket,
1010
}
1111

12-
impl From<(Game, Bucket)> for Vertex {
12+
impl From<(Game, Bucket)> for Spot {
1313
fn from((game, bucket): (Game, Bucket)) -> Self {
1414
Self { game, bucket }
1515
}
1616
}
1717

18-
impl Vertex {
18+
impl Spot {
1919
pub fn game(&self) -> &Game {
2020
&self.game
2121
}

src/mccfr/trainer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use super::data::Vertex;
21
use super::edge::Edge;
32
use super::node::Node;
43
use super::player::Player;
54
use super::profile::Profile;
5+
use super::spot::Spot;
66
use super::tree::Tree;
77
use crate::clustering::sampling::Sampler;
88
use petgraph::graph::NodeIndex;
@@ -72,7 +72,7 @@ impl Explorer {
7272
/// recursively build the Tree from the given Node, according to the distribution defined by Profile.
7373
/// we assert the Tree property of every non-root Node having exactly one parent Edge
7474
/// we construct the appropriate references in self.attach() to ensure safety.
75-
fn dfs(&mut self, head: Vertex, edge: Edge, root: NodeIndex) {
75+
fn dfs(&mut self, head: Spot, edge: Edge, root: NodeIndex) {
7676
let head = self.witness(head);
7777
let head = self.tree.graph_mut().add_node(head);
7878
let edge = self.tree.graph_mut().add_edge(root, head, edge);
@@ -87,7 +87,7 @@ impl Explorer {
8787
/// attach a Node to the Tree,
8888
/// update the Profile to witness the new Node
8989
/// update the InfoPartition to witness the new Node.
90-
fn witness(&mut self, data: Vertex) -> Node {
90+
fn witness(&mut self, data: Spot) -> Node {
9191
let player = data.player().clone();
9292
let graph = self.tree.graph_ptr();
9393
let count = self.tree.graph_ref().node_count();
@@ -106,13 +106,13 @@ impl Explorer {
106106
/// Game::root() -> Observation -> Abstraction
107107
///
108108
/// NOT deterministic, hole cards are thread_rng
109-
fn root(&self) -> Vertex {
109+
fn root(&self) -> Spot {
110110
use crate::mccfr::bucket::Bucket;
111111
use crate::play::game::Game;
112112
let node = Game::root();
113113
let path = self.sampler.path_abstraction(&Vec::new());
114114
let abstraction = self.sampler.card_abstraction(&node);
115115
let bucket = Bucket::from((path, abstraction));
116-
Vertex::from((node, bucket))
116+
Spot::from((node, bucket))
117117
}
118118
}

0 commit comments

Comments
 (0)