aGrUM  0.16.0
Chi2TestPolicy.h
Go to the documentation of this file.
1 
30 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_CHI2_TEST_POLICY_H
31 #define GUM_MULTI_DIM_FUNCTION_GRAPH_CHI2_TEST_POLICY_H
32 
33 // ============================================================================
37 // ============================================================================
38 
39 namespace gum {
40 
50  template < typename GUM_SCALAR >
51  class Chi2TestPolicy : public ITestPolicy< GUM_SCALAR > {
52  public:
53  Chi2TestPolicy() : ITestPolicy< GUM_SCALAR >(), __conTab(), __chi2Score(0) {
54  GUM_CONSTRUCTOR(Chi2TestPolicy);
55  }
56 
57  virtual ~Chi2TestPolicy() { GUM_DESTRUCTOR(Chi2TestPolicy); }
58 
59  // ============================================================================
61  // ============================================================================
62  void* operator new(size_t s) {
64  }
65  void operator delete(void* p) {
67  }
68 
69  // ############################################################################
71  // ############################################################################
73 
74  // ============================================================================
76  // ============================================================================
77  void addObservation(Idx attr, GUM_SCALAR value);
78 
80 
81 
82  // ############################################################################
84  // ############################################################################
86 
87  // ============================================================================
90  // ============================================================================
91  bool isTestRelevant() const {
92  return (this->nbObservation() > 20
93  && this->nbObservation() > __conTab.attrASize() * 5);
94  }
95 
97 
98 
99  // ############################################################################
101  // ############################################################################
103 
104  // ============================================================================
106  // ============================================================================
107  void computeScore() const;
108 
109  // ============================================================================
111  // ============================================================================
112  double score() const;
113 
114  // ============================================================================
116  // ============================================================================
117  virtual double secondaryscore() const;
118 
120 
122 
123  void add(const Chi2TestPolicy< GUM_SCALAR >& src);
124 
125  std::string toString() const {
126  std::stringstream ss;
127  ss << ITestPolicy< GUM_SCALAR >::toString()
128  << "\t\t\tContingency Table : " << std::endl
129  << __conTab.toString() << std::endl
130  << "\t\t\tGStat : " << this->score() << std::endl
131  << "\t\t\tGStat : " << this->secondaryscore() << std::endl;
132  return ss.str();
133  }
134 
135  private:
138 
139  mutable double __chi2Score;
140  };
141 
142 } // End of namespace gum
143 
145 
146 #endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_CHI2_TEST_POLICY_H */
void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.
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
<agrum/multidim/core/testPolicy/Chi2TestPolicy.h>
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/multidim/core/testPolicies/ITestPolicy.h>
Definition: ITestPolicy.h:50
const ContingencyTable< Idx, GUM_SCALAR > & ct() 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.
virtual double secondaryscore() const
Returns a second criterion to severe ties.
void add(const Chi2TestPolicy< GUM_SCALAR > &src)
virtual ~Chi2TestPolicy()
void computeScore() const
Recomputes the statistic from the beginning.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
bool isTestRelevant() const
Returns true if enough observation were made so that the test can be relevant.
double score() const
Returns the performance of current variable according to the test.
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()
ContingencyTable< Idx, GUM_SCALAR > __conTab
The contingency table used to keeps records of all observation.
std::string toString() const