66 template <
typename GUM_ELEMENT >
79 template <
typename GUM_ELEMENT >
83 for (
auto attrIter =
_conTab_.attrABeginSafe(); attrIter !=
_conTab_.attrAEndSafe();
86 for (
auto valIter =
_conTab_.attrBBeginSafe(); valIter !=
_conTab_.attrBEndSafe();
88 double cell = (
double)
_conTab_.joint(attrIter.key(), valIter.key());
89 if (cell < 5)
continue;
90 double expected = semiExpected * (
double)(valIter.val());
92 _chi2Score_ += std::pow(cell - expected, 2.0) / expected;
100 template <
typename GUM_ELEMENT >
112 template <
typename GUM_ELEMENT >
118 template <
typename GUM_ELEMENT >
124 template <
typename GUM_ELEMENT >
130 template <
typename GUM_ELEMENT >
136 template <
typename GUM_ELEMENT >
141 template <
typename GUM_ELEMENT >
146 template <
typename GUM_ELEMENT >
151 template <
typename GUM_ELEMENT >
156 template <
typename GUM_ELEMENT >
158 return std::format(
"{}\t\t\tContingency Table : \n{}\n\t\t\tGStat : {}\n\t\t\tGStat : {}\n",
162 this->secondaryscore());
Headers of the Chi2TestPolicy.
void add(const Chi2TestPolicy< GUM_ELEMENT > &src)
void addObservation(Idx attr, GUM_ELEMENT value) override
Comptabilizes the new observation.
std::string toString() const
~Chi2TestPolicy() override
bool isTestRelevant() const override
Returns true if enough observation were made so that the test can be relevant.
void computeScore() const override
Recomputes the statistic from the beginning.
ContingencyTable< Idx, GUM_ELEMENT > _conTab_
The contingency table used to keeps records of all observation.
double secondaryscore() const override
Returns a second criterion to severe ties.
const ContingencyTable< Idx, GUM_ELEMENT > & ct() const
double score() const override
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)
ITestPolicy()
Allocators and Deallocators redefinition.
virtual void addObservation(Idx attr, GUM_ELEMENT value)
Comptabilizes the new observation.
virtual void computeScore() const
Recomputes the statistic from the beginning.
void add(const ITestPolicy< GUM_ELEMENT > &src)
Idx nbObservation() const
Comptabilizes the new observation.
std::string toString() const
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Size Idx
Type for indexes.
gum is the global namespace for all aGrUM entities