1 #ifndef AI_TOOLBOX_POMDP_PROJECTER_HEADER_FILE
2 #define AI_TOOLBOX_POMDP_PROJECTER_HEADER_FILE
49 using PossibleObservationsTable = boost::multi_array<bool, 2>;
54 void computePossibleObservations();
59 void computeImmediateRewards();
66 PossibleObservationsTable possibleObservations_;
71 model_(model), S(model_.getS()), A(model_.getA()), O(model_.getO()),
72 discount_(model_.getDiscount()), possibleObservations_(boost::extents[A][O])
74 computePossibleObservations();
75 computeImmediateRewards();
82 for (
size_t a = 0; a < A; ++a )
83 projections[a] =
operator()(w, a);
92 for (
size_t o = 0; o < O; ++o ) {
96 if ( !possibleObservations_[a][o] ) {
101 projections[o].emplace_back(immediateRewards_.row(a), a,
VObs(1,0));
107 for (
size_t i = 0; i < w.size(); ++i ) {
108 const auto & v = w[i].values;
112 if constexpr(IsModelEigen<M>) {
113 vproj = model_.getTransitionFunction(a) * (v.cwiseProduct(model_.getObservationFunction(a).col(o)));
116 for (
size_t s = 0; s < S; ++s )
117 for (
size_t s1 = 0; s1 < S; ++s1 )
118 vproj[s] += model_.getTransitionProbability(s,a,s1) * model_.getObservationProbability(s1,a,o) * v[s1];
122 projections[o].emplace_back(vproj * discount_ + immediateRewards_.row(a).transpose(), a,
VObs(1,i));
130 immediateRewards_ = [&]{
131 if constexpr(MDP::IsModelEigen<M>)
132 return model_.getRewardFunction().transpose();
138 immediateRewards_ /=
static_cast<double>(O);
142 void Projecter<M>::computePossibleObservations() {
143 for (
size_t a = 0; a < A; ++a )
144 for (
size_t o = 0; o < O; ++o )
145 for (
size_t s = 0; s < S; ++s )
146 if (
checkDifferentSmall(model_.getObservationProbability(s,a,o), 0.0) ) { possibleObservations_[a][o] =
true;
break; }