src/mcts.cpp
/*
  Relevance UCB is F-aware: Use only actions that apply to active features or according to rollout policy
*/
Relevance UCB is F-aware: Use only actions that apply to active features or according to rollout policy
Relevance UCB is F - aware : Use only actions that apply to active features or according to rollout policy
int MCTS::RelevanceUCB(VNODE *vnode, bool ucb) const
{
    static vector<int> besta;
    besta.clear();
    double bestq = -Infinity;
    int N = vnode->Value.GetCount();
    double logN = log(N + 1);
    vector<int> actions;
    vector<int> inactiveActions;
    ftable.inactiveActions(inactiveActions);
    vector<int> allActions;
    for(int i=0; i<Simulator.GetNumActions(); i++) {
        allActions.push_back(i);
    }
    std::set_difference(allActions.begin(), allActions.end(), inactiveActions.begin(), inactiveActions.end(),
            std::inserter(actions, actions.begin()));
    if(Params.Verbose >= 1){
        cout << "UCB with " << actions.size() << " actions." << endl;
    }
    int action = 0;
    for (int i = 0; i < actions.size(); i++) {
        action = actions[i];
        double q;
        int n;
        QNODE& qnode = vnode->Child(action);
        q = qnode.Value.GetValue();
        n = qnode.Value.GetCount();
        if (ucb)
            q += FastUCB(N, n, logN);
        if (q >= bestq)
        {
            if (q > bestq)
                besta.clear();
            bestq = q;
            besta.push_back(action);
        }
    }
    actions.clear();
    assert(!besta.empty());
    return besta[Random(besta.size())];
}
int MCTS :: RelevanceUCB ( VNODE * vnode , bool ucb ) const { static vector < int > besta ; besta . clear ( ) ; double bestq = - Infinity ; int N = vnode -> Value . GetCount ( ) ; double logN = log ( N + 1 ) ; vector < int > actions ; vector < int > inactiveActions ; ftable . inactiveActions ( inactiveActions ) ; vector < int > allActions ; for ( int i = 0 ; i < Simulator . GetNumActions ( ) ; i ++ ) { allActions . push_back ( i ) ; } std :: set_difference ( allActions . begin ( ) , allActions . end ( ) , inactiveActions . begin ( ) , inactiveActions . end ( ) , std :: inserter ( actions , actions . begin ( ) ) ) ; if ( Params . Verbose >= 1 ) { cout << " " << actions . size ( ) << " " << endl ; } int action = 0 ; for ( int i = 0 ; i < actions . size ( ) ; i ++ ) { action = actions [ i ] ; double q ; int n ; QNODE & qnode = vnode -> Child ( action ) ; q = qnode . Value . GetValue ( ) ; n = qnode . Value . GetCount ( ) ; if ( ucb ) q += FastUCB ( N , n , logN ) ; if ( q >= bestq ) { if ( q > bestq ) besta . clear ( ) ; bestq = q ; besta . push_back ( action ) ; } } actions . clear ( ) ; assert ( ! besta . empty ( ) ) ; return besta [ Random ( besta . size ( ) ) ] ; }
Relevance UCB is F-aware: Use only actions that apply to active features or according to rollout policy
Relevance UCB is F - aware : Use only actions that apply to active features or according to rollout policy
//Relevance option 1: sample state and obtain active actions in that state /*STATE* state = vnode->Beliefs().CreateSample(Simulator);
        Simulator.GenerateRelevant(*state, History, actions, Status);
        Simulator.FreeState(state);
         */ //Relevance option 2: eliminate actions of inactive features (safer) //cout << "Belief sample (from " << vnode->Beliefs().GetNumSamples() << "):"; //Simulator.DisplayState(*state, cout);