From e3168cfafdfc27ff732b1f2abcc0929e259bfbf9 Mon Sep 17 00:00:00 2001 From: Alexis Olson Date: Tue, 10 Sep 2019 20:00:07 -0500 Subject: [PATCH 1/5] Add PR925 logic No flag. --- src/mcts/search.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mcts/search.cc b/src/mcts/search.cc index 28e93994cf..ef82cf17cb 100644 --- a/src/mcts/search.cc +++ b/src/mcts/search.cc @@ -260,7 +260,9 @@ std::vector Search::GetVerboseStats(Node* node, << ") "; oss << "(Q+U: " << std::setw(8) << std::setprecision(5) - << edge.GetQ(fpu) + edge.GetU(U_coeff) << ") "; + << (params_.GetLogitQEnabled() ? FastLogit(edge.GetQ(0)) : + edge.GetQ(fpu)) + edge.GetU(U_coeff) + << ") "; oss << "(V: "; optional v; @@ -1029,7 +1031,8 @@ SearchWorker::NodeToProcess SearchWorker::PickNodeToExtend( } } - const float score = child.GetU(puct_mult) + Q; + const float Q0 = child.GetQ(0); + const float score = child.GetU(puct_mult) + (Q - Q0) + FastLogit(0.99999999 * Q0); if (score > best) { second_best = best; second_best_edge = best_edge; From b7a741e03790ef15b6213ecc1361f198c278f091 Mon Sep 17 00:00:00 2001 From: Alexis Olson Date: Tue, 10 Sep 2019 20:01:42 -0500 Subject: [PATCH 2/5] Add FastLogit --- src/utils/fastmath.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/fastmath.h b/src/utils/fastmath.h index 795d48bb53..20bd8f2d7f 100644 --- a/src/utils/fastmath.h +++ b/src/utils/fastmath.h @@ -65,4 +65,8 @@ inline float FastLog(const float a) { return 0.6931471805599453f * FastLog2(a); } +// Fast logit for more readable code. +inline float FastLogit(const float a) { + return 0.5 * FastLog((1.0f + a) / (1.0f - a)); + } // namespace lczero From 9c670352f6e3e0efd1e6b8ecd38137e2b6d3f82a Mon Sep 17 00:00:00 2001 From: Alexis Olson Date: Tue, 10 Sep 2019 20:03:42 -0500 Subject: [PATCH 3/5] Add PR925 logic --- src/mcts/node.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mcts/node.h b/src/mcts/node.h index 87ad7ad63d..2636e01132 100644 --- a/src/mcts/node.h +++ b/src/mcts/node.h @@ -37,6 +37,7 @@ #include "chess/position.h" #include "neural/encoder.h" #include "neural/writer.h" +#include "utils/fastmath.h" #include "utils/mutex.h" namespace lczero { @@ -521,7 +522,7 @@ class EdgeAndNode { int GetVisitsToReachU(float target_score, float numerator, float default_q) const { - const auto q = GetQ(default_q); + const auto q = FastLogit(GetQ(default_q)); if (q >= target_score) return std::numeric_limits::max(); const auto n1 = GetNStarted() + 1; return std::max( From 334f42b0333c214aff58403216736692c68aa793 Mon Sep 17 00:00:00 2001 From: Alexis Olson Date: Tue, 10 Sep 2019 20:07:39 -0500 Subject: [PATCH 4/5] Remove flag switch --- src/mcts/search.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mcts/search.cc b/src/mcts/search.cc index ef82cf17cb..9b8ee12ab5 100644 --- a/src/mcts/search.cc +++ b/src/mcts/search.cc @@ -260,8 +260,7 @@ std::vector Search::GetVerboseStats(Node* node, << ") "; oss << "(Q+U: " << std::setw(8) << std::setprecision(5) - << (params_.GetLogitQEnabled() ? FastLogit(edge.GetQ(0)) : - edge.GetQ(fpu)) + edge.GetU(U_coeff) + << FastLogit(edge.GetQ(0)) + edge.GetU(U_coeff) << ") "; oss << "(V: "; From f35c4c6cf815ada46ea05e16182c791e31694f9e Mon Sep 17 00:00:00 2001 From: Alexis Olson Date: Tue, 10 Sep 2019 20:19:41 -0500 Subject: [PATCH 5/5] Add missing bracket --- src/utils/fastmath.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/fastmath.h b/src/utils/fastmath.h index 20bd8f2d7f..b8f77e30dd 100644 --- a/src/utils/fastmath.h +++ b/src/utils/fastmath.h @@ -68,5 +68,6 @@ inline float FastLog(const float a) { // Fast logit for more readable code. inline float FastLogit(const float a) { return 0.5 * FastLog((1.0f + a) / (1.0f - a)); +} } // namespace lczero