33 template <
typename GUM_SCALAR >
35 for (
auto obsIter = this->__obsTable.cbeginSafe();
36 __obsTable.cendSafe() != obsIter;
51 template <
typename GUM_SCALAR >
57 if (__sumAttrTable.exists(attr))
58 __sumAttrTable[attr] += value;
60 __sumAttrTable.insert(attr, value);
62 if (__nbObsTable.exists(attr))
65 __nbObsTable.insert(attr, 1);
67 if (!__obsTable.exists(attr))
69 __obsTable[attr]->addLink(value);
80 template <
typename GUM_SCALAR >
83 double mean = __sumO / (
double)this->nbObservation();
85 double sumErrorAttr = 0.0;
86 for (
auto attrIter = __sumAttrTable.cbeginSafe();
87 attrIter != __sumAttrTable.cendSafe();
89 Idx key = attrIter.key();
90 double meanAttr = __sumAttrTable[key] / (
double)__nbObsTable[key];
91 double errorAttr = 0.0;
95 errorAttr += std::pow(linky->
element() - meanAttr, 2);
96 errorO += std::pow(linky->
element() - mean, 2);
101 ((
double)__nbObsTable[key] / (
double)this->nbObservation()) * errorAttr;
103 __score = errorO - sumErrorAttr;
109 template <
typename GUM_SCALAR >
111 if (this->_isModified()) computeScore();
118 template <
typename GUM_SCALAR >
120 if (this->_isModified()) computeScore();
124 template <
typename GUM_SCALAR >
131 if (__nbObsTable.exists(obsIter.key()))
132 __nbObsTable[obsIter.key()] += obsIter.val();
134 __nbObsTable.insert(obsIter.key(), obsIter.val());
139 if (__sumAttrTable.exists(attrIter.key()))
140 __sumAttrTable[attrIter.key()] += attrIter.val();
142 __sumAttrTable.insert(attrIter.key(), attrIter.val());
144 for (
auto obsIter = src.
obsTable().cbeginSafe();
145 obsIter != src.
obsTable().cendSafe();
147 if (!__obsTable.exists(obsIter.key()))
151 __obsTable[obsIter.key()]->addLink(srcLink->
element());
const HashTable< Idx, LinkedList< double > *> & obsTable() const
Returns global sum (needed for the merging)
virtual void computeScore() const
Recomputes the statistic from the beginning.
double score()
Returns the performance of current variable according to the test.
const HashTable< Idx, Idx > & nbObsTable() const
Returns nbobs per modality table (needed for the merging)
virtual ~LeastSquareTestPolicy()
Destructor.
double secondaryscore() const
Returns a second criterion to severe ties.
const HashTable< Idx, double > & sumAttrTable() const
Returns sum per modality table (needed for the merging)
virtual void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.
const_iterator_safe cbeginSafe() const
Returns the safe const_iterator pointing to the beginning of the hashtable.
void add(const LeastSquareTestPolicy< GUM_SCALAR > &src)
Performs the merging of current LeastSquareTestPolicy instance with given instance.
gum is the global namespace for all aGrUM entities
<agrum/multidim/core/testPolicy/leastSquareTestPolicy.h>
void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.
const T & element() const
Returns the element stored in this link.
const const_iterator_safe & cendSafe() const noexcept
Returns the safe const_iterator pointing to the end of the hashtable.
void computeScore()
Returns the performance of current variable according to the test.
Link of a chain list allocated using the SmallObjectAllocator.
void add(const ITestPolicy< GUM_SCALAR > &src)
Chain list allocated using the SmallObjectAllocator.
Headers of the LeastSquareTestPolicy.
Size Idx
Type for indexes.
const Link< T > * nextLink() const
Returns next link.