aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::Chi2TestPolicy< GUM_SCALAR > Class Template Reference

<agrum/base/multidim/core/testPolicy/Chi2TestPolicy.h> More...

#include <Chi2TestPolicy.h>

Inheritance diagram for gum::Chi2TestPolicy< GUM_SCALAR >:
Collaboration diagram for gum::Chi2TestPolicy< GUM_SCALAR >:

Public Member Functions

 Chi2TestPolicy ()
virtual ~Chi2TestPolicy ()
void * operator new (size_t s)
 Allocators and Deallocators redefinition.
void operator delete (void *p)
const ContingencyTable< Idx, GUM_SCALAR > & ct () const
void add (const Chi2TestPolicy< GUM_SCALAR > &src)
std::string toString () const
Observation insertion
void addObservation (Idx attr, GUM_SCALAR value)
 Comptabilizes the new observation.
Test relevance
bool isTestRelevant () const
 Returns true if enough observation were made so that the test can be relevant.
Test result
void computeScore () const
 Recomputes the statistic from the beginning.
double score () const
 Returns the performance of current variable according to the test.
virtual double secondaryscore () const
 Returns a second criterion to severe ties.
Observation methods
Idx nbObservation () const
 Comptabilizes the new observation.
Fusion Methods
void add (const ITestPolicy< GUM_SCALAR > &src)

Protected Member Functions

bool isModified_ () const

Private Attributes

ContingencyTable< Idx, GUM_SCALAR > _conTab_
 The contingency table used to keeps records of all observation.
double _chi2Score_
bool _isModified_
 Booleans indicating if we have to re eval test.
Idx _nbObs_

Detailed Description

template<typename GUM_SCALAR>
class gum::Chi2TestPolicy< GUM_SCALAR >

<agrum/base/multidim/core/testPolicy/Chi2TestPolicy.h>

Chi2TestPolicy implements a test policy that follows the Chi2 statistic

Definition at line 72 of file Chi2TestPolicy.h.

Constructor & Destructor Documentation

◆ Chi2TestPolicy()

template<typename GUM_SCALAR>
gum::Chi2TestPolicy< GUM_SCALAR >::Chi2TestPolicy ( )
inline

Definition at line 74 of file Chi2TestPolicy.h.

76 }
<agrum/base/multidim/core/testPolicy/Chi2TestPolicy.h>
ContingencyTable< Idx, GUM_SCALAR > _conTab_
The contingency table used to keeps records of all observation.
ITestPolicy()
Allocators and Deallocators redefinition.
Definition ITestPolicy.h:81

References Chi2TestPolicy(), gum::ITestPolicy< GUM_SCALAR >::ITestPolicy(), _chi2Score_, and _conTab_.

Referenced by Chi2TestPolicy(), ~Chi2TestPolicy(), add(), and operator delete().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Chi2TestPolicy()

template<typename GUM_SCALAR>
virtual gum::Chi2TestPolicy< GUM_SCALAR >::~Chi2TestPolicy ( )
inlinevirtual

Definition at line 78 of file Chi2TestPolicy.h.

78 {
80 ;
81 }

References Chi2TestPolicy().

Here is the call graph for this function:

Member Function Documentation

◆ add() [1/2]

template<typename GUM_SCALAR>
void gum::Chi2TestPolicy< GUM_SCALAR >::add ( const Chi2TestPolicy< GUM_SCALAR > & src)

Definition at line 118 of file Chi2TestPolicy_tpl.h.

118 {
120 _conTab_ += src.ct();
121 }
const ContingencyTable< Idx, GUM_SCALAR > & ct() const
void add(const ITestPolicy< GUM_SCALAR > &src)

References Chi2TestPolicy(), _conTab_, gum::ITestPolicy< GUM_SCALAR >::add(), and ct().

Here is the call graph for this function:

◆ add() [2/2]

template<typename GUM_SCALAR>
void gum::ITestPolicy< GUM_SCALAR >::add ( const ITestPolicy< GUM_SCALAR > & src)
inlineinherited

Definition at line 161 of file ITestPolicy.h.

161 {
162 _isModified_ = true;
164 }
<agrum/base/multidim/core/testPolicies/ITestPolicy.h>
Definition ITestPolicy.h:71
Idx nbObservation() const
Comptabilizes the new observation.
bool _isModified_
Booleans indicating if we have to re eval test.

References ITestPolicy(), _isModified_, _nbObs_, and nbObservation().

Referenced by gum::Chi2TestPolicy< GUM_SCALAR >::add(), gum::GTestPolicy< GUM_SCALAR >::add(), and gum::LeastSquareTestPolicy< GUM_SCALAR >::add().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addObservation()

