aGrUM  0.14.2
GTestPolicy.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_G_TEST_POLICY_H
28 #define GUM_MULTI_DIM_FUNCTION_GRAPH_G_TEST_POLICY_H
29 // ============================================================================
34 // ============================================================================
35 
36 namespace gum {
37 
38  // template <typename GUM_SCALAR>
39  // using ConTab = ContingencyTable<Idx, GUM_SCALAR>;
40 
49  template < typename GUM_SCALAR >
50  class GTestPolicy : public ITestPolicy< GUM_SCALAR > {
51  public:
52  // ############################################################################
54  // ############################################################################
56 
57  // ============================================================================
59  // ============================================================================
60  GTestPolicy() : ITestPolicy< GUM_SCALAR >(), __conTab(), __GStat(0) {
61  GUM_CONSTRUCTOR(GTestPolicy);
62  }
63 
64  // ============================================================================
66  // ============================================================================
67  virtual ~GTestPolicy() { GUM_DESTRUCTOR(GTestPolicy); }
68 
69  // ============================================================================
71  // ============================================================================
72  void* operator new(size_t s) {
74  }
75 
76  void operator delete(void* p) {
78  }
79 
81 
82  // ############################################################################
84  // ############################################################################
86 
87  // ============================================================================
89  // ============================================================================
90  void addObservation(Idx iattr, GUM_SCALAR ivalue);
91 
93 
94 
95  // ############################################################################
97  // ############################################################################
99 
100  // ============================================================================
103  // ============================================================================
104  bool isTestRelevant() const {
105  return (this->nbObservation() > 20
106  && this->nbObservation() > __conTab.attrASize() * 5);
107  }
108 
109  // ============================================================================
111  // ============================================================================
112  void computeScore() const;
113 
114  // ============================================================================
116  // ============================================================================
117  double score() const;
118 
119  // ============================================================================
121  // ============================================================================
122  double secondaryscore() const;
123 
124 
126 
127 
128  // ############################################################################
130  // ############################################################################
132 
133  // ============================================================================
135  // ============================================================================
136  void add(const GTestPolicy< GUM_SCALAR >& src);
137 
138  // ============================================================================
141  // ============================================================================
143 
144 
146 
147 
148  // ############################################################################
150  // ############################################################################
152 
153  std::string toString() const {
154  std::stringstream ss;
155  ss << ITestPolicy< GUM_SCALAR >::toString()
156  << "\t\t\tContingency Table : " << std::endl
157  << __conTab.toString() << std::endl
158  << "\t\t\tGStat : " << __GStat << std::endl
159  << "\t\t\tGStat : " << this->secondaryscore() << std::endl;
160  return ss.str();
161  }
162 
164 
165  private:
168  mutable double __GStat;
169  };
170 
171 } // End of namespace gum
172 
174 
175 #endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_G_TEST_POLICY_H */
void computeScore() const
Computes the GStat of current variable according to the test.
virtual ~GTestPolicy()
Destructor.
Definition: GTestPolicy.h:67
Template implementations for the GTestPolicy class.
void addObservation(Idx iattr, GUM_SCALAR ivalue)
Comptabilizes the new observation.
const ContingencyTable< Idx, GUM_SCALAR > & ct() const
Returns contingency table (needed for the merging of GTestPolicy instances)
Definition: GTestPolicy.h:142
std::string toString() const
Headers of the ITestPolicy.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Headers of the ChiSquare class.
std::string toString() const
Definition: GTestPolicy.h:153
ContingencyTable< Idx, GUM_SCALAR > __conTab
The contingency table used to keeps records of all observation.
Definition: GTestPolicy.h:167
<agrum/multidim/core/testPolicies/ITestPolicy.h>
Definition: ITestPolicy.h:47
Headers of the ContingencyTable class.
double secondaryscore() const
Returns a second criterion to severe ties.
<agrum/multidim/core/testPolicies/GTestPolicy.h>
Definition: GTestPolicy.h:50
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
double score() const
Returns the performance of current variable according to the test.
bool isTestRelevant() const
Returns true if enough observation were made so that the test can be relevant.
Definition: GTestPolicy.h:104
void add(const GTestPolicy< GUM_SCALAR > &src)
Performs the merging of current GTestPolicy instance with given instance.
GTestPolicy()
Constructor.
Definition: GTestPolicy.h:60
Size Idx
Type for indexes.
Definition: types.h:50
void * allocate(const size_t &objectSize)
Allocates a block.
Idx nbObservation() const
Comptabilizes the new observation.
Definition: ITestPolicy.h:95
Idx attrASize() const
Returns the number of samples for line iattr.
static SmallObjectAllocator & instance()