aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
ITestPolicy.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 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) {
61  GUM_CONSTRUCTOR(ITestPolicy);
62  }
63 
64  // ============================================================================
65  ///
66  // ============================================================================
67  virtual ~ITestPolicy() { GUM_DESTRUCTOR(ITestPolicy); }
68 
69  // ============================================================================
70  /// Allocators and Deallocators redefinition
71  // ============================================================================
72  void* operator new(size_t s) {
73  return SmallObjectAllocator::instance().allocate(s);
74  }
75  void operator delete(void* p) {
76  SmallObjectAllocator::instance().deallocate(p, sizeof(ITestPolicy));
77  }
78 
79  /// @}
80 
81 
82  // ############################################################################
83  /// @name Observation methods
84  // ############################################################################
85  /// @{
86 
87  // ============================================================================
88  /// Comptabilizes the new observation
89  // ============================================================================
90  virtual void addObservation(Idx attr, GUM_SCALAR value) {
91  isModified__ = true;
92  nbObs__++;
93  }
94 
95  // ============================================================================
96  /// Comptabilizes the new observation
97  // ============================================================================
98  Idx nbObservation() const { return nbObs__; }
99 
100  /// @}
101 
102 
103  // ############################################################################
104  /// @name Test methods
105  // ############################################################################
106  /// @{
107 
108  // ============================================================================
109  /// Returns true if enough observation were added so that the test can be
110  /// relevant
111  // ============================================================================
112  virtual bool isTestRelevant() const = 0;
113 
114  // ============================================================================
115  /// Recomputes the statistic from the beginning
116  // ============================================================================
117  virtual void computeScore() const { isModified__ = false; }
118 
119  // ============================================================================
120  /// Returns the performance of current variable according to the test
121  // ============================================================================
122  virtual double score() const = 0;
123 
124  // ============================================================================
125  /// Returns a second criterion to severe ties
126  // ============================================================================
127  virtual double secondaryscore() const = 0;
128 
129  /// @}
130 
131 
132  // ############################################################################
133  /// @name Fusion Methods
134  // ############################################################################
135  /// @{
136 
137  // ============================================================================
138  ///
139  // ============================================================================
140  void add(const ITestPolicy< GUM_SCALAR >& src) {
141  isModified__ = true;
142  nbObs__ += src.nbObservation();
143  }
144 
145  /// @}
146 
147 
148  // ############################################################################
149  /// @name Miscelleanous Methods
150  // ############################################################################
151  /// @{
152 
153  // ============================================================================
154  ///
155  // ============================================================================
156  std::string toString() const {
157  std::stringstream ss;
158  ss << "\t\t\tNb Obs : " << nbObs__ << std::endl;
159  return ss.str();
160  }
161 
162  /// @}
163 
164  protected:
165  bool isModified_() const { return isModified__; }
166 
167  private:
168  /// Booleans indicating if we have to re eval test
169  mutable bool isModified__;
170 
171  ///
173  };
174 
175 } // End of namespace gum
176 
177 #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:117
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:669
virtual void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.
Definition: ITestPolicy.h:90
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:72
<agrum/tools/multidim/core/testPolicies/ITestPolicy.h>
Definition: ITestPolicy.h:50
bool isModified_() const
Definition: ITestPolicy.h:165
virtual ~ITestPolicy()
Allocators and Deallocators redefinition.
Definition: ITestPolicy.h:67
std::string toString() const
Definition: ITestPolicy.h:156
void add(const ITestPolicy< GUM_SCALAR > &src)
Definition: ITestPolicy.h:140
void operator delete(void *p)
Allocators and Deallocators redefinition.
Definition: ITestPolicy.h:75
bool isModified__
Booleans indicating if we have to re eval test.
Definition: ITestPolicy.h:169
Idx nbObservation() const
Comptabilizes the new observation.
Definition: ITestPolicy.h:98