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

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

#include <leastSquareTestPolicy.h>

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

Public Member Functions

Constructor/Destrcutor
 LeastSquareTestPolicy ()
 Constructor.
void * operator new (size_t s)
 Allocators and Deallocators redefinition.
void operator delete (void *p)
 Constructor.
virtual ~LeastSquareTestPolicy ()
 Destructor.
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 ()
 Returns the performance of current variable according to the test.
double score ()
 Returns the performance of current variable according to the test.
double secondaryscore () const
 Returns a second criterion to severe ties.
Observation methods
Idx nbObservation () const
 Comptabilizes the new observation.
Test methods
virtual void computeScore () const
 Recomputes the statistic from the beginning.
virtual double score () const =0
 Returns the performance of current variable according to the test.
Fusion Methods
void add (const ITestPolicy< GUM_SCALAR > &src)
Miscelleanous Methods
std::string toString () const

Protected Member Functions

bool isModified_ () const

Private Attributes

bool _isModified_
 Booleans indicating if we have to re eval test.
Idx _nbObs_

Fusion Methods

double _sumO_
 Global sum.
HashTable< Idx, Idx_nbObsTable_
 Nb Observation for each modality assumed by variable.
HashTable< Idx, double_sumAttrTable_
 Sum for each modality assumed by variable.
HashTable< Idx, LinkedList< double > * > _obsTable_
 Not sure if needed.
double _score_
 Keeping computed score.
void add (const LeastSquareTestPolicy< GUM_SCALAR > &src)
 Performs the merging of current LeastSquareTestPolicy instance with given instance.
double sumValue () const
 Returns global sum (needed for the merging).
const HashTable< Idx, Idx > & nbObsTable () const
 Returns nbobs per modality table (needed for the merging).
const HashTable< Idx, double > & sumAttrTable () const
 Returns sum per modality table (needed for the merging).
const HashTable< Idx, LinkedList< double > * > & obsTable () const
 Returns global sum (needed for the merging).

Detailed Description

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

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

LeastSquareTestPolicy implements a test policy that follows the Least Square statistic

Definition at line 73 of file leastSquareTestPolicy.h.

Constructor & Destructor Documentation

◆ LeastSquareTestPolicy()

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

Constructor.

Definition at line 83 of file leastSquareTestPolicy.h.

85 }
ITestPolicy()
Allocators and Deallocators redefinition.
Definition ITestPolicy.h:81
<agrum/base/multidim/core/testPolicy/leastSquareTestPolicy.h>
double _score_
Keeping computed score.

References gum::ITestPolicy< GUM_SCALAR >::ITestPolicy(), LeastSquareTestPolicy(), _score_, and _sumO_.

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

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

◆ ~LeastSquareTestPolicy()

template<typename GUM_SCALAR>
gum::LeastSquareTestPolicy< GUM_SCALAR >::~LeastSquareTestPolicy ( )
virtual

Destructor.

Definition at line 58 of file leastSquareTestPolicy_tpl.h.

58 {
59 for (auto obsIter = this->_obsTable_.cbeginSafe(); _obsTable_.cendSafe() != obsIter; ++obsIter)
60 delete obsIter.val();
61
63 }
HashTable< Idx, LinkedList< double > * > _obsTable_
Not sure if needed.

References LeastSquareTestPolicy(), and _obsTable_.

Here is the call graph for this function:

Member Function Documentation

◆ add() [1/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:

◆ add() [2/2]

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

Performs the merging of current LeastSquareTestPolicy instance with given instance.

Definition at line 137 of file leastSquareTestPolicy_tpl.h.

137 {
139
141 ++obsIter)
142 if (_nbObsTable_.exists(obsIter.key())) _nbObsTable_[obsIter.key()] += obsIter.val();
143 else _nbObsTable_.insert(obsIter.key(), obsIter.val());
144
146 ++attrIter)
147 if (_sumAttrTable_.exists(attrIter.key())) _sumAttrTable_[attrIter.key()] += attrIter.val();
148 else _sumAttrTable_.insert(attrIter.key(), attrIter.val());
149
150 for (auto obsIter = src.obsTable().cbeginSafe(); obsIter != src.obsTable().cendSafe();
151 ++obsIter) {
152 if (!_obsTable_.exists(obsIter.key()))
153 _obsTable_.insert(obsIter.key(), new LinkedList< double >());
154 const Link< double >* srcLink = obsIter.val()->list();
155 while (srcLink) {
156 _obsTable_[obsIter.key()]->addLink(srcLink->element());
157 srcLink = srcLink->nextLink();
158 }
159 }
160 }
const const_iterator_safe & cendSafe() const noexcept
Returns the safe const_iterator pointing to the end of the hashtable.
const_iterator_safe cbeginSafe() const
Returns the safe const_iterator pointing to the beginning of the hashtable.
void add(const ITestPolicy< GUM_SCALAR > &src)
HashTable< Idx, Idx > _nbObsTable_
Nb Observation for each modality assumed by variable.
HashTable< Idx, double > _sumAttrTable_
Sum for each modality assumed by variable.
const HashTable< Idx, Idx > & nbObsTable() const
Returns nbobs per modality table (needed for the merging).
const HashTable< Idx, double > & sumAttrTable() const
Returns sum per modality table (needed for the merging).
const HashTable< Idx, LinkedList< double > * > & obsTable() const
Returns global sum (needed for the merging).

