00001
00002
00003
00004
00005
00006
00007 #include "SgSystem.h"
00008 #include "GoUctEstimatorStat.h"
00009
00010 #include <boost/format.hpp>
00011 #include "GoModBoard.h"
00012 #include "GoUctSearch.h"
00013 #include "SgDebug.h"
00014 #include "SgUctTreeUtil.h"
00015
00016 using namespace std;
00017 using boost::format;
00018
00019
00020
00021 void GoUctEstimatorStat::Compute(GoUctSearch& search,
00022 std::size_t trueValueMaxGames,
00023 std::size_t maxGames,
00024 std::size_t stepSize,
00025 const std::string& fileName)
00026 {
00027 double maxTime = numeric_limits<double>::max();
00028 vector<SgMoveInfo> moves;
00029 search.GenerateAllMoves(moves);
00030 SgArray<float,SG_PASS + 1> trueValues;
00031 for (size_t i = 0; i < moves.size(); ++i)
00032 {
00033 SgPoint p = moves[i].m_move;
00034 GoModBoard modBoard(search.Board());
00035 modBoard.Board().Play(p);
00036 vector<SgMove> sequence;
00037 float value = search.Search(trueValueMaxGames, maxTime, sequence);
00038 trueValues[p] = SgUctSearch::InverseEval(value);
00039 modBoard.Board().Undo();
00040 }
00041 search.StartSearch();
00042 if (search.MpiSynchronizer()->IsRootProcess())
00043 {
00044 ofstream out(fileName.c_str(), ios::app);
00045 for (size_t n = 0; n < maxGames; n += stepSize)
00046 {
00047 search.PlayGame();
00048 for (size_t i = 0; i < moves.size(); ++i)
00049 {
00050 SgPoint p = moves[i].m_move;
00051 const SgUctTree& tree = search.Tree();
00052 const SgUctNode* child =
00053 SgUctTreeUtil::FindChildWithMove(tree, tree.Root(), p);
00054 if (child == 0)
00055 continue;
00056 out << (format("%1$d\t"
00057 "%2$.2f\t"
00058 "%3$d\t"
00059 "%4$.2f\t"
00060 "%5$d\t"
00061 "%6$.2f\n"
00062 )
00063 % n
00064 % trueValues[p]
00065 % child->MoveCount()
00066 % (child->HasMean() ?
00067 SgUctSearch::InverseEval(child->Mean()) : 0)
00068 % child->RaveCount()
00069 % (child->HasRaveValue() ? child->RaveValue() : 0)
00070 );
00071 }
00072 }
00073 }
00074 search.EndSearch();
00075 }
00076
00077