Skip to content

Commit

Permalink
Allow analysis data output even when no play selection values
Browse files Browse the repository at this point in the history
  • Loading branch information
lightvector committed Jul 28, 2024
1 parent 8c91857 commit 827f755
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions cpp/search/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ struct Search {

// LCB helpers
void getSelfUtilityLCBAndRadius(const SearchNode& parent, const SearchNode* child, int64_t edgeVisits, Loc moveLoc, double& lcbBuf, double& radiusBuf) const;
void getSelfUtilityLCBAndRadiusZeroVisits(double& lcbBuf, double& radiusBuf) const;

//----------------------------------------------------------------------------------------
// Mirror handling logic
Expand Down
8 changes: 8 additions & 0 deletions cpp/search/searchhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ double Search::interpolateEarly(double halflife, double earlyValue, double value
return value + (earlyValue - value) * pow(0.5, halflives);
}

void Search::getSelfUtilityLCBAndRadiusZeroVisits(double& lcbBuf, double& radiusBuf) const {
// Max radius of the entire utility range
double utilityRangeRadius = searchParams.winLossUtilityFactor + searchParams.staticScoreUtilityFactor + searchParams.dynamicScoreUtilityFactor;
radiusBuf = 2.0 * utilityRangeRadius * searchParams.lcbStdevs;
lcbBuf = -radiusBuf;
return;
}

void Search::getSelfUtilityLCBAndRadius(const SearchNode& parent, const SearchNode* child, int64_t edgeVisits, Loc moveLoc, double& lcbBuf, double& radiusBuf) const {
int64_t childVisits = child->stats.visits.load(std::memory_order_acquire);
double scoreMeanAvg = child->stats.scoreMeanAvg.load(std::memory_order_acquire);
Expand Down
20 changes: 16 additions & 4 deletions cpp/search/searchresults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,22 @@ void Search::getAnalysisData(
return;
assert(numChildren <= NNPos::MAX_NN_POLICY_SIZE);

bool alwaysComputeLcb = true;
bool success = getPlaySelectionValues(node, scratchLocs, scratchValues, NULL, 1.0, false, alwaysComputeLcb, false, lcbBuf, radiusBuf);
if(!success)
return;
const bool alwaysComputeLcb = true;
bool gotPlaySelectionValues = getPlaySelectionValues(node, scratchLocs, scratchValues, NULL, 1.0, false, alwaysComputeLcb, false, lcbBuf, radiusBuf);

// No play selection values - then fill with values consistent with all 0 visits.
// We want it to be possible to get analysis data even when all visits are weightless.
if(!gotPlaySelectionValues) {
for(int i = 0; i<numChildren; i++) {
scratchLocs.push_back(childrenMoveLocs[i]);
scratchValues.push_back(0.0);
}
double lcbBufValue;
double radiusBufValue;
getSelfUtilityLCBAndRadiusZeroVisits(lcbBufValue,radiusBufValue);
std::fill(lcbBuf,lcbBuf+numChildren,lcbBufValue);
std::fill(radiusBuf,radiusBuf+numChildren,radiusBufValue);
}

const NNOutput* nnOutput = node.getNNOutput();
const float* policyProbsFromNN = nnOutput->getPolicyProbsMaybeNoised();
Expand Down

0 comments on commit 827f755

Please sign in to comment.