aGrUM  0.16.0
gum::LeafPair Class Reference

<agrum/FMDP/learning/datastructure/leaves/leafPair.h> More...

#include <leafPair.h>

+ Collaboration diagram for gum::LeafPair:

Public Member Functions

AbstractLeaffirstLeaf ()
 
AbstractLeafsecondLeaf ()
 
bool contains (NodeId testedId)
 Returns true if pair has leaf in it. More...
 
AbstractLeafconvert2Leaf (NodeId leafId) const
 Returns a leaf matching data and having given id as id. More...
 
AbstractLeafotherLeaf (AbstractLeaf *l) const
 
std::string toString ()
 
Constructor & destructor.
 LeafPair (AbstractLeaf *l1, AbstractLeaf *l2)
 Default constructor. More...
 
 ~LeafPair ()
 Default destructor. More...
 
void * operator new (size_t s)
 Allocators and Deallocators redefinition. More...
 
void operator delete (void *p)
 Default constructor. More...
 
Likelyhood Methods
void updateLikelyhood ()
 Updates GStatistic. More...
 
double likelyhood ()
 Updates GStatistic. More...
 

Detailed Description

<agrum/FMDP/learning/datastructure/leaves/leafPair.h>

Handles a pair of leaves

Definition at line 51 of file leafPair.h.

Constructor & Destructor Documentation

◆ LeafPair()

gum::LeafPair::LeafPair ( AbstractLeaf l1,
AbstractLeaf l2 
)
inline

Default constructor.

Definition at line 61 of file leafPair.h.

61  : __l1(l1), __l2(l2) {
62  GUM_CONSTRUCTOR(LeafPair);
63  }
AbstractLeaf * __l2
Definition: leafPair.h:127
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: leafPair.h:61
AbstractLeaf * __l1
Definition: leafPair.h:126

◆ ~LeafPair()

gum::LeafPair::~LeafPair ( )
inline

Default destructor.

Definition at line 68 of file leafPair.h.

68 { GUM_DESTRUCTOR(LeafPair); }
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: leafPair.h:61

Member Function Documentation

◆ contains()

bool gum::LeafPair::contains ( NodeId  testedId)
inline

Returns true if pair has leaf in it.

Definition at line 108 of file leafPair.h.

References __l1, __l2, and gum::AbstractLeaf::contains().

108  {
109  return __l1->contains(testedId) || __l2->contains(testedId);
110  }
virtual bool contains(NodeId testedId) const
Returns true if abstractleaf has leaf in it.
Definition: abstractLeaf.h:93
AbstractLeaf * __l2
Definition: leafPair.h:127
AbstractLeaf * __l1
Definition: leafPair.h:126
+ Here is the call graph for this function:

◆ convert2Leaf()

AbstractLeaf* gum::LeafPair::convert2Leaf ( NodeId  leafId) const
inline

Returns a leaf matching data and having given id as id.

Definition at line 115 of file leafPair.h.

References __l1, and __l2.

Referenced by gum::LeafAggregator::update().

115  {
116  return new ComposedLeaf(leafId, __l1, __l2);
117  }
AbstractLeaf * __l2
Definition: leafPair.h:127
AbstractLeaf * __l1
Definition: leafPair.h:126
+ Here is the caller graph for this function:

◆ firstLeaf()

AbstractLeaf* gum::LeafPair::firstLeaf ( )
inline

Definition at line 102 of file leafPair.h.

References __l1.

102 { return __l1; }
AbstractLeaf * __l1
Definition: leafPair.h:126

◆ likelyhood()

double gum::LeafPair::likelyhood ( )

Updates GStatistic.

Definition at line 77 of file leafPair.cpp.

References __l1, __likelyhood1, __likelyhood2, gum::AbstractLeaf::nbModa(), and gum::ChiSquare::probaChi2().

Referenced by gum::FusionContext< true >::__associateLeaf(), gum::FusionContext< true >::addPair(), operator delete(), toString(), gum::LeafAggregator::update(), and gum::FusionContext< true >::updatePair().

77  {
78  // updateLikelyhood();
79  return 1
81  : __likelyhood2,
82  (__l1->nbModa() - 1));
83  }
virtual Idx nbModa() const =0
double __likelyhood2
Definition: leafPair.h:130
static double probaChi2(double x, Size df)
computes the probability of chi2 value (used by the cache)
Definition: chiSquare.cpp:118
double __likelyhood1
Definition: leafPair.h:129
AbstractLeaf * __l1
Definition: leafPair.h:126
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator delete()

void gum::LeafPair::operator delete ( void *  p)
inline

Default constructor.

Definition at line 76 of file leafPair.h.

References gum::SmallObjectAllocator::deallocate(), gum::SmallObjectAllocator::instance(), likelyhood(), and updateLikelyhood().

76  {
78  }
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: leafPair.h:61
static SmallObjectAllocator & instance()
+ Here is the call graph for this function:

◆ operator new()

