Skip to content

Commit

Permalink
Small optimization to UCT.
Browse files Browse the repository at this point in the history
Calculate the numerator in the P-UCT formula before the main loop.
  • Loading branch information
gcp committed Nov 13, 2017
1 parent 3272d04 commit e873dc2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/UCTNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ UCTNode* UCTNode::uct_select_child(int color) {
}
childcount++;
}
float numerator = std::sqrt((double)parentvisits);

childcount = 0;
child = m_firstchild;
Expand Down Expand Up @@ -383,7 +384,7 @@ UCTNode* UCTNode::uct_select_child(int color) {
float winrate = child->get_eval(color);
float psa = child->get_score();
float denom = 1.0f + child->get_visits();
float puct = cfg_puct * psa * ((float)std::sqrt((double)parentvisits) / denom);
float puct = cfg_puct * psa * (numerator / denom);
float value = winrate + puct;
assert(value > -1000.0f);

Expand Down

0 comments on commit e873dc2

Please sign in to comment.