@@ -88,7 +88,6 @@ impl Blueprint {
88
88
/// Build the Tree iteratively starting from the root node.
89
89
/// This function uses a stack to simulate recursion and builds the tree in a depth-first manner.
90
90
fn sample ( & mut self ) -> Sample {
91
- log:: info!( "sampling tree" ) ;
92
91
let mut tree = Tree :: empty ( ) ;
93
92
let mut partition = Partition :: new ( ) ;
94
93
let ref mut queue = Vec :: new ( ) ;
@@ -104,47 +103,39 @@ impl Blueprint {
104
103
let head = tree. at ( tail) ;
105
104
self . visit ( & head, queue, infos) ;
106
105
}
107
- println ! ( "\n {}\n " , self . profile) ;
108
- println ! ( "\n {}\n " , tree) ;
109
106
Sample ( tree, partition)
110
107
}
111
108
112
109
/// Process a node: witness it for profile and partition if necessary,
113
110
/// and add its children to the exploration queue.
111
+ /// under external sampling rules:
112
+ /// - explore ALL my options
113
+ /// - explore 1 of Chance
114
+ /// - explore 1 of Villain
114
115
fn visit ( & mut self , head : & Node , queue : & mut Vec < Branch > , infosets : & mut Partition ) {
115
- let explored = self . explore ( head) ;
116
- if head. player ( ) == self . profile . walker ( ) {
117
- infosets. witness ( head) ;
118
- }
119
- if head. player ( ) != Player :: chance ( ) {
120
- self . profile . witness ( head, & explored) ;
121
- }
122
- for ( tail, from) in explored {
123
- queue. push ( ( tail, from, head. index ( ) ) ) ;
124
- }
125
- }
126
-
127
- /// generate children for a given node
128
- /// under external sampling rules.
129
- /// explore all MY options
130
- /// but only 1 of Chance, 1 of Villain
131
- fn explore ( & self , node : & Node ) -> Vec < ( Data , Edge ) > {
132
- let children = self . children ( node) ;
133
- let walker = self . profile . walker ( ) ;
134
116
let chance = Player :: chance ( ) ;
135
- let player = node. player ( ) ;
136
- if children. is_empty ( ) {
117
+ let player = head. player ( ) ;
118
+ let walker = self . profile . walker ( ) ;
119
+ let children = self . children ( head) ;
120
+ let sample = if children. is_empty ( ) {
137
121
vec ! [ ]
138
122
} else if player == chance {
139
- self . take_any ( children, node)
140
- } else if player == walker {
141
- self . take_all ( children, node)
123
+ self . sample_any ( children, head)
142
124
} else if player != walker {
143
- self . take_one ( children, node)
125
+ self . profile . witness ( head, & children) ;
126
+ self . sample_one ( children, head)
127
+ } else if player == walker {
128
+ infosets. witness ( head) ;
129
+ self . profile . witness ( head, & children) ;
130
+ self . sample_all ( children, head)
144
131
} else {
145
132
panic ! ( "at the disco" )
133
+ } ;
134
+ for ( tail, from) in sample {
135
+ queue. push ( ( tail, from, head. index ( ) ) ) ;
146
136
}
147
137
}
138
+
148
139
fn children ( & self , node : & Node ) -> Vec < ( Data , Edge ) > {
149
140
const MAX_N_RAISE : usize = 2 ;
150
141
let ref past = node. history ( ) ;
@@ -173,14 +164,14 @@ impl Blueprint {
173
164
// external sampling
174
165
175
166
/// full exploration of my decision space Edges
176
- fn take_all ( & self , choices : Vec < ( Data , Edge ) > , _: & Node ) -> Vec < ( Data , Edge ) > {
167
+ fn sample_all ( & self , choices : Vec < ( Data , Edge ) > , _: & Node ) -> Vec < ( Data , Edge ) > {
177
168
assert ! ( choices
178
169
. iter( )
179
170
. all( |( _, edge) | matches!( edge, Edge :: Choice ( _) ) ) ) ;
180
171
choices
181
172
}
182
173
/// uniform sampling of chance Edge
183
- fn take_any ( & self , mut choices : Vec < ( Data , Edge ) > , head : & Node ) -> Vec < ( Data , Edge ) > {
174
+ fn sample_any ( & self , mut choices : Vec < ( Data , Edge ) > , head : & Node ) -> Vec < ( Data , Edge ) > {
184
175
let ref mut rng = self . profile . rng ( head) ;
185
176
let n = choices. len ( ) ;
186
177
let choice = rng. gen_range ( 0 ..n) ;
@@ -189,7 +180,7 @@ impl Blueprint {
189
180
vec ! [ chosen]
190
181
}
191
182
/// Profile-weighted sampling of opponent Edge
192
- fn take_one ( & self , mut choices : Vec < ( Data , Edge ) > , head : & Node ) -> Vec < ( Data , Edge ) > {
183
+ fn sample_one ( & self , mut choices : Vec < ( Data , Edge ) > , head : & Node ) -> Vec < ( Data , Edge ) > {
193
184
let ref mut rng = self . profile . rng ( head) ;
194
185
let policy = choices
195
186
. iter ( )
@@ -207,7 +198,7 @@ impl Blueprint {
207
198
#[ cfg( test) ]
208
199
mod tests {
209
200
use super :: * ;
210
- use crate :: mccfr:: training :: Blueprint ;
201
+ use crate :: mccfr:: minimizer :: Blueprint ;
211
202
use petgraph:: graph:: NodeIndex ;
212
203
213
204
#[ test]
0 commit comments