Пример #1
0
void POCMAN::DisplayBeliefs(const BELIEF_STATE& beliefState,
    ostream& ostr) const
{
    GRID<int> counts(Maze.GetXSize(), Maze.GetYSize());
    counts.SetAllValues(0);
    for (int i = 0; i < beliefState.GetNumSamples(); i++)
    {
        const POCMAN_STATE* pocstate =
            safe_cast<const POCMAN_STATE*>(
                beliefState.GetSample(i));

        for (int g = 0; g < NumGhosts; g++)
            counts(pocstate->GhostPos[g])++;
    }

    for (int y = Maze.GetYSize() - 1; y >= 0; y--)
    {
        for (int x = 0; x < Maze.GetXSize(); x++)
        {
            ostr.width(6);
            ostr.precision(2);
            ostr << fixed << (double) counts(x, y) / beliefState.GetNumSamples();
        }
        ostr << endl;
    }
}
Пример #2
0
void ROCKSAMPLE::DisplayBeliefs(const BELIEF_STATE &belief,
                                std::ostream &ostr) const {
  std::vector<double> prob(NumRocks);

  for (int i = 0; i < belief.GetNumSamples(); ++i) {
    const ROCKSAMPLE_STATE &rockstate =
        safe_cast<const ROCKSAMPLE_STATE &>(*belief.GetSample(i));

    for (int j = 0; j < NumRocks; ++j) {
      if (!rockstate.Rocks[j].Collected) {
        prob[j] += rockstate.Rocks[j].Valuable;
      }
    }
  }

  ostr << "#Belief: ";
  for (int j = 0; j < NumRocks; ++j) {
    prob[j] /= belief.GetNumSamples();

    if (prob[j] > 0.0) {
      ostr << "#" << j << "(" << prob[j] << ") ";
    }
  }
  ostr << std::endl;
}
Пример #3
0
void ROOMS::DisplayBeliefs(const BELIEF_STATE &belief, std::ostream &ostr) const {
    unordered_map<COORD, int> m;
    for (int i = 0; i < belief.GetNumSamples(); ++i) {
        const ROOMS_STATE &state =
            safe_cast<const ROOMS_STATE &>(*belief.GetSample(i));
        m[state.AgentPos] += 1;
    }

    vector<pair<double, const COORD *>> sorted;
    for (unordered_map<COORD, int>::iterator it = m.begin(); it != m.end();
            ++it) {
        double p = double(it->second) / double(belief.GetNumSamples());
        sorted.push_back(make_pair(p, &(it->first)));
    }
    sort(sorted.begin(), sorted.end(), greater<pair<double, const COORD *>>());

    ostr << "#Belief: ";
    for (uint i = 0; i < sorted.size(); ++i) {
        ostr << "#" << *(sorted[i].second) << " (" << sorted[i].first << ") ";
    }
    ostr << std::endl;
}
Пример #4
0
void GHOSTGAME::DisplayBeliefs(const BELIEF_STATE& beliefState,
                                ostream& ostr) const
{
  const GHOSTGAME_STATE* ghostGameState;
  int numGhosts = 0;
  if (beliefState.GetNumSamples() > 0)
  {
    ghostGameState = safe_cast<const GHOSTGAME_STATE*>(beliefState.GetSample(0));
    numGhosts = ghostGameState->GhostLocs.size();
  }
  
  vector<int> targetCounts(numGhosts, 0);
  for (int i = 0; i < beliefState.GetNumSamples(); i++)
  {
    ghostGameState = safe_cast<const GHOSTGAME_STATE*>(beliefState.GetSample(i));
    targetCounts[ghostGameState->TargetGhost]++;
  }
  for(unsigned int i = 0; i < targetCounts.size(); ++i) 
  {
      ostr << "Ghost " << i << ": " << (targetCounts[i] / beliefState.GetNumSamples()) << endl;
  }
}
Пример #5
0
void FlatMCTS::ParticleFilter(BELIEF_STATE &beliefs)  // unweighted particle filter
{
  int attempts = 0, added = 0;
  int max_attempts = (Params.NumStartStates - beliefs.GetNumSamples()) * 10;

  int realObs = History.Back().Observation;
  int stepObs;
  double stepReward;

  if (Params.Verbose >= 1) {
    cout << "MCTS::ParticleFilter: last step belief size "
    << Root->Beliefs().GetNumSamples() << ", current belief size "
    << beliefs.GetNumSamples() << endl;
  }

  while (beliefs.GetNumSamples() < Params.NumStartStates &&
         attempts < max_attempts) {
    STATE *state = Root->Beliefs().CreateSample(Simulator);
    Simulator.Step(*state, History.Back().Action, stepObs, stepReward);
    if (Params.ThompsonSampling) {
      Root->Child(History.Back().Action).Update(stepObs, stepReward);
    }

    if (stepObs == realObs) {
      beliefs.AddSample(state);
      added++;
    } else {
      Simulator.FreeState(state);
    }
    attempts++;
  }

  if (Params.Verbose >= 1) {
    cout << "MCTS::ParticleFilter: Created " << added
    << " local transformations out of " << attempts << " attempts" << endl;
  }
}
Пример #6
0
void FlatMCTS::AddTransforms(BELIEF_STATE &beliefs) {
  int attempts = 0, added = 0;

  if (Params.Verbose >= 1) {
    cout << "MCTS::AddTransforms: last step belief size "
    << Root->Beliefs().GetNumSamples() << ", current belief size "
    << beliefs.GetNumSamples() << endl;
  }

  // Local transformations of state that are consistent with history
  while (added < Params.NumTransforms && attempts < Params.MaxAttempts) {
    STATE *transform = CreateTransform();
    if (transform) {
      beliefs.AddSample(transform);
      added++;
    }
    attempts++;
  }

  if (Params.Verbose >= 1) {
    cout << "MCTS::AddTransforms: Created " << added
    << " local transformations out of " << attempts << " attempts" << endl;
  }
}