References LeastSquareTestPolicy(), _nbObsTable_, _obsTable_, _sumAttrTable_, gum::ITestPolicy< GUM_SCALAR >::add(), gum::HashTable< Key, Val >::cbeginSafe(), gum::HashTable< Key, Val >::cendSafe(), gum::Link< T >::element(), nbObsTable(), gum::Link< T >::nextLink(), obsTable(), and sumAttrTable().

Here is the call graph for this function:

◆ addObservation()

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

Comptabilizes the new observation.

Reimplemented from gum::ITestPolicy< GUM_SCALAR >.

Definition at line 73 of file leastSquareTestPolicy_tpl.h.

73 {
75 _sumO_ += value;
76
78 else _sumAttrTable_.insert(attr, value);
79
80 if (_nbObsTable_.exists(attr)) _nbObsTable_[attr]++;
81 else _nbObsTable_.insert(attr, 1);
82
83 if (!_obsTable_.exists(attr)) _obsTable_.insert(attr, new LinkedList< double >());
84 _obsTable_[attr]->addLink(value);
85 }
virtual void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.

References _nbObsTable_, _obsTable_, _sumAttrTable_, _sumO_, and gum::ITestPolicy< GUM_SCALAR >::addObservation().

Here is the call graph for this function:

◆ computeScore() [1/2]

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

Recomputes the statistic from the beginning.

Reimplemented in gum::Chi2TestPolicy< GUM_SCALAR >, and gum::GTestPolicy< GUM_SCALAR >.

Definition at line 138 of file ITestPolicy.h.

138{ _isModified_ = false; }

References _isModified_.

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

Here is the caller graph for this function:

◆ computeScore() [2/2]

template<typename GUM_SCALAR>
void gum::LeastSquareTestPolicy< GUM_SCALAR >::computeScore ( )

Returns the performance of current variable according to the test.

Definition at line 95 of file leastSquareTestPolicy_tpl.h.

95 {
97 double mean = _sumO_ / (double)this->nbObservation();
98 double errorO = 0.0;
99 double sumErrorAttr = 0.0;
100 for (auto attrIter = _sumAttrTable_.cbeginSafe(); attrIter != _sumAttrTable_.cendSafe();
101 ++attrIter) {
102 Idx key = attrIter.key();
104 double errorAttr = 0.0;
105
106 const Link< double >* linky = _obsTable_[key]->list();
107 while (linky) {
108 errorAttr += std::pow(linky->element() - meanAttr, 2);
109 errorO += std::pow(linky->element() - mean, 2);
110 linky = linky->nextLink();
111 }
112
114 }
116 }
virtual void computeScore() const
Recomputes the statistic from the beginning.

References _nbObsTable_, _obsTable_, _score_, _sumAttrTable_, _sumO_, gum::ITestPolicy< GUM_SCALAR >::computeScore(), gum::Link< T >::element(), gum::ITestPolicy< GUM_SCALAR >::nbObservation(), and gum::Link< T >::nextLink().

Referenced by score(), and secondaryscore().

Here is the call graph for this function:
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::LeastSquareTestPolicy< 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 123 of file leastSquareTestPolicy.h.

123{ return (this->nbObservation() > 20); }

References 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:

◆ nbObsTable()

template<typename GUM_SCALAR>
const HashTable< Idx, Idx > & gum::LeastSquareTestPolicy< GUM_SCALAR >::nbObsTable ( ) const
inline

Returns nbobs per modality table (needed for the merging).

Definition at line 170 of file leastSquareTestPolicy.h.

170{ return _nbObsTable_; }

References _nbObsTable_.

Referenced by add().

Here is the caller graph for this function:

◆ obsTable()

