aGrUM  0.14.2
Chi2TestPolicy.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_CHI2_TEST_POLICY_H
28 #define GUM_MULTI_DIM_FUNCTION_GRAPH_CHI2_TEST_POLICY_H
29 
30 // ============================================================================
34 // ============================================================================
35 
36 namespace gum {
37 
47  template < typename GUM_SCALAR >
48  class Chi2TestPolicy : public ITestPolicy< GUM_SCALAR > {
49  public:
50  Chi2TestPolicy() : ITestPolicy< GUM_SCALAR >(), __conTab(), __chi2Score(0) {
51  GUM_CONSTRUCTOR(Chi2TestPolicy);
52  }
53 
54  virtual ~Chi2TestPolicy() { GUM_DESTRUCTOR(Chi2TestPolicy); }
55 
56  // ============================================================================
58  // ============================================================================
59  void* operator new(size_t s) {
61  }
62  void operator delete(void* p) {
64  }
65 
66  // ############################################################################
68  // ############################################################################
70 
71  // ============================================================================
73  // ============================================================================
74  void addObservation(Idx attr, GUM_SCALAR value);
75 
77 
78 
79  // ############################################################################
81  // ############################################################################
83 
84  // ============================================================================
87  // ============================================================================
88  bool isTestRelevant() const {
89  return (this->nbObservation() > 20
90  && this->nbObservation() > __conTab.attrASize() * 5);
91  }
92 
94 
95 
96  // ############################################################################
98  // ############################################################################
100 
101  // ============================================================================
103  // ============================================================================
104  void computeScore() const;
105 
106  // ============================================================================
108  // ============================================================================
109  double score() const;
110 
111  // ============================================================================
113  // ============================================================================
114  virtual double secondaryscore() const;
115 
117 
119 
120  void add(const Chi2TestPolicy< GUM_SCALAR >& src);
121 
122  std::string toString() const {
123  std::stringstream ss;
124  ss << ITestPolicy< GUM_SCALAR >::toString()
125  << "\t\t\tContingency Table : " << std::endl
126  << __conTab.toString() << std::endl
127  << "\t\t\tGStat : " << this->score() << std::endl
128  << "\t\t\tGStat : " << this->secondaryscore() << std::endl;
129  return ss.str();
130  }
131 
132  private:
135 
136  mutable double __chi2Score;
137  };
138 
139 } // End of namespace gum
140 
142 
143 #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
Headers of the ITestPolicy.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
<agrum/multidim/core/testPolicy/Chi2TestPolicy.h>
Headers of the ChiSquare class.
<agrum/multidim/core/testPolicies/ITestPolicy.h>
Definition: ITestPolicy.h:47
const ContingencyTable< Idx, GUM_SCALAR > & ct() const
Template implementations for the Chi2TestPolicy class.
Headers of the ContingencyTable class.
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: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()
ContingencyTable< Idx, GUM_SCALAR > __conTab
The contingency table used to keeps records of all observation.
std::string toString() const