aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
observation.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 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  // ###################################################################
64  GUM_CONSTRUCTOR(Observation);
65  ;
66  }
67 
68  // ###################################################################
69  /// Default destructor
70  // ###################################################################
72  GUM_DESTRUCTOR(Observation);
73  ;
74  }
75 
76  // ============================================================================
77  /// Allocators and Deallocators redefinition
78  // ============================================================================
79  void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
80  void operator delete(void* p) {
81  SmallObjectAllocator::instance().deallocate(p, sizeof(Observation));
82  }
83 
84  /// @}
85 
86  // ==========================================================================
87  /// @name Observation Handlers
88  // ==========================================================================
89  /// @{
90 
91  // ###################################################################
92  /**
93  * Returns the modality assumed by the given variable in this observation
94  *
95  * @throws NotFound if variable is not in this observation
96  */
97  // ###################################################################
98  INLINE Idx modality(const DiscreteVariable* var) const { return _varInst_[var]; }
99  INLINE Idx rModality(const DiscreteVariable* var) const { return _rInst_[var]; }
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  // ###################################################################
140  return _varInst_.cbeginSafe();
141  }
142 
143  // ###################################################################
144  /// Returns an const safe iterator on the end of the list of
145  /// variables in this observation
146  // ###################################################################
148  return _varInst_.cendSafe();
149  }
150 
151  /// @}
152 
153  private:
154  /// Table giving for every variables its instantiation
157 
158  /// The reward associated to this transition
159  double _reward_;
160  };
161 
162 } /* namespace gum */
163 
164 
165 #endif // GUM_OBSERVATION_H
void operator delete(void *p)
Default constructor.
Definition: observation.h:80
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
~Observation()
Default destructor.
Definition: observation.h:71
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:147
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:139
HashTable< const DiscreteVariable *, Idx > _varInst_
Table giving for every variables its instantiation.
Definition: observation.h:155
std::string toString() const
Definition: observation.cpp:26
HashTable< const DiscreteVariable *, Idx > _rInst_
Definition: observation.h:156
double _reward_
The reward associated to this transition.
Definition: observation.h:159
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: observation.h:79