Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PR925 logic #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mcts/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<int>::max();
const auto n1 = GetNStarted() + 1;
return std::max(
Expand Down
6 changes: 4 additions & 2 deletions src/mcts/search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ std::vector<std::string> Search::GetVerboseStats(Node* node,
<< ") ";

oss << "(Q+U: " << std::setw(8) << std::setprecision(5)
<< edge.GetQ(fpu) + edge.GetU(U_coeff) << ") ";
<< FastLogit(edge.GetQ(0)) + edge.GetU(U_coeff)
<< ") ";

oss << "(V: ";
optional<float> v;
Expand Down Expand Up @@ -1029,7 +1030,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;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/fastmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ 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