aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
ITestPolicy.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 ITestPolicy
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  *
29  */
30 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_INTERFACE_TEST_POLICY_H
31 #define GUM_MULTI_DIM_FUNCTION_GRAPH_INTERFACE_TEST_POLICY_H
32 
33 // ============================================================================
34 #include <agrum/tools/core/smallobjectallocator/smallObjectAllocator.h>
35 // ============================================================================
36 #include <agrum/tools/graphs/parts/nodeGraphPart.h>
37 // ============================================================================
38 
39 namespace gum {
40 
41  /**
42  * @class ITestPolicy ITestPolicy.h
43  * <agrum/tools/multidim/core/testPolicies/ITestPolicy.h>
44  *
45  * @brief Interface specifying the methods to be implemented by any TestPolicy
46  *
47  * @ingroup fmdp_group
48  */
49  template < typename GUM_SCALAR >
50  class ITestPolicy {
51  public:
52  // ############################################################################
53  /// @name Constructor/Destructor
54  // ############################################################################
55  /// @{
56 
57  // ============================================================================
58  ///
59  // ============================================================================
60  ITestPolicy() : _isModified_(false), _nbObs_(0) { GUM_CONSTRUCTOR(ITestPolicy); }
61 
62  // ============================================================================
63  ///
64  // ============================================================================
65  virtual ~ITestPolicy() {
66  GUM_DESTRUCTOR(ITestPolicy);
67  ;
68  }
69 
70  // ============================================================================
71  /// Allocators and Deallocators redefinition
72  // ============================================================================
73  void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
74  void operator delete(void* p) {
75  SmallObjectAllocator::instance().deallocate(p, sizeof(ITestPolicy));
76  }
77 
78  /// @}
79 
80 
81  // ############################################################################
82  /// @name Observation methods
83  // ############################################################################
84  /// @{
85 
86  // ============================================================================
87  /// Comptabilizes the new observation
88  // ============================================================================
89  virtual void addObservation(Idx attr, GUM_SCALAR value) {
90  _isModified_ = true;
91  _nbObs_++;
92  }
93 
94  // ============================================================================
95  /// Comptabilizes the new observation
96  // ============================================================================
97  Idx nbObservation() const { return _nbObs_; }
98 
99  /// @}
100 
101 
102  // ############################################################################
103  /// @name Test methods
104  // ############################################################################
105  /// @{
106 
107  // ============================================================================
108  /// Returns true if enough observation were added so that the test can be
109  /// relevant
110  // ============================================================================
111  virtual bool isTestRelevant() const = 0;
112 
113  // ============================================================================
114  /// Recomputes the statistic from the beginning
115  // ============================================================================
116  virtual void computeScore() const { _isModified_ = false; }
117 
118  // ============================================================================
119  /// Returns the performance of current variable according to the test
120  // ============================================================================
121  virtual double score() const = 0;
122 
123  // ============================================================================
124  /// Returns a second criterion to severe ties
125  // ============================================================================
126  virtual double secondaryscore() const = 0;
127 
128  /// @}
129 
130 
131  // ############################################################################
132  /// @name Fusion Methods
133  // ############################################################################
134  /// @{
135 
136  // ============================================================================
137  ///
138  // ============================================================================
139  void add(const ITestPolicy< GUM_SCALAR >& src) {
140  _isModified_ = true;
141  _nbObs_ += src.nbObservation();
142  }
143 
144  /// @}
145 
146 
147  // ############################################################################
148  /// @name Miscelleanous Methods
149  // ############################################################################
150  /// @{
151 
152  // ============================================================================
153  ///
154  // ============================================================================
155  std::string toString() const {
156  std::stringstream ss;
157  ss << "\t\t\tNb Obs : " << _nbObs_ << std::endl;
158  return ss.str();
159  }
160 
161  /// @}
162 
163  protected:
164  bool isModified_() const { return _isModified_; }
165 
166  private:
167  /// Booleans indicating if we have to re eval test
168  mutable bool _isModified_;
169 
170  ///
172  };
173 
174 } // End of namespace gum
175 
176 #endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_INTERFACE_TEST_POLICY_H */
virtual double score() const =0
Returns the performance of current variable according to the test.
virtual void computeScore() const
Recomputes the statistic from the beginning.
Definition: ITestPolicy.h:116
virtual bool isTestRelevant() const =0
Returns true if enough observation were added so that the test can be relevant.
ITestPolicy()
Allocators and Deallocators redefinition.
Definition: ITestPolicy.h:60
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
virtual void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.
Definition: ITestPolicy.h:89
virtual double secondaryscore() const =0
Returns a second criterion to severe ties.
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: ITestPolicy.h:73
<agrum/tools/multidim/core/testPolicies/ITestPolicy.h>
Definition: ITestPolicy.h:50
bool isModified_() const
Definition: ITestPolicy.h:164
virtual ~ITestPolicy()
Allocators and Deallocators redefinition.
Definition: ITestPolicy.h:65
std::string toString() const
Definition: ITestPolicy.h:155
bool _isModified_
Booleans indicating if we have to re eval test.
Definition: ITestPolicy.h:168
void add(const ITestPolicy< GUM_SCALAR > &src)
Definition: ITestPolicy.h:139
void operator delete(void *p)
Allocators and Deallocators redefinition.
Definition: ITestPolicy.h:74
Idx nbObservation() const
Comptabilizes the new observation.
Definition: ITestPolicy.h:97