template<typename GUM_SCALAR>
void gum::Chi2TestPolicy< GUM_SCALAR >::addObservation ( Idx attr,
GUM_SCALAR value )
virtual

Comptabilizes the new observation.

Reimplemented from gum::ITestPolicy< GUM_SCALAR >.

Definition at line 66 of file Chi2TestPolicy_tpl.h.

66 {
68 _conTab_.add(iattr, ivalue);
69 }
virtual void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.

References _conTab_, and gum::ITestPolicy< GUM_SCALAR >::addObservation().

Here is the call graph for this function:

◆ computeScore()

template<typename GUM_SCALAR>
void gum::Chi2TestPolicy< GUM_SCALAR >::computeScore ( ) const
virtual

Recomputes the statistic from the beginning.

Reimplemented from gum::ITestPolicy< GUM_SCALAR >.

Definition at line 79 of file Chi2TestPolicy_tpl.h.

79 {
81 _chi2Score_ = 0;
82 for (auto attrIter = _conTab_.attrABeginSafe(); attrIter != _conTab_.attrAEndSafe();
83 ++attrIter) {
84 double semiExpected = (double)(attrIter.val()) / (double)this->nbObservation();
85 for (auto valIter = _conTab_.attrBBeginSafe(); valIter != _conTab_.attrBEndSafe();
86 ++valIter) {
87 double cell = (double)_conTab_.joint(attrIter.key(), valIter.key());
88 if (cell < 5) continue;
89 double expected = semiExpected * (double)(valIter.val());
90
92 }
93 }
94 }
virtual void computeScore() const
Recomputes the statistic from the beginning.

References _chi2Score_, _conTab_, gum::ITestPolicy< GUM_SCALAR >::computeScore(), and gum::ITestPolicy< GUM_SCALAR >::nbObservation().

Referenced by score(), and secondaryscore().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ct()

template<typename GUM_SCALAR>
const ContingencyTable< Idx, GUM_SCALAR > & gum::Chi2TestPolicy< GUM_SCALAR >::ct ( ) const
inline

Definition at line 143 of file Chi2TestPolicy.h.

143{ return _conTab_; }

References _conTab_.

Referenced by add().

Here is the caller graph for this function:

◆ isModified_()

template<typename GUM_SCALAR>
bool gum::ITestPolicy< GUM_SCALAR >::isModified_ ( ) const
inlineprotectedinherited

Definition at line 186 of file ITestPolicy.h.

186{ return _isModified_; }

References _isModified_.

Referenced by gum::Chi2TestPolicy< GUM_SCALAR >::score(), gum::GTestPolicy< GUM_SCALAR >::score(), gum::LeastSquareTestPolicy< GUM_SCALAR >::score(), gum::Chi2TestPolicy< GUM_SCALAR >::secondaryscore(), gum::GTestPolicy< GUM_SCALAR >::secondaryscore(), and gum::LeastSquareTestPolicy< GUM_SCALAR >::secondaryscore().

Here is the caller graph for this function:

◆ isTestRelevant()

template<typename GUM_SCALAR>
bool gum::Chi2TestPolicy< GUM_SCALAR >::isTestRelevant ( ) const
inlinevirtual

Returns true if enough observation were made so that the test can be relevant.

Implements gum::ITestPolicy< GUM_SCALAR >.

Definition at line 114 of file Chi2TestPolicy.h.

114 {
115 return (this->nbObservation() > 20 && this->nbObservation() > _conTab_.attrASize() * 5);
116 }

References _conTab_, and gum::ITestPolicy< GUM_SCALAR >::nbObservation().

Here is the call graph for this function:

◆ nbObservation()

template<typename GUM_SCALAR>
Idx gum::ITestPolicy< GUM_SCALAR >::nbObservation ( ) const
inlineinherited

Comptabilizes the new observation.

Definition at line 119 of file ITestPolicy.h.

119{ return _nbObs_; }

References _nbObs_.

Referenced by add(), gum::Chi2TestPolicy< GUM_SCALAR >::computeScore(), gum::GTestPolicy< GUM_SCALAR >::computeScore(), gum::LeastSquareTestPolicy< GUM_SCALAR >::computeScore(), gum::Chi2TestPolicy< GUM_SCALAR >::isTestRelevant(), gum::GTestPolicy< GUM_SCALAR >::isTestRelevant(), and gum::LeastSquareTestPolicy< GUM_SCALAR >::isTestRelevant().

Here is the caller graph for this function:

◆ operator delete()

template<typename GUM_SCALAR>
void gum::Chi2TestPolicy< GUM_SCALAR >::operator delete ( void * p)
inline

Definition at line 88 of file Chi2TestPolicy.h.

88 {
90 }
static SmallObjectAllocator & instance()
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.

References Chi2TestPolicy(), gum::SmallObjectAllocator::deallocate(), and gum::SmallObjectAllocator::instance().

Here is the call graph for this function:

◆ operator new()

template<typename GUM_SCALAR>
void * gum::Chi2TestPolicy< GUM_SCALAR >::operator new ( size_t s)
inline

Allocators and Deallocators redefinition.

Definition at line 86 of file Chi2TestPolicy.h.

void * allocate(const size_t &objectSize)
Allocates a block.

References gum::SmallObjectAllocator::allocate(), and gum::SmallObjectAllocator::instance().

Here is the call graph for this function:

◆ score()

template<typename GUM_SCALAR>
double gum::Chi2TestPolicy< GUM_SCALAR >::score ( ) const
virtual

Returns the performance of current variable according to the test.

Implements gum::ITestPolicy< GUM_SCALAR >.

Definition at line 100 of file Chi2TestPolicy_tpl.h.

100 {
101 if (this->isModified_()) computeScore();
102 double score = 1
104 (_conTab_.attrASize() - 1) * (_conTab_.attrBSize() - 1));
105 return score;
106 }
void computeScore() const
Recomputes the statistic from the beginning.
double score() const
Returns the performance of current variable according to the test.
static double probaChi2(double x, Size df)
computes the probability of chi2 value (used by the cache)
bool isModified_() const

References _chi2Score_, _conTab_, computeScore(), gum::ITestPolicy< GUM_SCALAR >::isModified_(), gum::ChiSquare::probaChi2(), and score().

Referenced by score(), and toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ secondaryscore()

template<typename GUM_SCALAR>
double gum::Chi2TestPolicy< GUM_SCALAR >::secondaryscore ( ) const
virtual

Returns a second criterion to severe ties.

Implements gum::ITestPolicy< GUM_SCALAR >.

Definition at line 112 of file Chi2TestPolicy_tpl.h.

112 {
113 if (this->isModified_()) computeScore();
114 return _chi2Score_;
115 }

References _chi2Score_, computeScore(), and gum::ITestPolicy< GUM_SCALAR >::isModified_().

Referenced by toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

template<typename GUM_SCALAR>
std::string gum::Chi2TestPolicy< GUM_SCALAR >::toString ( ) const
inline

Definition at line 147 of file Chi2TestPolicy.h.

147 {
149 ss << ITestPolicy< GUM_SCALAR >::toString() << "\t\t\tContingency Table : " << std::endl
150 << _conTab_.toString() << std::endl
151 << "\t\t\tGStat : " << this->score() << std::endl
152 << "\t\t\tGStat : " << this->secondaryscore() << std::endl;
153 return ss.str();
154 }
virtual double secondaryscore() const
Returns a second criterion to severe ties.

References _conTab_, score(), and secondaryscore().

Here is the call graph for this function:

Member Data Documentation

◆ _chi2Score_

template<typename GUM_SCALAR>
double gum::Chi2TestPolicy< GUM_SCALAR >::_chi2Score_
mutableprivate

Definition at line 160 of file Chi2TestPolicy.h.

Referenced by Chi2TestPolicy(), computeScore(), score(), and secondaryscore().

◆ _conTab_

template<typename GUM_SCALAR>
ContingencyTable< Idx, GUM_SCALAR > gum::Chi2TestPolicy< GUM_SCALAR >::_conTab_
private

The contingency table used to keeps records of all observation.

Definition at line 158 of file Chi2TestPolicy.h.

Referenced by Chi2TestPolicy(), add(), addObservation(), computeScore(), ct(), isTestRelevant(), score(), and toString().

◆ _isModified_

template<typename GUM_SCALAR>
bool gum::ITestPolicy< GUM_SCALAR >::_isModified_
mutableprivateinherited

Booleans indicating if we have to re eval test.

Definition at line 190 of file ITestPolicy.h.

Referenced by ITestPolicy(), add(), addObservation(), computeScore(), and isModified_().

◆ _nbObs_

template<typename GUM_SCALAR>
Idx gum::ITestPolicy< GUM_SCALAR >::_nbObs_
privateinherited

Definition at line 193 of file ITestPolicy.h.

Referenced by ITestPolicy(), add(), addObservation(), nbObservation(), and toString().


The documentation for this class was generated from the following files: