aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
fmdpLearner_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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, RewardAttributeSelection, LearnerSelection >::
46  FMDPLearner(double lT, bool actionReward, double sT) :
47  _actionReward_(actionReward),
48  _learningThreshold_(lT), _similarityThreshold_(sT) {
49  GUM_CONSTRUCTOR(FMDPLearner);
50  _rewardLearner_ = nullptr;
51  }
52 
53 
54  // ###################################################################
55  // Default destructor
56  // ###################################################################
63  ++actionIter) {
64  for (auto learnerIter = actionIter.val()->beginSafe();
66  ++learnerIter)
67  delete learnerIter.val();
68  delete actionIter.val();
71  }
72 
73  if (_rewardLearner_) delete _rewardLearner_;
74 
76  }
77 
78 
79  // ==========================================================================
80  //
81  // ==========================================================================
82 
83  // ###################################################################
84  //
85  // ###################################################################
90  initialize(FMDP< double >* fmdp) {
91  _fmdp_ = fmdp;
92 
93  _modaMax_ = 0;
94  _rmax_ = 0.0;
95 
97  for (auto varIter = _fmdp_->beginVariables(); varIter != _fmdp_->endVariables(); ++varIter) {
100  }
101 
103  ++actionIter) {
104  // Adding a Hashtable for the action
106 
107  // Adding a learner for each variable
108  for (auto varIter = _fmdp_->beginVariables(); varIter != _fmdp_->endVariables(); ++varIter) {
111  + " - VARIABLE : " + (*varIter)->name());
114  (*varIter),
116  }
117 
118  if (_actionReward_) {
120  reward->setTableName("REWARD - ACTION : " + _fmdp_->actionName(*actionIter));
124  }
125  }
126 
127  if (!_actionReward_) {
129  reward->setTableName("REWARD");
132  }
133  }
134 
135  // ###################################################################
136  //
137  // ###################################################################
145  ++varIter) {
148  }
149 
150  if (_actionReward_) {
153  } else {
156  }
157 
158  _rmax_ = _rmax_ < std::abs(newObs->reward()) ? std::abs(newObs->reward()) : _rmax_;
159 
160  return false;
161  }
162 
163  // ###################################################################
164  //
165  // ###################################################################
169  Size
171  Size s = 0;
174  ++actionIter) {
177  ++varIter)
180  }
181 
182  if (!_actionReward_) s += _rewardLearner_->size();
183 
184  return s;
185  }
186 
187 
188  // ###################################################################
189  //
190  // ###################################################################
198  ++actionIter) {
201  ++varIter)
204  }
205 
207  }
208 } // End of namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643