aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
leastSquareTestPolicy.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 LeastSquareTestPolicy
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_LEAST_SQUARE_TEST_POLICY_H
31 #define GUM_MULTI_DIM_FUNCTION_GRAPH_LEAST_SQUARE_TEST_POLICY_H
32 
33 // ============================================================================
34 #include <agrum/FMDP/learning/core/contingencyTable.h>
35 #include <agrum/FMDP/learning/core/testPolicy/ITestPolicy.h>
36 // ============================================================================
37 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/link.h>
38 // ============================================================================
39 
40 namespace gum {
41 
42  /**
43  * @class LeastSquareTestPolicy leastSquareTestPolicy.h
44  * <agrum/tools/multidim/core/testPolicy/leastSquareTestPolicy.h>
45  *
46  * @brief LeastSquareTestPolicy implements a test policy that follows the
47  * Least Square statistic
48  *
49  * @ingroup fmdp_group
50  */
51  template < typename GUM_SCALAR >
53  public:
54  // ############################################################################
55  /// @name Constructor/Destrcutor
56  // ############################################################################
57  /// @{
58 
59  // ============================================================================
60  /// Constructor
61  // ============================================================================
63  GUM_CONSTRUCTOR(LeastSquareTestPolicy);
64  }
65 
66  // ============================================================================
67  /// Allocators and Deallocators redefinition
68  // ============================================================================
69  void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
70  void operator delete(void* p) {
71  SmallObjectAllocator::instance().deallocate(p, sizeof(LeastSquareTestPolicy));
72  }
73 
74  // ============================================================================
75  /// Destructor
76  // ============================================================================
77  virtual ~LeastSquareTestPolicy();
78 
79  // ############################################################################
80  /// @name Observation insertion
81  // ############################################################################
82  /// @{
83 
84  // ============================================================================
85  /// Comptabilizes the new observation
86  // ============================================================================
87  void addObservation(Idx attr, GUM_SCALAR value);
88 
89  /// @}
90 
91 
92  // ############################################################################
93  /// @name Test relevance
94  // ############################################################################
95  /// @{
96 
97  // ============================================================================
98  /// Returns true if enough observation were made so that the test can be
99  /// relevant
100  // ============================================================================
101  bool isTestRelevant() const { return (this->nbObservation() > 20); }
102 
103  /// @}
104 
105 
106  // ############################################################################
107  /// @name Test result
108  // ############################################################################
109  /// @{
110 
111  // ============================================================================
112  /// Returns the performance of current variable according to the test
113  // ============================================================================
114  void computeScore();
115 
116  // ============================================================================
117  /// Returns the performance of current variable according to the test
118  // ============================================================================
119  double score();
120 
121  // ============================================================================
122  /// Returns a second criterion to severe ties
123  // ============================================================================
124  double secondaryscore() const;
125 
126  /// @}
127 
128 
129  // ############################################################################
130  /// @name Fusion Methods
131  // ############################################################################
132  /// @{
133 
134  // ============================================================================
135  /// Performs the merging of current LeastSquareTestPolicy instance with
136  /// given instance
137  // ============================================================================
138  void add(const LeastSquareTestPolicy< GUM_SCALAR >& src);
139 
140 
141  // ============================================================================
142  /// Returns global sum (needed for the merging)
143  // ============================================================================
144  double sumValue() const { return _sumO_; }
145 
146  // ============================================================================
147  /// Returns nbobs per modality table (needed for the merging)
148  // ============================================================================
149  const HashTable< Idx, Idx >& nbObsTable() const { return _nbObsTable_; }
150 
151  // ============================================================================
152  /// Returns sum per modality table (needed for the merging)
153  // ============================================================================
154  const HashTable< Idx, double >& sumAttrTable() const { return _sumAttrTable_; }
155 
156  // ============================================================================
157  /// Returns global sum (needed for the merging)
158  // ============================================================================
159  const HashTable< Idx, LinkedList< double >* >& obsTable() const { return _obsTable_; }
160 
161  private:
162  /// Global sum
163  double _sumO_;
164 
165  /// Nb Observation for each modality assumed by variable
167 
168  /// Sum for each modality assumed by variable
170 
171  /// Not sure if needed
173 
174  /// Keeping computed score
175  double _score_;
176  };
177 
178 } // End of namespace gum
179 
180 #include <agrum/FMDP/learning/core/testPolicy/leastSquareTestPolicy_tpl.h>
181 
182 #endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_LEAST_SQUARE_TEST_POLICY_H */
const HashTable< Idx, LinkedList< double > *> & obsTable() const
Returns global sum (needed for the merging)
double score()
Returns the performance of current variable according to the test.
void operator delete(void *p)
Constructor.
const HashTable< Idx, Idx > & nbObsTable() const
Returns nbobs per modality table (needed for the merging)
virtual ~LeastSquareTestPolicy()
Destructor.
double secondaryscore() const
Returns a second criterion to severe ties.
const HashTable< Idx, double > & sumAttrTable() const
Returns sum per modality table (needed for the merging)
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
double _score_
Keeping computed score.
void add(const LeastSquareTestPolicy< GUM_SCALAR > &src)
Performs the merging of current LeastSquareTestPolicy instance with given instance.
double sumValue() const
Returns global sum (needed for the merging)
bool isTestRelevant() const
Returns true if enough observation were made so that the test can be relevant.
void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.
HashTable< Idx, Idx > _nbObsTable_
Nb Observation for each modality assumed by variable.
void computeScore()
Returns the performance of current variable according to the test.
void * operator new(size_t s)
Allocators and Deallocators redefinition.
HashTable< Idx, double > _sumAttrTable_
Sum for each modality assumed by variable.