aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
fmdpLearner_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Template Implementations of the FMDPLearner class.
25  *
26  * @author Jean-Christophe MAGNAN
27  */
28 
29 // =========================================================================
30 #include <agrum/FMDP/learning/fmdpLearner.h>
31 // =========================================================================
32 
33 namespace gum {
34 
35  // ==========================================================================
36  // Constructor & destructor.
37  // ==========================================================================
38 
39  // ###################################################################
40  // Default constructor
41  // ###################################################################
42  template < TESTNAME VariableAttributeSelection,
43  TESTNAME RewardAttributeSelection,
44  LEARNERNAME LearnerSelection >
45  FMDPLearner< VariableAttributeSelection,
46  RewardAttributeSelection,
47  LearnerSelection >::FMDPLearner(double lT,
48  bool actionReward,
49  double sT) :
50  actionReward__(actionReward),
51  learningThreshold__(lT), similarityThreshold__(sT) {
52  GUM_CONSTRUCTOR(FMDPLearner);
53  rewardLearner__ = nullptr;
54  }
55 
56 
57  // ###################################################################
58  // Default destructor
59  // ###################################################################
68  ++actionIter) {
69  for (auto learnerIter = actionIter.val()->beginSafe();
71  ++learnerIter)
72  delete learnerIter.val();
73  delete actionIter.val();
76  }
77 
78  if (rewardLearner__) delete rewardLearner__;
79 
81  }
82 
83 
84  // ==========================================================================
85  //
86  // ==========================================================================
87 
88  // ###################################################################
89  //
90  // ###################################################################
97  fmdp__ = fmdp;
98 
99  modaMax__ = 0;
100  rmax__ = 0.0;
101 
103  for (auto varIter = fmdp__->beginVariables();
105  ++varIter) {
108  : modaMax__;
109  }
110 
111  for (auto actionIter = fmdp__->beginActions();
113  ++actionIter) {
114  // Adding a Hashtable for the action
116 
117  // Adding a learner for each variable
118  for (auto varIter = fmdp__->beginVariables();
120  ++varIter) {
123  + " - VARIABLE : " + (*varIter)->name());
126  (*varIter),
130  }
131 
132  if (actionReward__) {
134  reward->setTableName("REWARD - ACTION : "
138  *actionIter,
140  }
141  }
142 
143  if (!actionReward__) {
145  reward->setTableName("REWARD");
148  }
149  }
150 
151  // ###################################################################
152  //
153  // ###################################################################
160  const Observation* newObs) {
162  = fmdp__->beginVariables();
164  ++varIter) {
166  ->getWithDefault(*varIter, nullptr)
169  }
170 
171  if (actionReward__) {
174  } else {
177  }
178 
179  rmax__
180  = rmax__ < std::abs(newObs->reward()) ? std::abs(newObs->reward()) : rmax__;
181 
182  return false;
183  }
184 
185  // ###################################################################
186  //
187  // ###################################################################
194  Size s = 0;
197  ++actionIter) {
199  = fmdp__->beginVariables();
201  ++varIter)
203  ->getWithDefault(*varIter, nullptr)
204  ->size();
206  }
207 
208  if (!actionReward__) s += rewardLearner__->size();
209 
210  return s;
211  }
212 
213 
214  // ###################################################################
215  //
216  // ###################################################################
225  ++actionIter) {
227  = fmdp__->beginVariables();
229  ++varIter)
231  ->getWithDefault(*varIter, nullptr)
233  if (actionReward__)
235  }
236 
238  }
239 } // End of namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669