aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
observation.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 Headers of the Observation class.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  */
29 
30 // #define TRACE_ALGO
31 // =========================================================================
32 #ifndef GUM_OBSERVATION_H
33 #define GUM_OBSERVATION_H
34 // =========================================================================
35 #include <agrum/tools/core/hashTable.h>
36 #include <agrum/tools/core/smallobjectallocator/smallObjectAllocator.h>
37 // =========================================================================
38 #include <agrum/tools/variables/discreteVariable.h>
39 // =========================================================================
40 
41 namespace gum {
42 
43  /**
44  * @class Observation
45  * @headerfile observation.h <agrum/FMDP/learning/observation.h>
46  * @brief
47  * @ingroup fmdp_group
48  *
49  *
50  *
51  */
52 
53  class Observation {
54  public:
55  // ==========================================================================
56  /// @name Constructor & destructor.
57  // ==========================================================================
58  /// @{
59 
60  // ###################################################################
61  /// Default constructor
62  // ###################################################################
63  Observation() { GUM_CONSTRUCTOR(Observation); }
64 
65  // ###################################################################
66  /// Default destructor
67  // ###################################################################
68  ~Observation() { GUM_DESTRUCTOR(Observation); }
69 
70  // ============================================================================
71  /// Allocators and Deallocators redefinition
72  // ============================================================================
73  void* operator new(size_t s) {
74  return SmallObjectAllocator::instance().allocate(s);
75  }
76  void operator delete(void* p) {
77  SmallObjectAllocator::instance().deallocate(p, sizeof(Observation));
78  }
79 
80  /// @}
81 
82  // ==========================================================================
83  /// @name Observation Handlers
84  // ==========================================================================
85  /// @{
86 
87  // ###################################################################
88  /**
89  * Returns the modality assumed by the given variable in this observation
90  *
91  * @throws NotFound if variable is not in this observation
92  */
93  // ###################################################################
94  INLINE Idx modality(const DiscreteVariable* var) const {
95  return varInst__[var];
96  }
98  return rInst__[var];
99  }
100 
101  // ###################################################################
102  /**
103  * Sets the modality assumed by the given variable in this observation
104  *
105  * @throws DuplicateElement if a value has already be assigned to
106  * this variable
107  */
108  // ###################################################################
111  }
114  }
115 
116  // ###################################################################
117  // Returns the reward obtained during this observation
118  // ###################################################################
119  double reward() const { return reward__; }
120 
121  // ###################################################################
122  // Sets the reward obtained during this observation
123  // ###################################################################
124  void setReward(double reward) { reward__ = reward; }
125 
126  /// @}
127  ///
128  std::string toString() const;
129 
130  // ==========================================================================
131  /// @name Iterators on Variables
132  // ==========================================================================
133  /// @{
134 
135  // ###################################################################
136  /// Returns an const safe iterator on the beginning of the list of
137  /// variables in this observation
138  // ###################################################################
141  return varInst__.cbeginSafe();
142  }
143 
144  // ###################################################################
145  /// Returns an const safe iterator on the end of the list of
146  /// variables in this observation
147  // ###################################################################
150  return varInst__.cendSafe();
151  }
152 
153  /// @}
154 
155  private:
156  /// Table giving for every variables its instantiation
159 
160  /// The reward associated to this transition
161  double reward__;
162  };
163 
164 } /* namespace gum */
165 
166 
167 #endif // GUM_OBSERVATION_H
HashTable< const DiscreteVariable *, Idx > rInst__
Definition: observation.h:158
void operator delete(void *p)
Default constructor.
Definition: observation.h:76
double reward__
The reward associated to this transition.
Definition: observation.h:161
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
~Observation()
Default destructor.
Definition: observation.h:68
HashTableConstIteratorSafe< const DiscreteVariable *, Idx > cendVariablesSafe() const
Returns an const safe iterator on the end of the list of variables in this observation.
Definition: observation.h:149
Observation()
Default constructor.
Definition: observation.h:63
HashTableConstIteratorSafe< const DiscreteVariable *, Idx > cbeginVariablesSafe() const
Returns an const safe iterator on the beginning of the list of variables in this observation.
Definition: observation.h:140
std::string toString() const
Definition: observation.cpp:26
HashTable< const DiscreteVariable *, Idx > varInst__
Table giving for every variables its instantiation.
Definition: observation.h:157
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: observation.h:73