| AIToolbox
    A library that offers tools for AI problem solving. | 
 
 
 
Go to the documentation of this file.    1 #ifndef AI_TOOLBOX_POMDP_rPOMCP_GRAPH_HEADER_FILE 
    2 #define AI_TOOLBOX_POMDP_rPOMCP_GRAPH_HEADER_FILE 
    5 #include <unordered_map> 
   23     template <
bool UseEntropy>
 
   26     template <
bool UseEntropy>
 
   29     template <
bool UseEntropy>
 
   30     struct BeliefParticle : 
public std::conditional_t<UseEntropy, Impl::POMDP::BeliefParticleEntropyAddon, Impl::POMDP::EmptyStruct> {
 
   37     template <
bool UseEntropy>
 
   48     template <
bool UseEntropy>
 
   49     class BeliefNode : 
public std::conditional_t<UseEntropy, Impl::POMDP::EmptyStruct, Impl::POMDP::BeliefNodeNoEntropyAddon> {
 
   73     template <
bool UseEntropy>
 
   74     using BeliefNodes = std::unordered_map<size_t, BeliefNode<UseEntropy>>;
 
   76     template <
bool UseEntropy>
 
   97     template <
bool UseEntropy>
 
  135     template <
bool UseEntropy>
 
  138             actionsV(0.0), bestAction(0),
 
  139             knowledgeMeasure_(0.0) {}
 
  150         knowledgeMeasure_ -= trackBelief_[s].negativeEntropy;
 
  152         trackBelief_[s].N += 1;
 
  154         double p = 
static_cast<double>(trackBelief_[s].N) / 
static_cast<double>(N+1);
 
  155         double newEntropy = p * std::log(p);
 
  157         trackBelief_[s].negativeEntropy = newEntropy;
 
  158         knowledgeMeasure_ += newEntropy;
 
  164         trackBelief_[s].N += 1;
 
  166         if ( trackBelief_[s].N > trackBelief_[maxS_].N )
 
  169         knowledgeMeasure_ = 
static_cast<double>(trackBelief_[maxS_].N) / 
static_cast<double>(N+1);
 
  172     template <
bool UseEntropy>
 
  174         return knowledgeMeasure_;
 
  177     template <
bool UseEntropy>
 
  182     template <
bool UseEntropy>
 
  184             BeliefNode<UseEntropy>(), rand_(&rand), beliefSize_(beliefSize)
 
  187         std::unordered_map<size_t, unsigned> generatedSamples;
 
  190         for ( 
size_t i = 0; i < beliefSize_; ++i )
 
  193         sampleBelief_.reserve(beliefSize_);
 
  194         for ( 
auto & pair : generatedSamples ) {
 
  195             sampleBelief_.emplace_back(pair);
 
  202     template <
bool UseEntropy>
 
  204             BeliefNode<UseEntropy>(std::move(bn)), rand_(&rand), beliefSize_(0)
 
  209             sampleBelief_.emplace_back(pair.first, pair.second.N);
 
  210             beliefSize_ += pair.second.N;
 
  215     template <
bool UseEntropy>
 
  217         return sampleBelief_.empty();
 
  220     template <
bool UseEntropy>
 
  222         std::uniform_int_distribution<unsigned> generator(1, beliefSize_);
 
  223         int pick = generator(*rand_);
 
  227             pick -= sampleBelief_[index].second;
 
  228             if ( pick < 1 ) 
return sampleBelief_[index].first;
 
  233     template <
bool UseEntropy>
 
  236         size_t bestGuess; 
unsigned bestGuessCount = 0;
 
  237         for ( 
auto & pair : sampleBelief_ ) {
 
  238             if ( pair.second > bestGuessCount ) {
 
  239                 bestGuessCount = pair.second;
 
  240                 bestGuess = pair.first;
 
 
 
unsigned N
Number of particles for this particular type (state)
Definition: rPOMCPGraph.hpp:31
Definition: rPOMCPGraph.hpp:13
double negativeEntropy
Estimated entropy deriving from this particle type.
Definition: rPOMCPGraph.hpp:14
Definition: rPOMCPGraph.hpp:30