Monte Carlo tree search using UCT. More...
#include <SgUctSearch.h>
Classes | |
class | Thread |
Public Member Functions | |
SgUctSearch (SgUctThreadStateFactory *threadStateFactory, int moveRange=0) | |
Constructor. | |
virtual | ~SgUctSearch () |
void | SetThreadStateFactory (SgUctThreadStateFactory *factory) |
SgUctThreadState & | ThreadState (int i) const |
Get state of one of the threads. | |
bool | ThreadsCreated () const |
Check if threads are already created. | |
void | CreateThreads () |
Create threads. | |
Pure virtual functions | |
virtual std::string | MoveString (SgMove move) const =0 |
Convert move to string (game dependent). | |
virtual SgUctValue | UnknownEval () const =0 |
Evaluation value to use if evaluation is unknown. | |
Virtual functions | |
virtual void | OnSearchIteration (SgUctValue gameNumber, unsigned int threadId, const SgUctGameInfo &info) |
Hook function that will be called by Search() after each game. | |
virtual void | OnStartSearch () |
Hook function that will be called by StartSearch(). | |
virtual void | OnEndSearch () |
Hook function that will be called when search completes. | |
virtual void | OnThreadStartSearch (SgUctThreadState &state) |
virtual void | OnThreadEndSearch (SgUctThreadState &state) |
virtual SgUctValue | GamesPlayed () const |
Search functions | |
void | GenerateAllMoves (std::vector< SgUctMoveInfo > &moves) |
Get a list of all generated moves. | |
void | PlayGame () |
Play a single game. | |
void | StartSearch (const std::vector< SgMove > &rootFilter=std::vector< SgMove >(), SgUctTree *initTree=0) |
Start search. | |
void | EndSearch () |
SgUctValue | Search (SgUctValue maxGames, double maxTime, std::vector< SgMove > &sequence, const std::vector< SgMove > &rootFilter=std::vector< SgMove >(), SgUctTree *initTree=0, SgUctEarlyAbortParam *earlyAbort=0) |
Calls StartSearch() and then PlayGame() in a loop. | |
SgPoint | SearchOnePly (SgUctValue maxGames, double maxTime, SgUctValue &value) |
Do a one-ply Monte-Carlo search instead of the UCT search. | |
const SgUctNode * | FindBestChild (const SgUctNode &node, const std::vector< SgMove > *excludeMoves=0) const |
Find child node with best move. | |
void | FindBestSequence (std::vector< SgMove > &sequence) const |
Extract sequence of best moves from root node. | |
SgUctValue | GetBound (bool useRave, const SgUctNode &node, const SgUctNode &child) const |
Return the bound of a move. | |
Search data | |
const SgUctGameInfo & | LastGameInfo () const |
Info for last game. | |
std::string | LastGameSummaryLine () const |
One-line summary text for last game. | |
bool | WasEarlyAbort () const |
See parameter earlyAbort in Search(). | |
const SgUctTree & | Tree () const |
SgUctTree & | GetTempTree () |
Get temporary tree. | |
Parameters | |
float | BiasTermConstant () const |
Constant c in the bias term. | |
void | SetBiasTermConstant (float biasTermConstant) |
See BiasTermConstant(). | |
std::vector< SgUctValue > | KnowledgeThreshold () const |
Points at which to recompute children. | |
void | SetKnowledgeThreshold (const std::vector< SgUctValue > &counts) |
See KnowledgeThreshold(). | |
std::size_t | MaxNodes () const |
Maximum number of nodes in the tree. | |
void | SetMaxNodes (std::size_t maxNodes) |
See MaxNodes(). | |
unsigned int | NumberThreads () const |
The number of threads to use during the search. | |
void | SetNumberThreads (unsigned int n) |
See SetNumberThreads(). | |
bool | LockFree () const |
Lock-free usage of multi-threaded search. | |
void | SetLockFree (bool enable) |
See LockFree(). | |
int | RandomizeRaveFrequency () const |
See SetRandomizeRaveFrequency(). | |
void | SetRandomizeRaveFrequency (int frequency) |
Randomly turns off rave with given frequency - once in every frequency child selections. | |
bool | RaveCheckSame () const |
Don't update RAVE value if opponent played the same move first. | |
void | SetRaveCheckSame (bool enable) |
See RaveCheckSame(). | |
SgUctValue | FirstPlayUrgency () const |
First play urgency. | |
void | SetFirstPlayUrgency (SgUctValue firstPlayUrgency) |
See FirstPlayUrgency(). | |
bool | LogGames () const |
Log one-line summary for each game during Search() to a file. | |
void | SetLogGames (bool enable) |
See LogGames(). | |
std::size_t | MaxGameLength () const |
Maximum game length. | |
void | SetMaxGameLength (std::size_t maxGameLength) |
See MaxGameLength(). | |
SgUctValue | ExpandThreshold () const |
Required number of simulations to expand a node in the tree. | |
void | SetExpandThreshold (SgUctValue expandThreshold) |
See ExpandThreshold(). | |
std::size_t | NumberPlayouts () const |
The number of playouts per simulated game. | |
void | SetNumberPlayouts (std::size_t n) |
bool | Rave () const |
Use the RAVE algorithm (Rapid Action Value Estimation). | |
void | SetRave (bool enable) |
See Rave(). | |
SgUctMoveSelect | MoveSelect () const |
See SgUctMoveSelect. | |
void | SetMoveSelect (SgUctMoveSelect moveSelect) |
See SgUctMoveSelect. | |
float | RaveWeightInitial () const |
See Estimator weights in SgUctSearch. | |
void | SetRaveWeightInitial (float value) |
See Estimator weights in SgUctSearch. | |
float | RaveWeightFinal () const |
See Estimator weights in SgUctSearch. | |
void | SetRaveWeightFinal (float value) |
See Estimator weights in SgUctSearch. | |
bool | WeightRaveUpdates () const |
Weight RAVE updates. | |
void | SetWeightRaveUpdates (bool enable) |
See WeightRaveUpdates(). | |
bool | VirtualLoss () const |
Whether search uses virtual loss. | |
void | SetVirtualLoss (bool enable) |
See VirtualLoss(). | |
bool | PruneFullTree () const |
Prune nodes with low counts if tree is full. | |
void | SetPruneFullTree (bool enable) |
See PruneFullTree(). | |
SgUctValue | PruneMinCount () const |
See PruneFullTree(). | |
void | SetPruneMinCount (SgUctValue n) |
See PruneFullTree(). | |
bool | CheckFloatPrecision () const |
Terminate the search if the counts can no longer be represented precisely by SgUctValue. | |
void | SetCheckFloatPrecision (bool enable) |
See CheckFloatPrecision(). | |
void | SetMpiSynchronizer (const SgMpiSynchronizerHandle &synchronizerHandle) |
SgMpiSynchronizerHandle | MpiSynchronizer () |
const SgMpiSynchronizerHandle | MpiSynchronizer () const |
Statistics | |
const SgUctSearchStat & | Statistics () const |
void | WriteStatistics (std::ostream &out) const |
Static Public Member Functions | |
static SgUctValue | InverseEval (SgUctValue eval) |
static SgUctValue | InverseEstimate (SgUctValue eval) |
Private Types | |
typedef boost::recursive_mutex::scoped_lock | GlobalLock |
Private Member Functions | |
void | ApplyRootFilter (std::vector< SgUctMoveInfo > &moves) |
void | PropagateProvenStatus (const vector< const SgUctNode * > &nodes) |
Backs up proven information. | |
bool | CheckAbortSearch (SgUctThreadState &state) |
bool | CheckEarlyAbort () const |
bool | CheckCountAbort (SgUctThreadState &state, SgUctValue remainingGames) const |
void | Debug (const SgUctThreadState &state, const std::string &textLine) |
Write a debugging line of text from within a thread. | |
void | DeleteThreads () |
void | ExpandNode (SgUctThreadState &state, const SgUctNode &node) |
Expand a node. | |
void | CreateChildren (SgUctThreadState &state, const SgUctNode &node, bool deleteChildTrees) |
Creates the children with the given moves and merges with existing children in the tree. | |
SgUctValue | GetBound (bool useRave, SgUctValue logPosCount, const SgUctNode &child) const |
SgUctValue | GetValueEstimate (bool useRave, const SgUctNode &child) const |
SgUctValue | GetValueEstimateRave (const SgUctNode &child) const |
Optimized version of GetValueEstimate() if RAVE and not other estimators are used. | |
SgUctValue | Log (SgUctValue x) const |
bool | NeedToComputeKnowledge (const SgUctNode *current) |
void | PlayGame (SgUctThreadState &state, GlobalLock *lock) |
bool | PlayInTree (SgUctThreadState &state, bool &isTerminal) |
Play game until it leaves the tree. | |
bool | PlayoutGame (SgUctThreadState &state, std::size_t playout) |
Finish the game using GeneratePlayoutMove(). | |
void | PrintSearchProgress (double currTime) const |
Print time, mean, nodes searched, and PV. | |
void | SearchLoop (SgUctThreadState &state, GlobalLock *lock) |
Loop invoked by each thread for playing games. | |
const SgUctNode & | SelectChild (int &randomizeCounter, const SgUctNode &node) |
std::string | SummaryLine (const SgUctGameInfo &info) const |
void | UpdateCheckTimeInterval (double time) |
void | UpdateDynRaveBias () |
void | UpdateRaveValues (SgUctThreadState &state) |
Update the RAVE values in the tree for both players after a game was played. | |
void | UpdateRaveValues (SgUctThreadState &state, std::size_t playout) |
void | UpdateRaveValues (SgUctThreadState &state, std::size_t playout, SgUctValue eval, std::size_t i, const std::size_t firstPlay[], const std::size_t firstPlayOpp[]) |
void | UpdateStatistics (const SgUctGameInfo &info) |
void | UpdateTree (const SgUctGameInfo &info) |
Private Attributes | |
std::auto_ptr < SgUctThreadStateFactory > | m_threadStateFactory |
bool | m_logGames |
See LogGames(). | |
bool | m_rave |
See Rave(). | |
std::vector< SgUctValue > | m_knowledgeThreshold |
See KnowledgeThreshold(). | |
volatile bool | m_aborted |
Flag indicating that the search was terminated because the maximum time or number of games was reached. | |
volatile bool | m_isTreeOutOfMemory |
std::auto_ptr< boost::barrier > | m_searchLoopFinished |
bool | m_wasEarlyAbort |
See SgUctEarlyAbortParam. | |
std::auto_ptr < SgUctEarlyAbortParam > | m_earlyAbort |
See SgUctEarlyAbortParam. | |
SgUctMoveSelect | m_moveSelect |
See SgUctMoveSelect. | |
bool | m_raveCheckSame |
See RaveCheckSame(). | |
int | m_randomizeRaveFrequency |
See SetRandomizeRaveFrequency(). | |
bool | m_lockFree |
See LockFree(). | |
bool | m_weightRaveUpdates |
See WeightRaveUpdates(). | |
bool | m_pruneFullTree |
See PruneFullTree(). | |
bool | m_checkFloatPrecision |
See CheckFloatPrecision(). | |
unsigned int | m_numberThreads |
See NumberThreads(). | |
std::size_t | m_numberPlayouts |
See NumberPlayouts(). | |
std::size_t | m_maxNodes |
See MaxNodes(). | |
SgUctValue | m_pruneMinCount |
See PruneMinCount(). | |
const int | m_moveRange |
See parameter moveRange in constructor. | |
std::size_t | m_maxGameLength |
See MaxGameLength(). | |
SgUctValue | m_expandThreshold |
See ExpandThreshold(). | |
SgUctValue | m_maxGames |
Number of games limit for the current search. | |
SgUctValue | m_numberGames |
Number of games played in the current search. | |
SgUctValue | m_startRootMoveCount |
SgUctValue | m_checkTimeInterval |
Interval in number of games in which to check time abort. | |
volatile SgUctValue | m_nextCheckTime |
double | m_lastScoreDisplayTime |
float | m_biasTermConstant |
See BiasTermConstant(). | |
SgUctValue | m_firstPlayUrgency |
See FirstPlayUrgency(). | |
float | m_raveWeightInitial |
See Estimator weights in SgUctSearch. | |
float | m_raveWeightFinal |
See Estimator weights in SgUctSearch. | |
SgUctValue | m_raveWeightParam1 |
1 / m_raveWeightInitial precomputed for efficiency | |
SgUctValue | m_raveWeightParam2 |
m_raveWeightInitial / m_raveWeightFinal precomputed for efficiency | |
double | m_maxTime |
Time limit for current search. | |
bool | m_virtualLoss |
See VirtualLoss(). | |
std::string | m_logFileName |
SgTimer | m_timer |
SgUctTree | m_tree |
SgUctTree | m_tempTree |
See GetTempTree(). | |
std::vector< SgMove > | m_rootFilter |
See parameter rootFilter in function Search(). | |
std::ofstream | m_log |
boost::recursive_mutex | m_globalMutex |
Mutex for protecting global variables during multi-threading. | |
SgUctSearchStat | m_statistics |
std::vector< boost::shared_ptr < Thread > > | m_threads |
List of threads. | |
SgFastLog | m_fastLog |
boost::shared_ptr < SgMpiSynchronizer > | m_mpiSynchronizer |
Friends | |
class | Thread |
Monte Carlo tree search using UCT.
The evaluation function is assumed to be in [0..1]
and inverted with 1 - eval
.
Definition at line 465 of file SgUctSearch.h.
typedef boost::recursive_mutex::scoped_lock SgUctSearch::GlobalLock [private] |
Definition at line 859 of file SgUctSearch.h.
SgUctSearch::SgUctSearch | ( | SgUctThreadStateFactory * | threadStateFactory, | |
int | moveRange = 0 | |||
) |
Constructor.
threadStateFactory | The tread state factory (takes ownership). Can be null and set later (before using the search) with SetThreadStateFactory to allow multi-step construction. | |
moveRange | Upper integer limit (exclusive) used for move representation. Certain enhancements of SgUctSearch (e.g. Rave()) need to store data in arrays using the move as an index for efficient implementation. If the game does not use a small integer range for its move representation, this parameter should be 0. Then, enhancements that require a small move range cannot be enabled. |
Definition at line 249 of file SgUctSearch.cpp.
SgUctSearch::~SgUctSearch | ( | ) | [virtual] |
Definition at line 283 of file SgUctSearch.cpp.
References DeleteThreads().
void SgUctSearch::ApplyRootFilter | ( | std::vector< SgUctMoveInfo > & | moves | ) | [private] |
Definition at line 288 of file SgUctSearch.cpp.
References m_rootFilter.
Referenced by PlayInTree().
float SgUctSearch::BiasTermConstant | ( | ) | const |
Constant c in the bias term.
This constant corresponds to 2 C_p in the original UCT paper. The default value is 0.7, which works well in 9x9 Go.
Definition at line 1130 of file SgUctSearch.h.
References m_biasTermConstant.
bool SgUctSearch::CheckAbortSearch | ( | SgUctThreadState & | state | ) | [private] |
Definition at line 305 of file SgUctSearch.cpp.
References CheckCountAbort(), CheckEarlyAbort(), Debug(), SgTimer::GetTime(), SgUctValueUtil::IsPrecise(), SgUctNode::IsProven(), SgUctNode::IsProvenWin(), m_checkFloatPrecision, m_checkTimeInterval, m_earlyAbort, SgUctSearchStat::m_gamesPerSecond, m_maxGames, m_maxTime, m_moveSelect, m_nextCheckTime, m_numberGames, m_statistics, m_timer, m_tree, m_wasEarlyAbort, SgUctNode::MoveCount(), SgUctTree::Root(), SG_UCTMOVESELECT_COUNT, SgUserAbort(), and UpdateCheckTimeInterval().
Referenced by SearchLoop().
bool SgUctSearch::CheckCountAbort | ( | SgUctThreadState & | state, | |
SgUctValue | remainingGames | |||
) | const [private] |
Definition at line 386 of file SgUctSearch.cpp.
References FindBestChild(), SgUctThreadState::m_excludeMoves, m_tree, SgUctNode::Move(), SgUctNode::MoveCount(), SgUctTree::Root(), and SG_ASSERT.
Referenced by CheckAbortSearch().
bool SgUctSearch::CheckEarlyAbort | ( | ) | const [private] |
Definition at line 405 of file SgUctSearch.cpp.
References SgUctNode::HasMean(), m_earlyAbort, m_tree, SgUctNode::Mean(), SgUctNode::MoveCount(), and SgUctTree::Root().
Referenced by CheckAbortSearch().
bool SgUctSearch::CheckFloatPrecision | ( | ) | const |
Terminate the search if the counts can no longer be represented precisely by SgUctValue.
Default is true.
Definition at line 1135 of file SgUctSearch.h.
References m_checkFloatPrecision.
void SgUctSearch::CreateChildren | ( | SgUctThreadState & | state, | |
const SgUctNode & | node, | |||
bool | deleteChildTrees | |||
) | [private] |
Creates the children with the given moves and merges with existing children in the tree.
Definition at line 739 of file SgUctSearch.cpp.
References Debug(), SgUctTree::HasCapacity(), SgUctThreadState::m_isTreeOutOfMem, m_isTreeOutOfMemory, SgUctThreadState::m_moves, SgUctThreadState::m_threadId, m_tree, SgUctTree::MaxNodes(), SgUctTree::MergeChildren(), and SgSynchronizeThreadMemory().
Referenced by PlayInTree().
void SgUctSearch::CreateThreads | ( | ) |
Create threads.
The threads are created at the beginning of the first search (to allow multi-step construction with setting the policy after the constructor call). This function needs to be called explicitely only, if a thread state is going to be used before the first search.
Definition at line 414 of file SgUctSearch.cpp.
References SgUctTree::CreateAllocators(), DeleteThreads(), m_maxNodes, m_numberThreads, m_searchLoopFinished, m_threads, m_threadStateFactory, m_tree, SgUctTree::SetMaxNodes(), and Thread.
Referenced by GenerateAllMoves(), SearchOnePly(), SetNumberThreads(), and StartSearch().
void SgUctSearch::Debug | ( | const SgUctThreadState & | state, | |
const std::string & | textLine | |||
) | [private] |
Write a debugging line of text from within a thread.
Prepends the line with the thread number if number of threads is greater than one. Also ensures that the line is written as a single string to avoid intermingling of text lines from different threads.
state | The state of the thread (only used for state.m_threadId) | |
textLine | The line of text without trailing newline character. |
Definition at line 436 of file SgUctSearch.cpp.
References m_globalMutex, m_numberThreads, SgUctThreadState::m_threadId, and SgDebug().
Referenced by CheckAbortSearch(), CreateChildren(), and ExpandNode().
void SgUctSearch::DeleteThreads | ( | ) | [private] |
Definition at line 449 of file SgUctSearch.cpp.
References m_threads.
Referenced by CreateThreads(), SetThreadStateFactory(), and ~SgUctSearch().
void SgUctSearch::EndSearch | ( | ) |
void SgUctSearch::ExpandNode | ( | SgUctThreadState & | state, | |
const SgUctNode & | node | |||
) | [private] |
Expand a node.
state | The thread state with state.m_moves already computed. | |
node | The node to expand. |
Definition at line 457 of file SgUctSearch.cpp.
References SgUctTree::CreateChildren(), Debug(), SgUctTree::HasCapacity(), SgUctThreadState::m_isTreeOutOfMem, m_isTreeOutOfMemory, SgUctThreadState::m_moves, SgUctThreadState::m_threadId, m_tree, SgUctTree::MaxNodes(), and SgSynchronizeThreadMemory().
Referenced by PlayInTree().
SgUctValue SgUctSearch::ExpandThreshold | ( | ) | const |
Required number of simulations to expand a node in the tree.
The default is 2, which means a node will be expanded on the second visit.
Definition at line 1140 of file SgUctSearch.h.
References m_expandThreshold.
const SgUctNode * SgUctSearch::FindBestChild | ( | const SgUctNode & | node, | |
const std::vector< SgMove > * | excludeMoves = 0 | |||
) | const |
Find child node with best move.
node | The father node. | |
excludeMoves | Optional list of moves to ignore in the children nodes. |
Definition at line 473 of file SgUctSearch.cpp.
References GetBound(), GetValueEstimate(), SgUctNode::HasChildren(), SgUctNode::HasMean(), SgUctNode::HasRaveValue(), InverseEstimate(), SgUctNode::IsProvenLoss(), m_moveSelect, m_rave, m_tree, SgUctNode::Mean(), SgUctNode::Move(), SgUctNode::MoveCount(), SG_ASSERT, SG_UCTMOVESELECT_BOUND, SG_UCTMOVESELECT_COUNT, SG_UCTMOVESELECT_ESTIMATE, and SG_UCTMOVESELECT_VALUE.
Referenced by CheckCountAbort(), FindBestSequence(), and PrintSearchProgress().
void SgUctSearch::FindBestSequence | ( | std::vector< SgMove > & | sequence | ) | const |
Extract sequence of best moves from root node.
[out] | sequence | The resulting sequence. |
Definition at line 532 of file SgUctSearch.cpp.
References FindBestChild(), SgUctNode::HasChildren(), m_tree, SgUctNode::Move(), and SgUctTree::Root().
Referenced by Search().
SgUctValue SgUctSearch::FirstPlayUrgency | ( | ) | const |
First play urgency.
The value for unexplored moves. According to UCT they should always be preferred to moves, that have been played at least once. According to the MoGo tech report, it can be useful to use smaller values (as low as 1) to encorouge early exploitation. Default value is 10000.
Definition at line 1145 of file SgUctSearch.h.
References m_firstPlayUrgency.
SgUctValue SgUctSearch::GamesPlayed | ( | ) | const [virtual] |
Definition at line 300 of file SgUctSearch.cpp.
References m_startRootMoveCount, m_tree, SgUctNode::MoveCount(), and SgUctTree::Root().
Referenced by Search(), UpdateCheckTimeInterval(), and WriteStatistics().
void SgUctSearch::GenerateAllMoves | ( | std::vector< SgUctMoveInfo > & | moves | ) |
Get a list of all generated moves.
Sets up thread state 0 for a seach and calls GenerateAllMoves of the thread state.
Definition at line 547 of file SgUctSearch.cpp.
References CreateThreads(), SgUctThreadState::GenerateAllMoves(), m_threads, OnStartSearch(), SgUctThreadState::StartSearch(), and ThreadState().
SgUctValue SgUctSearch::GetBound | ( | bool | useRave, | |
const SgUctNode & | node, | |||
const SgUctNode & | child | |||
) | const |
Return the bound of a move.
This is the bound that was used for move selection. It can be the pure UCT bound or the combined bound if RAVE is used.
useRave | Whether rave should be used or not. | |
node | The node corresponding to the position | |
child | The node corresponding to the move |
Definition at line 559 of file SgUctSearch.cpp.
References Log(), SgUctNode::PosCount(), and SgUctNode::VirtualLossCount().
Referenced by FindBestChild(), and SelectChild().
SgUctValue SgUctSearch::GetBound | ( | bool | useRave, | |
SgUctValue | logPosCount, | |||
const SgUctNode & | child | |||
) | const [private] |
Definition at line 571 of file SgUctSearch.cpp.
References GetValueEstimate(), GetValueEstimateRave(), m_biasTermConstant, and SgUctNode::MoveCount().
SgUctTree & SgUctSearch::GetTempTree | ( | ) |
Get temporary tree.
Returns a tree that is compatible in size and number of allocators to the tree of the search. This tree is used by the search itself as a temporary tree for certain operations during the search, but can be used by other code while the search is not running.
Definition at line 590 of file SgUctSearch.cpp.
References SgUctTree::Clear(), SgUctTree::CreateAllocators(), m_tempTree, SgUctTree::MaxNodes(), MaxNodes(), SgUctTree::NuAllocators(), NumberThreads(), and SgUctTree::SetMaxNodes().
Referenced by Search().
SgUctValue SgUctSearch::GetValueEstimate | ( | bool | useRave, | |
const SgUctNode & | child | |||
) | const [private] |
Definition at line 608 of file SgUctSearch.cpp.
References SgStatisticsBase< VALUE, COUNT >::Add(), SgStatisticsBase< VALUE, COUNT >::Count(), SgUctNode::HasMean(), SgUctNode::HasRaveValue(), SgStatisticsBase< VALUE, COUNT >::Initialize(), InverseEstimate(), SgStatisticsBase< VALUE, COUNT >::IsDefined(), m_firstPlayUrgency, m_raveWeightParam1, m_raveWeightParam2, SgStatisticsBase< VALUE, COUNT >::Mean(), SgUctNode::Mean(), SgUctNode::MoveCount(), SgUctNode::RaveCount(), SgUctNode::RaveValue(), and SgUctNode::VirtualLossCount().
Referenced by FindBestChild(), GetBound(), and GetValueEstimateRave().
SgUctValue SgUctSearch::GetValueEstimateRave | ( | const SgUctNode & | child | ) | const [private] |
Optimized version of GetValueEstimate() if RAVE and not other estimators are used.
Previously there were more estimators than move value and RAVE value, and in the future there may be again. GetValueEstimate() is easier to extend, this function is more optimized for the special case.
Definition at line 668 of file SgUctSearch.cpp.
References SgStatisticsBase< VALUE, COUNT >::Add(), SgStatisticsBase< VALUE, COUNT >::Count(), GetValueEstimate(), SgUctNode::HasMean(), SgUctNode::HasRaveValue(), SgStatisticsBase< VALUE, COUNT >::Initialize(), InverseEstimate(), SgStatisticsBase< VALUE, COUNT >::IsDefined(), m_firstPlayUrgency, m_lockFree, m_numberThreads, m_rave, m_raveWeightParam1, m_raveWeightParam2, SgStatisticsBase< VALUE, COUNT >::Mean(), SgUctNode::Mean(), SgUctNode::MoveCount(), SgUctNode::RaveCount(), SgUctNode::RaveValue(), SG_ASSERT, and SgUctNode::VirtualLossCount().
Referenced by GetBound().
SgUctValue SgUctSearch::InverseEstimate | ( | SgUctValue | eval | ) | [static] |
Definition at line 1155 of file SgUctSearch.h.
Referenced by SgUctTreeStatistics::Compute(), FindBestChild(), GetValueEstimate(), and GetValueEstimateRave().
SgUctValue SgUctSearch::InverseEval | ( | SgUctValue | eval | ) | [static] |
Definition at line 1150 of file SgUctSearch.h.
Referenced by PlayGame(), SearchOnePly(), UpdateRaveValues(), and UpdateTree().
std::vector< SgUctValue > SgUctSearch::KnowledgeThreshold | ( | ) | const |
Points at which to recompute children.
Specifies the number of visits at which GenerateAllMoves() is called again at the node. This is to allow multiple knowledge computations to occur as a node becomes more important. Returned move info will be merged with info in the tree. This is can be used prune, add children, give a bonus to a move, etc.
Definition at line 1283 of file SgUctSearch.h.
References m_knowledgeThreshold.
const SgUctGameInfo & SgUctSearch::LastGameInfo | ( | ) | const |
Info for last game.
Returns the last game info of the first thread. This function is not thread-safe.
Definition at line 1165 of file SgUctSearch.h.
References SgUctThreadState::m_gameInfo, and ThreadState().
Referenced by LastGameSummaryLine().
string SgUctSearch::LastGameSummaryLine | ( | ) | const |
One-line summary text for last game.
Contains: move, count and mean for all nodes; result Returns the last game info of the first thread. This function is not thread-safe.
Definition at line 723 of file SgUctSearch.cpp.
References LastGameInfo(), and SummaryLine().
bool SgUctSearch::LockFree | ( | ) | const |
Lock-free usage of multi-threaded search.
Definition at line 1160 of file SgUctSearch.h.
References m_lockFree.
SgUctValue SgUctSearch::Log | ( | SgUctValue | x | ) | const [private] |
Definition at line 728 of file SgUctSearch.cpp.
References SgFastLog::Log(), and m_fastLog.
Referenced by GetBound(), and SelectChild().
bool SgUctSearch::LogGames | ( | ) | const |
Log one-line summary for each game during Search() to a file.
Definition at line 1170 of file SgUctSearch.h.
References m_logGames.
std::size_t SgUctSearch::MaxGameLength | ( | ) | const |
Maximum game length.
If the number of moves in a game exceed this length, it will be counted as a loss. The default is numeric_limits<size_t>::max()
Definition at line 1175 of file SgUctSearch.h.
References m_maxGameLength.
std::size_t SgUctSearch::MaxNodes | ( | ) | const |
Maximum number of nodes in the tree.
Definition at line 1180 of file SgUctSearch.h.
References m_maxNodes.
Referenced by GetTempTree().
SgUctMoveSelect SgUctSearch::MoveSelect | ( | ) | const |
virtual std::string SgUctSearch::MoveString | ( | SgMove | move | ) | const [pure virtual] |
Convert move to string (game dependent).
This function needs to be thread-safe.
Referenced by PrintSearchProgress(), SearchOnePly(), and SummaryLine().
SgMpiSynchronizerHandle SgUctSearch::MpiSynchronizer | ( | ) |
Definition at line 1316 of file SgUctSearch.h.
References m_mpiSynchronizer.
const SgMpiSynchronizerHandle SgUctSearch::MpiSynchronizer | ( | ) | const |
Definition at line 1321 of file SgUctSearch.h.
References m_mpiSynchronizer.
bool SgUctSearch::NeedToComputeKnowledge | ( | const SgUctNode * | current | ) | [private] |
Definition at line 756 of file SgUctSearch.cpp.
References SgUctNode::KnowledgeCount(), m_knowledgeThreshold, m_tree, SgUctNode::MoveCount(), SgUctTree::SetKnowledgeCount(), and SG_ASSERT.
Referenced by PlayInTree().
std::size_t SgUctSearch::NumberPlayouts | ( | ) | const |
The number of playouts per simulated game.
Useful for multi-threading to increase the workload of the threads. Default is 1.
Definition at line 1195 of file SgUctSearch.h.
References m_numberPlayouts.
unsigned int SgUctSearch::NumberThreads | ( | ) | const |
The number of threads to use during the search.
Definition at line 1190 of file SgUctSearch.h.
References m_numberThreads.
Referenced by GetTempTree(), and SearchLoop().
void SgUctSearch::OnEndSearch | ( | ) | [virtual] |
Hook function that will be called when search completes.
Default implementation calls m_mpiSynchronizer.EndSearch(). This function does not need to be thread-safe.
Definition at line 785 of file SgUctSearch.cpp.
References m_mpiSynchronizer.
Referenced by EndSearch().
void SgUctSearch::OnSearchIteration | ( | SgUctValue | gameNumber, | |
unsigned int | threadId, | |||
const SgUctGameInfo & | info | |||
) | [virtual] |
Hook function that will be called by Search() after each game.
Default implementation does nothing. This function does not need to be thread-safe.
gameNumber | The number of this iteration. | |
threadId | ||
info | The game info of the thread which played this iteration. |
Definition at line 816 of file SgUctSearch.cpp.
References SgTimer::GetTime(), m_lastScoreDisplayTime, m_mpiSynchronizer, m_timer, and PrintSearchProgress().
Referenced by SearchLoop(), and SearchOnePly().
void SgUctSearch::OnStartSearch | ( | ) | [virtual] |
Hook function that will be called by StartSearch().
Default implementation calls m_mpiSynchronizer.StartSearch(). This function does not need to be thread-safe.
Definition at line 780 of file SgUctSearch.cpp.
References m_mpiSynchronizer.
Referenced by GenerateAllMoves(), SearchOnePly(), and StartSearch().
void SgUctSearch::OnThreadEndSearch | ( | SgUctThreadState & | state | ) | [virtual] |
Definition at line 1171 of file SgUctSearch.cpp.
References m_mpiSynchronizer.
Referenced by SearchLoop().
void SgUctSearch::OnThreadStartSearch | ( | SgUctThreadState & | state | ) | [virtual] |
Definition at line 1166 of file SgUctSearch.cpp.
References m_mpiSynchronizer.
Referenced by SearchLoop().
void SgUctSearch::PlayGame | ( | SgUctThreadState & | state, | |
GlobalLock * | lock | |||
) | [private] |
Definition at line 832 of file SgUctSearch.cpp.
References SgUctGameInfo::Clear(), SgUctThreadState::EndPlayout(), SgUctThreadState::Evaluate(), SgUctThreadState::GameStart(), InverseEval(), SgUctGameInfo::m_aborted, SgUctGameInfo::m_eval, SgUctThreadState::m_gameInfo, SgUctGameInfo::m_inTreeSequence, SgUctThreadState::m_isTreeOutOfMem, SgUctGameInfo::m_nodes, m_numberPlayouts, m_rave, SgUctGameInfo::m_sequence, SgUctGameInfo::m_skipRaveUpdate, m_tree, PlayInTree(), PlayoutGame(), PropagateProvenStatus(), SgUctTree::SetProvenType(), SG_PROVEN_LOSS, SG_PROVEN_WIN, SgUctThreadState::StartPlayout(), SgUctThreadState::StartPlayouts(), SgUctThreadState::TakeBackInTree(), SgUctThreadState::TakeBackPlayout(), UnknownEval(), UpdateRaveValues(), UpdateStatistics(), and UpdateTree().
void SgUctSearch::PlayGame | ( | ) |
Play a single game.
Plays a single game using the thread state of the first thread. Call StartSearch() before calling this function.
Definition at line 1200 of file SgUctSearch.h.
References ThreadState().
Referenced by SearchLoop().
bool SgUctSearch::PlayInTree | ( | SgUctThreadState & | state, | |
bool & | isTerminal | |||
) | [private] |
Play game until it leaves the tree.
state | ||
[out] | isTerminal | Was the sequence terminated because of a real terminal position (GenerateAllMoves() returned an empty list)? |
false
, if game was aborted due to maximum length Definition at line 948 of file SgUctSearch.cpp.
References SgUctTree::AddVirtualLoss(), ApplyRootFilter(), CreateChildren(), SgUctThreadState::Execute(), ExpandNode(), SgUctThreadState::GenerateAllMoves(), SgUctNode::HasChildren(), SgUctNode::IsProven(), SgUctNode::KnowledgeCount(), m_expandThreshold, SgUctThreadState::m_gameInfo, SgUctGameInfo::m_inTreeSequence, SgUctThreadState::m_isTreeOutOfMem, SgUctSearchStat::m_knowledge, m_maxGameLength, SgUctThreadState::m_moves, SgUctGameInfo::m_nodes, m_numberThreads, SgUctThreadState::m_randomizeCounter, m_statistics, m_tree, m_virtualLoss, SgUctNode::Move(), SgUctNode::MoveCount(), NeedToComputeKnowledge(), PropagateProvenStatus(), SgUctTree::Root(), SelectChild(), SgUctTree::SetProvenType(), and SG_NOT_PROVEN.
Referenced by PlayGame().
bool SgUctSearch::PlayoutGame | ( | SgUctThreadState & | state, | |
std::size_t | playout | |||
) | [private] |
Finish the game using GeneratePlayoutMove().
state | The thread state. | |
playout | The number of the playout. |
false
if game was aborted Definition at line 1042 of file SgUctSearch.cpp.
References SgUctThreadState::ExecutePlayout(), SgUctThreadState::GeneratePlayoutMove(), SgUctThreadState::m_gameInfo, m_maxGameLength, SgUctGameInfo::m_sequence, SgUctGameInfo::m_skipRaveUpdate, and SG_NULLMOVE.
Referenced by PlayGame(), and SearchOnePly().
void SgUctSearch::PrintSearchProgress | ( | double | currTime | ) | const [private] |
Print time, mean, nodes searched, and PV.
Definition at line 791 of file SgUctSearch.cpp.
References FindBestChild(), SgTime::Format(), SgUctNode::HasChildren(), m_tree, SgUctNode::Mean(), SgUctNode::Move(), SgUctNode::MoveCount(), MoveString(), SgUctTree::Root(), and SgDebug().
Referenced by OnSearchIteration().
void SgUctSearch::PropagateProvenStatus | ( | const vector< const SgUctNode * > & | nodes | ) | [private] |
Backs up proven information.
Last node of nodes is the newly proven node.
Definition at line 913 of file SgUctSearch.cpp.
References SgUctNode::IsProven(), SgUctNode::IsProvenLoss(), m_tree, SgUctTree::SetProvenType(), and SG_NOT_PROVEN.
Referenced by PlayGame(), and PlayInTree().
bool SgUctSearch::PruneFullTree | ( | ) | const |
Prune nodes with low counts if tree is full.
This will prune nodes below a minimum count, if the tree gets full during a search. The minimum count is PruneMinCount() at the beginning of the search and is doubled every time a pruning operation does not reduce the tree by at least a factor of 2. The creation of the pruned tree uses the temporary tree (see GetTempTree()).
Definition at line 1205 of file SgUctSearch.h.
References m_pruneFullTree.
SgUctValue SgUctSearch::PruneMinCount | ( | ) | const |
int SgUctSearch::RandomizeRaveFrequency | ( | ) | const |
See SetRandomizeRaveFrequency().
Definition at line 1326 of file SgUctSearch.h.
References m_randomizeRaveFrequency.
bool SgUctSearch::Rave | ( | ) | const |
Use the RAVE algorithm (Rapid Action Value Estimation).
See Gelly, Silver 2007 in the references in the class description. In difference to the original description of the RAVE algorithm, no "RAVE bias term" is used. The estimated value of a move is the weighted mean of the move value and the RAVE value and then a single UCT-like bias term is added.
Definition at line 1215 of file SgUctSearch.h.
References m_rave.
bool SgUctSearch::RaveCheckSame | ( | ) | const |
Don't update RAVE value if opponent played the same move first.
Default is false (since it depends on the game and move representation, if it should be used).
Definition at line 1220 of file SgUctSearch.h.
References m_raveCheckSame.
float SgUctSearch::RaveWeightFinal | ( | ) | const |
See Estimator weights in SgUctSearch.
Definition at line 1230 of file SgUctSearch.h.
References m_raveWeightFinal.
float SgUctSearch::RaveWeightInitial | ( | ) | const |
See Estimator weights in SgUctSearch.
Definition at line 1225 of file SgUctSearch.h.
References m_raveWeightInitial.
SgUctValue SgUctSearch::Search | ( | SgUctValue | maxGames, | |
double | maxTime, | |||
std::vector< SgMove > & | sequence, | |||
const std::vector< SgMove > & | rootFilter = std::vector<SgMove>() , |
|||
SgUctTree * | initTree = 0 , |
|||
SgUctEarlyAbortParam * | earlyAbort = 0 | |||
) |
Calls StartSearch() and then PlayGame() in a loop.
maxGames | The maximum number of games (greater or equal one). The number of games includes the ones already counted in the initialization tree (see parameter initTree). | |
maxTime | The maximum time in seconds. | |
[out] | sequence | The move sequence with the best value. |
rootFilter | Moves to filter at the root node | |
initTree | The tree to initialize the search with. 0 for no initialization. The trees are actually swapped, not copied. | |
earlyAbort | See SgUctEarlyAbortParam. Null means not to do an early abort. |
Definition at line 1062 of file SgUctSearch.cpp.
References SgUctTree::CopyPruneLowCount(), EndSearch(), FindBestSequence(), GamesPlayed(), GetTempTree(), SgTimer::GetTime(), m_aborted, m_earlyAbort, SgUctSearchStat::m_gamesPerSecond, m_isTreeOutOfMemory, m_log, m_logFileName, m_logGames, m_maxGames, m_maxTime, m_mpiSynchronizer, m_pruneFullTree, m_pruneMinCount, m_rootFilter, m_statistics, m_threads, SgUctSearchStat::m_time, m_timer, m_tree, SgUctNode::Mean(), SgUctNode::MoveCount(), SgUctTree::NuNodes(), SgUctTree::Root(), SgDebug(), SgSynchronizeThreadMemory(), SgTimer::Start(), StartSearch(), and SgUctTree::Swap().
void SgUctSearch::SearchLoop | ( | SgUctThreadState & | state, | |
GlobalLock * | lock | |||
) | [private] |
Loop invoked by each thread for playing games.
Definition at line 1128 of file SgUctSearch.cpp.
References CheckAbortSearch(), m_aborted, SgUctThreadState::m_gameInfo, SgUctThreadState::m_isSearchInitialized, SgUctThreadState::m_isTreeOutOfMem, m_isTreeOutOfMemory, m_lockFree, m_log, m_logGames, m_numberGames, m_pruneFullTree, m_searchLoopFinished, SgUctThreadState::m_threadId, NumberThreads(), OnSearchIteration(), OnThreadEndSearch(), OnThreadStartSearch(), PlayGame(), SgSynchronizeThreadMemory(), and SummaryLine().
Referenced by SgUctSearch::Thread::operator()().
SgPoint SgUctSearch::SearchOnePly | ( | SgUctValue | maxGames, | |
double | maxTime, | |||
SgUctValue & | value | |||
) |
Do a one-ply Monte-Carlo search instead of the UCT search.
maxGames | ||
maxTime | ||
[out] | value | The value of the best move |
Definition at line 1176 of file SgUctSearch.cpp.
References SgUctGameInfo::Clear(), CreateThreads(), SgUctThreadState::EndPlayout(), SgUctThreadState::Evaluate(), SgUctThreadState::Execute(), SgUctThreadState::GameStart(), SgUctThreadState::GenerateAllMoves(), SgTimer::GetTime(), InverseEval(), SgUctThreadState::m_gameInfo, SgUctGameInfo::m_inTreeSequence, SgUctGameInfo::m_sequence, SgUctGameInfo::m_skipRaveUpdate, m_threads, m_timer, MoveString(), OnSearchIteration(), OnStartSearch(), PlayoutGame(), SG_NULLMOVE, SgDebug(), SgUserAbort(), SgTimer::Start(), SgUctThreadState::StartPlayout(), SgUctThreadState::StartPlayouts(), SgUctThreadState::StartSearch(), SgUctThreadState::TakeBackInTree(), SgUctThreadState::TakeBackPlayout(), ThreadState(), and UnknownEval().
const SgUctNode & SgUctSearch::SelectChild | ( | int & | randomizeCounter, | |
const SgUctNode & | node | |||
) | [private] |
Definition at line 1236 of file SgUctSearch.cpp.
References SgUctNode::FirstChild(), GetBound(), SgUctNode::HasChildren(), SgUctNode::IsProvenWin(), Log(), m_randomizeRaveFrequency, m_rave, m_tree, SgUctNode::PosCount(), SG_ASSERT, and SgUctNode::VirtualLossCount().
Referenced by PlayInTree().
void SgUctSearch::SetBiasTermConstant | ( | float | biasTermConstant | ) |
See BiasTermConstant().
Definition at line 1235 of file SgUctSearch.h.
References m_biasTermConstant.
void SgUctSearch::SetCheckFloatPrecision | ( | bool | enable | ) |
Definition at line 1240 of file SgUctSearch.h.
References m_checkFloatPrecision.
void SgUctSearch::SetExpandThreshold | ( | SgUctValue | expandThreshold | ) |
See ExpandThreshold().
Definition at line 1245 of file SgUctSearch.h.
References m_expandThreshold, and SG_ASSERT.
void SgUctSearch::SetFirstPlayUrgency | ( | SgUctValue | firstPlayUrgency | ) |
See FirstPlayUrgency().
Definition at line 1251 of file SgUctSearch.h.
References m_firstPlayUrgency.
void SgUctSearch::SetKnowledgeThreshold | ( | const std::vector< SgUctValue > & | counts | ) |
See KnowledgeThreshold().
Definition at line 1289 of file SgUctSearch.h.
References m_knowledgeThreshold.
void SgUctSearch::SetLockFree | ( | bool | enable | ) |
void SgUctSearch::SetLogGames | ( | bool | enable | ) |
void SgUctSearch::SetMaxGameLength | ( | std::size_t | maxGameLength | ) |
void SgUctSearch::SetMaxNodes | ( | std::size_t | maxNodes | ) |
See MaxNodes().
maxNodes | Maximum number of nodes (>= 1) |
Definition at line 1271 of file SgUctSearch.h.
References m_maxNodes, m_threads, m_tree, and SgUctTree::SetMaxNodes().
void SgUctSearch::SetMoveSelect | ( | SgUctMoveSelect | moveSelect | ) |
void SgUctSearch::SetMpiSynchronizer | ( | const SgMpiSynchronizerHandle & | synchronizerHandle | ) |
Definition at line 1310 of file SgUctSearch.h.
References m_mpiSynchronizer.
void SgUctSearch::SetNumberPlayouts | ( | std::size_t | n | ) |
Definition at line 1294 of file SgUctSearch.h.
References m_numberPlayouts, and SG_ASSERT.
void SgUctSearch::SetNumberThreads | ( | unsigned int | n | ) |
See SetNumberThreads().
Definition at line 1290 of file SgUctSearch.cpp.
References CreateThreads(), m_numberThreads, and SG_ASSERT.
void SgUctSearch::SetPruneFullTree | ( | bool | enable | ) |
void SgUctSearch::SetPruneMinCount | ( | SgUctValue | n | ) |
void SgUctSearch::SetRandomizeRaveFrequency | ( | int | frequency | ) |
Randomly turns off rave with given frequency - once in every frequency child selections.
Helps in rare cases where rave ignores the best move. Set frequency to 0 to switch it off.
Definition at line 1331 of file SgUctSearch.h.
References m_randomizeRaveFrequency.
void SgUctSearch::SetRave | ( | bool | enable | ) |
void SgUctSearch::SetRaveCheckSame | ( | bool | enable | ) |
void SgUctSearch::SetRaveWeightFinal | ( | float | value | ) |
See Estimator weights in SgUctSearch.
Definition at line 1341 of file SgUctSearch.h.
References m_raveWeightFinal.
void SgUctSearch::SetRaveWeightInitial | ( | float | value | ) |
See Estimator weights in SgUctSearch.
Definition at line 1346 of file SgUctSearch.h.
References m_raveWeightInitial.
void SgUctSearch::SetThreadStateFactory | ( | SgUctThreadStateFactory * | factory | ) |
Definition at line 1306 of file SgUctSearch.cpp.
References DeleteThreads(), m_threadStateFactory, and SG_ASSERT.
void SgUctSearch::SetVirtualLoss | ( | bool | enable | ) |
void SgUctSearch::SetWeightRaveUpdates | ( | bool | enable | ) |
See WeightRaveUpdates().
Definition at line 1351 of file SgUctSearch.h.
References m_weightRaveUpdates.
void SgUctSearch::StartSearch | ( | const std::vector< SgMove > & | rootFilter = std::vector<SgMove>() , |
|
SgUctTree * | initTree = 0 | |||
) |
Start search.
Initializes search for current position and clears statistics.
rootFilter | Moves to filter at the root node | |
initTree | The tree to initialize the search with. 0 for no initialization. The trees are actually swapped, not copied. |
Definition at line 1316 of file SgUctSearch.cpp.
References SgUctTree::ApplyFilter(), SgUctSearchStat::Clear(), SgUctTree::Clear(), CreateThreads(), SgTime::DefaultMode(), SgTimer::GetTime(), SgUctTree::HasCapacity(), m_aborted, m_checkTimeInterval, m_lastScoreDisplayTime, m_nextCheckTime, m_numberGames, m_numberThreads, SgUctThreadState::m_randomizeCounter, m_randomizeRaveFrequency, m_raveWeightFinal, m_raveWeightInitial, m_raveWeightParam1, m_raveWeightParam2, m_startRootMoveCount, m_statistics, m_threads, m_timer, m_tree, m_wasEarlyAbort, SgUctNode::MoveCount(), SgUctNode::NuChildren(), OnStartSearch(), SgUctTree::Root(), SgWarning(), SgUctThreadState::StartSearch(), SgUctTree::Swap(), and ThreadState().
Referenced by Search().
const SgUctSearchStat & SgUctSearch::Statistics | ( | ) | const |
Definition at line 1366 of file SgUctSearch.h.
References m_statistics.
string SgUctSearch::SummaryLine | ( | const SgUctGameInfo & | info | ) | const [private] |
Definition at line 1366 of file SgUctSearch.cpp.
References SgUctGameInfo::m_eval, SgUctGameInfo::m_nodes, SgUctNode::Mean(), SgUctNode::Move(), SgUctNode::MoveCount(), and MoveString().
Referenced by LastGameSummaryLine(), and SearchLoop().
bool SgUctSearch::ThreadsCreated | ( | ) | const |
Check if threads are already created.
The threads are created at the beginning of the first search (to allow multi-step construction with setting the policy after the constructor call).
Definition at line 1371 of file SgUctSearch.h.
References m_threads.
SgUctThreadState & SgUctSearch::ThreadState | ( | int | i | ) | const |
Get state of one of the threads.
Requires: ThreadsCreated()
Definition at line 1376 of file SgUctSearch.h.
References m_threads, and SG_ASSERT.
Referenced by GenerateAllMoves(), LastGameInfo(), PlayGame(), SearchOnePly(), and StartSearch().
const SgUctTree & SgUctSearch::Tree | ( | ) | const |
Definition at line 1382 of file SgUctSearch.h.
References m_tree.
virtual SgUctValue SgUctSearch::UnknownEval | ( | ) | const [pure virtual] |
Evaluation value to use if evaluation is unknown.
This value will be used, if games are aborted, because they exceed the maximum game length. This function needs to be thread-safe.
Referenced by PlayGame(), and SearchOnePly().
void SgUctSearch::UpdateCheckTimeInterval | ( | double | time | ) | [private] |
Definition at line 1382 of file SgUctSearch.cpp.
References GamesPlayed(), m_checkTimeInterval, SgUctSearchStat::m_gamesPerSecond, m_maxTime, m_numberThreads, and m_statistics.
Referenced by CheckAbortSearch().
void SgUctSearch::UpdateDynRaveBias | ( | ) | [private] |
void SgUctSearch::UpdateRaveValues | ( | SgUctThreadState & | state, | |
std::size_t | playout | |||
) | [private] |
Definition at line 1412 of file SgUctSearch.cpp.
References InverseEval(), SgUctGameInfo::m_eval, SgUctThreadState::m_firstPlay, SgUctThreadState::m_firstPlayOpp, SgUctThreadState::m_gameInfo, SgUctGameInfo::m_inTreeSequence, m_moveRange, SgUctGameInfo::m_nodes, SgUctGameInfo::m_sequence, SgUctGameInfo::m_skipRaveUpdate, SG_ASSERT, and UpdateRaveValues().
void SgUctSearch::UpdateRaveValues | ( | SgUctThreadState & | state, | |
std::size_t | playout, | |||
SgUctValue | eval, | |||
std::size_t | i, | |||
const std::size_t | firstPlay[], | |||
const std::size_t | firstPlayOpp[] | |||
) | [private] |
Definition at line 1473 of file SgUctSearch.cpp.
References SgUctTree::AddRaveValue(), SgUtil::InRange(), SgUctThreadState::m_gameInfo, SgUctGameInfo::m_nodes, m_raveCheckSame, SgUctGameInfo::m_sequence, m_tree, m_weightRaveUpdates, SgUctNode::Move(), and SG_ASSERT.
void SgUctSearch::UpdateRaveValues | ( | SgUctThreadState & | state | ) | [private] |
Update the RAVE values in the tree for both players after a game was played.
Definition at line 1406 of file SgUctSearch.cpp.
References m_numberPlayouts.
Referenced by PlayGame(), and UpdateRaveValues().
void SgUctSearch::UpdateStatistics | ( | const SgUctGameInfo & | info | ) | [private] |
Definition at line 1503 of file SgUctSearch.cpp.
References SgStatisticsBase< VALUE, COUNT >::Add(), SgStatisticsExt< VALUE, COUNT >::Add(), SgUctGameInfo::m_aborted, SgUctSearchStat::m_aborted, SgUctSearchStat::m_gameLength, SgUctGameInfo::m_inTreeSequence, SgUctSearchStat::m_movesInTree, m_numberPlayouts, SgUctGameInfo::m_sequence, and m_statistics.
Referenced by PlayGame().
void SgUctSearch::UpdateTree | ( | const SgUctGameInfo & | info | ) | [private] |
Definition at line 1515 of file SgUctSearch.cpp.
References SgUctTree::AddGameResults(), InverseEval(), SgUctGameInfo::m_eval, SgUctGameInfo::m_nodes, m_numberPlayouts, m_numberThreads, m_tree, m_virtualLoss, and SgUctTree::RemoveVirtualLoss().
Referenced by PlayGame().
bool SgUctSearch::VirtualLoss | ( | ) | const |
Whether search uses virtual loss.
Definition at line 1356 of file SgUctSearch.h.
References m_virtualLoss.
bool SgUctSearch::WasEarlyAbort | ( | ) | const |
See parameter earlyAbort in Search().
Definition at line 1387 of file SgUctSearch.h.
References m_wasEarlyAbort.
bool SgUctSearch::WeightRaveUpdates | ( | ) | const |
Weight RAVE updates.
Gives more weight to moves that are closer to the position for which the RAVE statistics are stored. The weighting function is linearly decreasing from 2 to 0 with the move number from the position for which the RAVE statistics are stored to the end of the simulated game.
Definition at line 1392 of file SgUctSearch.h.
References m_weightRaveUpdates.
void SgUctSearch::WriteStatistics | ( | std::ostream & | out | ) | const |
Definition at line 1536 of file SgUctSearch.cpp.
References GamesPlayed(), SgUctSearchStat::m_knowledge, m_knowledgeThreshold, m_mpiSynchronizer, m_statistics, m_tree, SgUctNode::MoveCount(), SgUctTree::NuNodes(), SgUctTree::Root(), and SgUctSearchStat::Write().
friend class Thread [friend] |
Definition at line 861 of file SgUctSearch.h.
Referenced by CreateThreads().
volatile bool SgUctSearch::m_aborted [private] |
Flag indicating that the search was terminated because the maximum time or number of games was reached.
Definition at line 934 of file SgUctSearch.h.
Referenced by Search(), SearchLoop(), and StartSearch().
float SgUctSearch::m_biasTermConstant [private] |
See BiasTermConstant().
Definition at line 1010 of file SgUctSearch.h.
Referenced by BiasTermConstant(), GetBound(), and SetBiasTermConstant().
bool SgUctSearch::m_checkFloatPrecision [private] |
Definition at line 966 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), CheckFloatPrecision(), and SetCheckFloatPrecision().
SgUctValue SgUctSearch::m_checkTimeInterval [private] |
Interval in number of games in which to check time abort.
Avoids that the potentially expensive SgTime::Get() is called after every game. The interval is updated dynamically according to the current games/sec, such that it is called ten times per second (if the total search time is at least one second, otherwise ten times per total maximum search time)
Definition at line 1003 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), StartSearch(), and UpdateCheckTimeInterval().
std::auto_ptr<SgUctEarlyAbortParam> SgUctSearch::m_earlyAbort [private] |
See SgUctEarlyAbortParam.
The auto pointer is empty, if no early abort is used.
Definition at line 945 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), CheckEarlyAbort(), and Search().
SgUctValue SgUctSearch::m_expandThreshold [private] |
See ExpandThreshold().
Definition at line 987 of file SgUctSearch.h.
Referenced by ExpandThreshold(), PlayInTree(), and SetExpandThreshold().
SgFastLog SgUctSearch::m_fastLog [private] |
Definition at line 1061 of file SgUctSearch.h.
Referenced by Log().
SgUctValue SgUctSearch::m_firstPlayUrgency [private] |
See FirstPlayUrgency().
Definition at line 1013 of file SgUctSearch.h.
Referenced by FirstPlayUrgency(), GetValueEstimate(), GetValueEstimateRave(), and SetFirstPlayUrgency().
boost::recursive_mutex SgUctSearch::m_globalMutex [private] |
Mutex for protecting global variables during multi-threading.
Currently, only the play-out phase of games is thread safe, therefore this lock is always locked elsewhere (in-tree phase, updating of values and statistics, etc.)
Definition at line 1051 of file SgUctSearch.h.
Referenced by Debug().
volatile bool SgUctSearch::m_isTreeOutOfMemory [private] |
Definition at line 936 of file SgUctSearch.h.
Referenced by CreateChildren(), ExpandNode(), Search(), and SearchLoop().
std::vector<SgUctValue> SgUctSearch::m_knowledgeThreshold [private] |
See KnowledgeThreshold().
Definition at line 930 of file SgUctSearch.h.
Referenced by KnowledgeThreshold(), NeedToComputeKnowledge(), SetKnowledgeThreshold(), and WriteStatistics().
double SgUctSearch::m_lastScoreDisplayTime [private] |
Definition at line 1007 of file SgUctSearch.h.
Referenced by OnSearchIteration(), and StartSearch().
bool SgUctSearch::m_lockFree [private] |
See LockFree().
Definition at line 957 of file SgUctSearch.h.
Referenced by GetValueEstimateRave(), LockFree(), SearchLoop(), and SetLockFree().
std::ofstream SgUctSearch::m_log [private] |
Definition at line 1045 of file SgUctSearch.h.
Referenced by Search(), and SearchLoop().
std::string SgUctSearch::m_logFileName [private] |
Definition at line 1033 of file SgUctSearch.h.
Referenced by Search().
bool SgUctSearch::m_logGames [private] |
See LogGames().
Definition at line 924 of file SgUctSearch.h.
Referenced by LogGames(), Search(), SearchLoop(), and SetLogGames().
std::size_t SgUctSearch::m_maxGameLength [private] |
See MaxGameLength().
Definition at line 984 of file SgUctSearch.h.
Referenced by MaxGameLength(), PlayInTree(), PlayoutGame(), and SetMaxGameLength().
SgUctValue SgUctSearch::m_maxGames [private] |
Number of games limit for the current search.
Definition at line 990 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), and Search().
std::size_t SgUctSearch::m_maxNodes [private] |
See MaxNodes().
Definition at line 975 of file SgUctSearch.h.
Referenced by CreateThreads(), MaxNodes(), and SetMaxNodes().
double SgUctSearch::m_maxTime [private] |
Time limit for current search.
Definition at line 1028 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), Search(), and UpdateCheckTimeInterval().
const int SgUctSearch::m_moveRange [private] |
See parameter moveRange in constructor.
Definition at line 981 of file SgUctSearch.h.
Referenced by SetRave(), and UpdateRaveValues().
SgUctMoveSelect SgUctSearch::m_moveSelect [private] |
See SgUctMoveSelect.
Definition at line 948 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), FindBestChild(), MoveSelect(), and SetMoveSelect().
boost::shared_ptr<SgMpiSynchronizer> SgUctSearch::m_mpiSynchronizer [private] |
Definition at line 1064 of file SgUctSearch.h.
Referenced by MpiSynchronizer(), OnEndSearch(), OnSearchIteration(), OnStartSearch(), OnThreadEndSearch(), OnThreadStartSearch(), Search(), SetMpiSynchronizer(), and WriteStatistics().
volatile SgUctValue SgUctSearch::m_nextCheckTime [private] |
Definition at line 1005 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), and StartSearch().
SgUctValue SgUctSearch::m_numberGames [private] |
Number of games played in the current search.
Definition at line 993 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), SearchLoop(), and StartSearch().
std::size_t SgUctSearch::m_numberPlayouts [private] |
See NumberPlayouts().
Definition at line 972 of file SgUctSearch.h.
Referenced by NumberPlayouts(), PlayGame(), SetNumberPlayouts(), UpdateRaveValues(), UpdateStatistics(), and UpdateTree().
unsigned int SgUctSearch::m_numberThreads [private] |
See NumberThreads().
Definition at line 969 of file SgUctSearch.h.
Referenced by CreateThreads(), Debug(), GetValueEstimateRave(), NumberThreads(), PlayInTree(), SetNumberThreads(), StartSearch(), UpdateCheckTimeInterval(), and UpdateTree().
bool SgUctSearch::m_pruneFullTree [private] |
See PruneFullTree().
Definition at line 963 of file SgUctSearch.h.
Referenced by PruneFullTree(), Search(), SearchLoop(), and SetPruneFullTree().
SgUctValue SgUctSearch::m_pruneMinCount [private] |
See PruneMinCount().
Definition at line 978 of file SgUctSearch.h.
Referenced by PruneMinCount(), Search(), and SetPruneMinCount().
int SgUctSearch::m_randomizeRaveFrequency [private] |
See SetRandomizeRaveFrequency().
Definition at line 954 of file SgUctSearch.h.
Referenced by RandomizeRaveFrequency(), SelectChild(), SetRandomizeRaveFrequency(), and StartSearch().
bool SgUctSearch::m_rave [private] |
See Rave().
Definition at line 927 of file SgUctSearch.h.
Referenced by FindBestChild(), GetValueEstimateRave(), PlayGame(), Rave(), SelectChild(), and SetRave().
bool SgUctSearch::m_raveCheckSame [private] |
See RaveCheckSame().
Definition at line 951 of file SgUctSearch.h.
Referenced by RaveCheckSame(), SetRaveCheckSame(), and UpdateRaveValues().
float SgUctSearch::m_raveWeightFinal [private] |
See Estimator weights in SgUctSearch.
Definition at line 1019 of file SgUctSearch.h.
Referenced by RaveWeightFinal(), SetRaveWeightFinal(), and StartSearch().
float SgUctSearch::m_raveWeightInitial [private] |
See Estimator weights in SgUctSearch.
Definition at line 1016 of file SgUctSearch.h.
Referenced by RaveWeightInitial(), SetRaveWeightInitial(), and StartSearch().
SgUctValue SgUctSearch::m_raveWeightParam1 [private] |
1 / m_raveWeightInitial precomputed for efficiency
Definition at line 1022 of file SgUctSearch.h.
Referenced by GetValueEstimate(), GetValueEstimateRave(), and StartSearch().
SgUctValue SgUctSearch::m_raveWeightParam2 [private] |
m_raveWeightInitial / m_raveWeightFinal precomputed for efficiency
Definition at line 1025 of file SgUctSearch.h.
Referenced by GetValueEstimate(), GetValueEstimateRave(), and StartSearch().
std::vector<SgMove> SgUctSearch::m_rootFilter [private] |
See parameter rootFilter in function Search().
Definition at line 1043 of file SgUctSearch.h.
Referenced by ApplyRootFilter(), and Search().
std::auto_ptr<boost::barrier> SgUctSearch::m_searchLoopFinished [private] |
Definition at line 938 of file SgUctSearch.h.
Referenced by CreateThreads(), and SearchLoop().
SgUctValue SgUctSearch::m_startRootMoveCount [private] |
Definition at line 995 of file SgUctSearch.h.
Referenced by GamesPlayed(), and StartSearch().
SgUctSearchStat SgUctSearch::m_statistics [private] |
Definition at line 1053 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), PlayInTree(), Search(), StartSearch(), Statistics(), UpdateCheckTimeInterval(), UpdateStatistics(), and WriteStatistics().
SgUctTree SgUctSearch::m_tempTree [private] |
std::vector<boost::shared_ptr<Thread> > SgUctSearch::m_threads [private] |
List of threads.
The elements are owned by the vector (shared_ptr is only used because auto_ptr should not be used with standard containers)
Definition at line 1058 of file SgUctSearch.h.
Referenced by CreateThreads(), DeleteThreads(), GenerateAllMoves(), Search(), SearchOnePly(), SetMaxNodes(), StartSearch(), ThreadsCreated(), and ThreadState().
std::auto_ptr<SgUctThreadStateFactory> SgUctSearch::m_threadStateFactory [private] |
Definition at line 921 of file SgUctSearch.h.
Referenced by CreateThreads(), and SetThreadStateFactory().
SgTimer SgUctSearch::m_timer [private] |
Definition at line 1035 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), OnSearchIteration(), Search(), SearchOnePly(), and StartSearch().
SgUctTree SgUctSearch::m_tree [private] |
Definition at line 1037 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), CheckCountAbort(), CheckEarlyAbort(), CreateChildren(), CreateThreads(), ExpandNode(), FindBestChild(), FindBestSequence(), GamesPlayed(), NeedToComputeKnowledge(), PlayGame(), PlayInTree(), PrintSearchProgress(), PropagateProvenStatus(), Search(), SelectChild(), SetMaxNodes(), StartSearch(), Tree(), UpdateRaveValues(), UpdateTree(), and WriteStatistics().
bool SgUctSearch::m_virtualLoss [private] |
See VirtualLoss().
Definition at line 1031 of file SgUctSearch.h.
Referenced by PlayInTree(), SetVirtualLoss(), UpdateTree(), and VirtualLoss().
bool SgUctSearch::m_wasEarlyAbort [private] |
See SgUctEarlyAbortParam.
Definition at line 941 of file SgUctSearch.h.
Referenced by CheckAbortSearch(), StartSearch(), and WasEarlyAbort().
bool SgUctSearch::m_weightRaveUpdates [private] |
See WeightRaveUpdates().
Definition at line 960 of file SgUctSearch.h.
Referenced by SetWeightRaveUpdates(), UpdateRaveValues(), and WeightRaveUpdates().