Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoUctEstimatorStat.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file GoUctEstimatorStat.cpp
00003     See GoUctEstimatorStat.h */
00004 //----------------------------------------------------------------------------
00005 
00006 #include "SgSystem.h"
00007 #include "GoUctEstimatorStat.h"
00008 
00009 #include <boost/format.hpp>
00010 #include "GoModBoard.h"
00011 #include "GoUctSearch.h"
00012 #include "SgDebug.h"
00013 #include "SgUctTreeUtil.h"
00014 
00015 using namespace std;
00016 using boost::format;
00017 
00018 //----------------------------------------------------------------------------
00019 
00020 void GoUctEstimatorStat::Compute(GoUctSearch& search,
00021                                  std::size_t trueValueMaxGames,
00022                                  std::size_t maxGames,
00023                                  std::size_t stepSize,
00024                                  const std::string& fileName)
00025 {
00026     double maxTime = numeric_limits<double>::max();
00027     vector<SgUctMoveInfo> moves;
00028     search.GenerateAllMoves(moves);
00029     SgArray<SgUctValue,SG_PASS + 1> trueValues;
00030     for (size_t i = 0; i < moves.size(); ++i)
00031     {
00032         SgPoint p = moves[i].m_move;
00033         GoModBoard modBoard(search.Board());
00034         modBoard.Board().Play(p);
00035         vector<SgMove> sequence;
00036         SgUctValue value =
00037             search.Search(SgUctValue(trueValueMaxGames), maxTime, sequence);
00038         trueValues[p] = SgUctSearch::InverseEstimate(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; // Root may not have been expanded yet
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 // 1
00064             % trueValues[p] // 2
00065             % child->MoveCount() // 3
00066             % (child->HasMean() ?
00067                SgUctSearch::InverseEstimate(child->Mean()) : 0) // 4
00068             % child->RaveCount() // 5
00069             % (child->HasRaveValue() ? child->RaveValue() : 0) // 6
00070             );
00071         }
00072     }
00073     }
00074     search.EndSearch();
00075 }
00076 
00077 //----------------------------------------------------------------------------


Sun Mar 13 2011 Doxygen 1.7.1