make weighted probabilities depending on node's children children count

This commit is contained in:
Matthieu Pignolet 2024-06-06 14:15:04 +04:00
parent e3f5437ed8
commit 16e9f11a3d

View file

@ -109,11 +109,11 @@ impl<'a> Trie<'a> {
while current_node.child_nodes.len() != 0 { while current_node.child_nodes.len() != 0 {
// We need to choose a random child based on weights // We need to choose a random child based on weights
let weighted = WeightedIndex::new(current_node.child_nodes.iter().map(|(_, node)| { let weighted = WeightedIndex::new(current_node.child_nodes.iter().map(|(_, node)| {
node.child_count / node node.child_count / (node
.child_nodes .child_nodes
.iter() .iter()
.map(|(_, b)| b.child_count) .map(|(_, b)| b.child_count)
.sum::<u64>() .sum::<u64>() + 1)
})) }))
.expect("distribution creation should be valid"); .expect("distribution creation should be valid");