void* gum::LeafPair::operator new ( size_t  s)
inline

Allocators and Deallocators redefinition.

Definition at line 73 of file leafPair.h.

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

73  {
75  }
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()
+ Here is the call graph for this function:

◆ otherLeaf()

AbstractLeaf* gum::LeafPair::otherLeaf ( AbstractLeaf l) const
inline

Definition at line 119 of file leafPair.h.

References __l1, __l2, and toString().

Referenced by gum::LeafAggregator::~LeafAggregator().

119  {
120  return l == __l1 ? __l2 : __l1;
121  }
AbstractLeaf * __l2
Definition: leafPair.h:127
AbstractLeaf * __l1
Definition: leafPair.h:126
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ secondLeaf()

AbstractLeaf* gum::LeafPair::secondLeaf ( )
inline

Definition at line 103 of file leafPair.h.

References __l2.

103 { return __l2; }
AbstractLeaf * __l2
Definition: leafPair.h:127

◆ toString()

std::string gum::LeafPair::toString ( )

Definition at line 85 of file leafPair.cpp.

References __l1, __l2, likelyhood(), and gum::AbstractLeaf::toString().

Referenced by otherLeaf().

85  {
86  std::stringstream ss;
87  ss << "\t[ Leaf1 : " << __l1->toString() << " - Leaf2 : " << __l2->toString();
88  // ss << " - L1 Total : " << __l1->total() << " - L2 Total : " <<
89  // __l2->total();
90  // for( Idx moda = 0; moda < __l1->nbModa(); ++moda )
91  // ss << "~ M=" << moda << ".L1=" << __l1->effectif(moda) << ".L2="
92  // << __l2->effectif(moda) << " ~";
93  ss << " - GStat : " << this->likelyhood() << " ]";
94  return ss.str();
95  }
virtual std::string toString()=0
AbstractLeaf * __l2
Definition: leafPair.h:127
double likelyhood()
Updates GStatistic.
Definition: leafPair.cpp:77
AbstractLeaf * __l1
Definition: leafPair.h:126
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateLikelyhood()

void gum::LeafPair::updateLikelyhood ( )

Updates GStatistic.

Definition at line 42 of file leafPair.cpp.

References __l1, __l2, __likelyhood1, __likelyhood2, gum::AbstractLeaf::effectif(), gum::AbstractLeaf::nbModa(), and gum::AbstractLeaf::total().

Referenced by gum::FusionContext< true >::__updateAllAssociatedLeaves(), gum::FusionContext< true >::__updateAssociatedLeaf(), gum::LeafAggregator::addLeaf(), and operator delete().

42  {
43  __likelyhood1 = 0.0;
44  __likelyhood2 = 0.0;
45 
46  if (!__l1->total() || !__l2->total()) {
47  __likelyhood1 = std::numeric_limits< double >::max();
48  __likelyhood2 = std::numeric_limits< double >::max();
49  return;
50  }
51 
52  double scaleFactor1 = __l1->total() / (__l1->total() + __l2->total());
53  double scaleFactor2 = __l2->total() / (__l1->total() + __l2->total());
54  for (Idx moda = 0; moda < __l1->nbModa(); ++moda) {
55  if (__l1->effectif(moda)) {
56  double add =
57  __l1->effectif(moda)
58  * std::log(
59  __l1->effectif(moda)
60  / (scaleFactor1 * (__l1->effectif(moda) + __l2->effectif(moda))));
61  __likelyhood1 += add;
62  }
63  if (__l2->effectif(moda)) {
64  double add =
65  __l2->effectif(moda)
66  * std::log(
67  __l2->effectif(moda)
68  / (scaleFactor2 * (__l1->effectif(moda) + __l2->effectif(moda))));
69  __likelyhood2 += add;
70  }
71  }
72 
73  __likelyhood1 *= 2;
74  __likelyhood2 *= 2;
75  }
virtual double effectif(Idx) const =0
Gaves the leaf effectif for given modality.
virtual Idx nbModa() const =0
double __likelyhood2
Definition: leafPair.h:130
AbstractLeaf * __l2
Definition: leafPair.h:127
double __likelyhood1
Definition: leafPair.h:129
virtual double total() const =0
AbstractLeaf * __l1
Definition: leafPair.h:126
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ __l1

AbstractLeaf* gum::LeafPair::__l1
private

◆ __l2

AbstractLeaf* gum::LeafPair::__l2
private

Definition at line 127 of file leafPair.h.

Referenced by contains(), convert2Leaf(), otherLeaf(), secondLeaf(), toString(), and updateLikelyhood().

◆ __likelyhood1

double gum::LeafPair::__likelyhood1
private

Definition at line 129 of file leafPair.h.

Referenced by likelyhood(), and updateLikelyhood().

◆ __likelyhood2

double gum::LeafPair::__likelyhood2
private

Definition at line 130 of file leafPair.h.

Referenced by likelyhood(), and updateLikelyhood().


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