template<typename GUM_SCALAR>
const HashTable< Idx, LinkedList< double > * > & gum::LeastSquareTestPolicy< GUM_SCALAR >::obsTable ( ) const
inline

Returns global sum (needed for the merging).

Definition at line 180 of file leastSquareTestPolicy.h.

180{ return _obsTable_; }

References _obsTable_.

Referenced by add().

Here is the caller graph for this function:

◆ operator delete()

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

Constructor.

Definition at line 92 of file leastSquareTestPolicy.h.

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

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

Here is the call graph for this function:

◆ operator new()

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

Allocators and Deallocators redefinition.

Definition at line 90 of file leastSquareTestPolicy.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() [1/2]

template<typename GUM_SCALAR>
virtual double gum::ITestPolicy< GUM_SCALAR >::score ( ) const
pure virtualinherited

Returns the performance of current variable according to the test.

Implemented in gum::Chi2TestPolicy< GUM_SCALAR >, and gum::GTestPolicy< GUM_SCALAR >.

◆ score() [2/2]

template<typename GUM_SCALAR>
double gum::LeastSquareTestPolicy< GUM_SCALAR >::score ( )

Returns the performance of current variable according to the test.

Definition at line 122 of file leastSquareTestPolicy_tpl.h.

122 {
123 if (this->isModified_()) computeScore();
124 return _score_;
125 }
bool isModified_() const
void computeScore()
Returns the performance of current variable according to the test.

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

Here is the call graph for this function:

◆ secondaryscore()

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

Returns a second criterion to severe ties.

Implements gum::ITestPolicy< GUM_SCALAR >.

Definition at line 131 of file leastSquareTestPolicy_tpl.h.

131 {
132 if (this->isModified_()) computeScore();
133 return _score_;
134 }

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

Here is the call graph for this function:

◆ sumAttrTable()

template<typename GUM_SCALAR>
const HashTable< Idx, double > & gum::LeastSquareTestPolicy< GUM_SCALAR >::sumAttrTable ( ) const
inline

Returns sum per modality table (needed for the merging).

Definition at line 175 of file leastSquareTestPolicy.h.

175{ return _sumAttrTable_; }

References _sumAttrTable_.

Referenced by add().

Here is the caller graph for this function:

◆ sumValue()

template<typename GUM_SCALAR>
double gum::LeastSquareTestPolicy< GUM_SCALAR >::sumValue ( ) const
inline

Returns global sum (needed for the merging).

Definition at line 165 of file leastSquareTestPolicy.h.

165{ return _sumO_; }

References _sumO_.

◆ toString()

template<typename GUM_SCALAR>
std::string gum::ITestPolicy< GUM_SCALAR >::toString ( ) const
inlineinherited

Definition at line 177 of file ITestPolicy.h.

177 {
179 ss << "\t\t\tNb Obs : " << _nbObs_ << std::endl;
180 return ss.str();
181 }

References _nbObs_.

Member Data Documentation

◆ _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().

◆ _nbObsTable_

template<typename GUM_SCALAR>
HashTable< Idx, Idx > gum::LeastSquareTestPolicy< GUM_SCALAR >::_nbObsTable_
private

Nb Observation for each modality assumed by variable.

Definition at line 187 of file leastSquareTestPolicy.h.

Referenced by add(), addObservation(), computeScore(), and nbObsTable().

◆ _obsTable_

template<typename GUM_SCALAR>
HashTable< Idx, LinkedList< double >* > gum::LeastSquareTestPolicy< GUM_SCALAR >::_obsTable_
private

Not sure if needed.

Definition at line 193 of file leastSquareTestPolicy.h.

Referenced by ~LeastSquareTestPolicy(), add(), addObservation(), computeScore(), and obsTable().

◆ _score_

template<typename GUM_SCALAR>
double gum::LeastSquareTestPolicy< GUM_SCALAR >::_score_
private

Keeping computed score.

Definition at line 196 of file leastSquareTestPolicy.h.

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

◆ _sumAttrTable_

template<typename GUM_SCALAR>
HashTable< Idx, double > gum::LeastSquareTestPolicy< GUM_SCALAR >::_sumAttrTable_
private

Sum for each modality assumed by variable.

Definition at line 190 of file leastSquareTestPolicy.h.

Referenced by add(), addObservation(), computeScore(), and sumAttrTable().

◆ _sumO_

template<typename GUM_SCALAR>
double gum::LeastSquareTestPolicy< GUM_SCALAR >::_sumO_
private

Global sum.

Definition at line 184 of file leastSquareTestPolicy.h.

Referenced by LeastSquareTestPolicy(), addObservation(), computeScore(), and sumValue().


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