36 template <
typename GUM_SCALAR >
38 for (
auto obsIter = this->__obsTable.cbeginSafe();
39 __obsTable.cendSafe() != obsIter;
54 template <
typename GUM_SCALAR >
60 if (__sumAttrTable.exists(attr))
61 __sumAttrTable[attr] += value;
63 __sumAttrTable.insert(attr, value);
65 if (__nbObsTable.exists(attr))
68 __nbObsTable.insert(attr, 1);
70 if (!__obsTable.exists(attr))
72 __obsTable[attr]->addLink(value);
83 template <
typename GUM_SCALAR >
86 double mean = __sumO / (
double)this->nbObservation();
88 double sumErrorAttr = 0.0;
89 for (
auto attrIter = __sumAttrTable.cbeginSafe();
90 attrIter != __sumAttrTable.cendSafe();
92 Idx key = attrIter.key();
93 double meanAttr = __sumAttrTable[key] / (
double)__nbObsTable[key];
94 double errorAttr = 0.0;
98 errorAttr += std::pow(linky->
element() - meanAttr, 2);
99 errorO += std::pow(linky->
element() - mean, 2);
104 ((
double)__nbObsTable[key] / (
double)this->nbObservation()) * errorAttr;
106 __score = errorO - sumErrorAttr;
112 template <
typename GUM_SCALAR >
114 if (this->_isModified()) computeScore();
121 template <
typename GUM_SCALAR >
123 if (this->_isModified()) computeScore();
127 template <
typename GUM_SCALAR >
134 if (__nbObsTable.exists(obsIter.key()))
135 __nbObsTable[obsIter.key()] += obsIter.val();
137 __nbObsTable.insert(obsIter.key(), obsIter.val());
142 if (__sumAttrTable.exists(attrIter.key()))
143 __sumAttrTable[attrIter.key()] += attrIter.val();
145 __sumAttrTable.insert(attrIter.key(), attrIter.val());
147 for (
auto obsIter = src.
obsTable().cbeginSafe();
148 obsIter != src.
obsTable().cendSafe();
150 if (!__obsTable.exists(obsIter.key()))
154 __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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size Idx
Type for indexes.
const Link< T > * nextLink() const
Returns next link.