aGrUM  0.16.0
GTestPolicy.h
Go to the documentation of this file.
1 
30 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_G_TEST_POLICY_H
31 #define GUM_MULTI_DIM_FUNCTION_GRAPH_G_TEST_POLICY_H
32 // ============================================================================
37 // ============================================================================
38 
39 namespace gum {
40 
41  // template <typename GUM_SCALAR>
42  // using ConTab = ContingencyTable<Idx, GUM_SCALAR>;
43 
52  template < typename GUM_SCALAR >
53  class GTestPolicy : public ITestPolicy< GUM_SCALAR > {
54  public:
55  // ############################################################################
57  // ############################################################################
59 
60  // ============================================================================
62  // ============================================================================
63  GTestPolicy() : ITestPolicy< GUM_SCALAR >(), __conTab(), __GStat(0) {
64  GUM_CONSTRUCTOR(GTestPolicy);
65  }
66 
67  // ============================================================================
69  // ============================================================================
70  virtual ~GTestPolicy() { GUM_DESTRUCTOR(GTestPolicy); }
71 
72  // ============================================================================
74  // ============================================================================
75  void* operator new(size_t s) {
77  }
78 
79  void operator delete(void* p) {
81  }
82 
84 
85  // ############################################################################
87  // ############################################################################
89 
90  // ============================================================================
92  // ============================================================================
93  void addObservation(Idx iattr, GUM_SCALAR ivalue);
94 
96 
97 
98  // ############################################################################
100  // ############################################################################
102 
103  // ============================================================================
106  // ============================================================================
107  bool isTestRelevant() const {
108  return (this->nbObservation() > 20
109  && this->nbObservation() > __conTab.attrASize() * 5);
110  }
111 
112  // ============================================================================
114  // ============================================================================
115  void computeScore() const;
116 
117  // ============================================================================
119  // ============================================================================
120  double score() const;
121 
122  // ============================================================================
124  // ============================================================================
125  double secondaryscore() const;
126 
127 
129 
130 
131  // ############################################################################
133  // ############################################################################
135 
136  // ============================================================================
138  // ============================================================================
139  void add(const GTestPolicy< GUM_SCALAR >& src);
140 
141  // ============================================================================
144  // ============================================================================
146 
147 
149 
150 
151  // ############################################################################
153  // ############################################################################
155 
156  std::string toString() const {
157  std::stringstream ss;
158  ss << ITestPolicy< GUM_SCALAR >::toString()
159  << "\t\t\tContingency Table : " << std::endl
160  << __conTab.toString() << std::endl
161  << "\t\t\tGStat : " << __GStat << std::endl
162  << "\t\t\tGStat : " << this->secondaryscore() << std::endl;
163  return ss.str();
164  }
165 
167 
168  private:
171  mutable double __GStat;
172  };
173 
174 } // End of namespace gum
175 
177 
178 #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:70
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:145
std::string toString() const
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::string toString() const
Definition: GTestPolicy.h:156
ContingencyTable< Idx, GUM_SCALAR > __conTab
The contingency table used to keeps records of all observation.
Definition: GTestPolicy.h:170
<agrum/multidim/core/testPolicies/ITestPolicy.h>
Definition: ITestPolicy.h:50
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
double secondaryscore() const
Returns a second criterion to severe ties.
<agrum/multidim/core/testPolicies/GTestPolicy.h>
Definition: GTestPolicy.h:53
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:107
void add(const GTestPolicy< GUM_SCALAR > &src)
Performs the merging of current GTestPolicy instance with given instance.
GTestPolicy()
Constructor.
Definition: GTestPolicy.h:63
Size Idx
Type for indexes.
Definition: types.h:53
void * allocate(const size_t &objectSize)
Allocates a block.
Idx nbObservation() const
Comptabilizes the new observation.
Definition: ITestPolicy.h:98
Idx attrASize() const
Returns the number of samples for line iattr.
static SmallObjectAllocator & instance()