aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
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 50 of file leafPair.h.

Constructor & Destructor Documentation

◆ LeafPair()

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

Default constructor.

Definition at line 60 of file leafPair.h.

60  : l1__(l1), l2__(l2) {
61  GUM_CONSTRUCTOR(LeafPair);
62  }
AbstractLeaf * l1__
Definition: leafPair.h:125
AbstractLeaf * l2__
Definition: leafPair.h:126
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: leafPair.h:60

◆ ~LeafPair()

gum::LeafPair::~LeafPair ( )
inline

Default destructor.

Definition at line 67 of file leafPair.h.

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

Member Function Documentation

◆ contains()

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

Returns true if pair has leaf in it.

Definition at line 107 of file leafPair.h.

107  {
108  return l1__->contains(testedId) || l2__->contains(testedId);
109  }
virtual bool contains(NodeId testedId) const
Returns true if abstractleaf has leaf in it.
Definition: abstractLeaf.h:92
AbstractLeaf * l1__
Definition: leafPair.h:125
AbstractLeaf * l2__
Definition: leafPair.h:126

◆ convert2Leaf()

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

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

Definition at line 114 of file leafPair.h.

114  {
115  return new ComposedLeaf(leafId, l1__, l2__);
116  }
AbstractLeaf * l1__
Definition: leafPair.h:125
AbstractLeaf * l2__
Definition: leafPair.h:126

◆ firstLeaf()

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

Definition at line 101 of file leafPair.h.

101 { return l1__; }
AbstractLeaf * l1__
Definition: leafPair.h:125

◆ likelyhood()

double gum::LeafPair::likelyhood ( )

Updates GStatistic.

Definition at line 75 of file leafPair.cpp.

References gum::Set< Key, Alloc >::emplace().

75  {
76  // updateLikelyhood();
77  return 1
79  : likelyhood2__,
80  (l1__->nbModa() - 1));
81  }
AbstractLeaf * l1__
Definition: leafPair.h:125
double likelyhood2__
Definition: leafPair.h:129
virtual Idx nbModa() const =0
static double probaChi2(double x, Size df)
computes the probability of chi2 value (used by the cache)
Definition: chiSquare.cpp:117
double likelyhood1__
Definition: leafPair.h:128
+ Here is the call graph for this function:

◆ operator delete()

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

Default constructor.

Definition at line 75 of file leafPair.h.

75  {
77  }
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: leafPair.h:60
static SmallObjectAllocator & instance()

◆ operator new()

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

Allocators and Deallocators redefinition.

Definition at line 72 of file leafPair.h.

72  {
74  }
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()

◆ otherLeaf()

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

Definition at line 118 of file leafPair.h.

118  {
119  return l == l1__ ? l2__ : l1__;
120  }
AbstractLeaf * l1__
Definition: leafPair.h:125
AbstractLeaf * l2__
Definition: leafPair.h:126

◆ secondLeaf()

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

Definition at line 102 of file leafPair.h.

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

◆ toString()

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

Definition at line 83 of file leafPair.cpp.

References gum::Set< Key, Alloc >::emplace().

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

◆ updateLikelyhood()

void gum::LeafPair::updateLikelyhood ( )

Updates GStatistic.

Definition at line 42 of file leafPair.cpp.

References gum::Set< Key, Alloc >::emplace().

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 = l1__->effectif(moda)
57  * std::log(l1__->effectif(moda)
58  / (scaleFactor1
59  * (l1__->effectif(moda) + l2__->effectif(moda))));
60  likelyhood1__ += add;
61  }
62  if (l2__->effectif(moda)) {
63  double add = l2__->effectif(moda)
64  * std::log(l2__->effectif(moda)
65  / (scaleFactor2
66  * (l1__->effectif(moda) + l2__->effectif(moda))));
67  likelyhood2__ += add;
68  }
69  }
70 
71  likelyhood1__ *= 2;
72  likelyhood2__ *= 2;
73  }
virtual double effectif(Idx) const =0
Gaves the leaf effectif for given modality.
AbstractLeaf * l1__
Definition: leafPair.h:125
double likelyhood2__
Definition: leafPair.h:129
AbstractLeaf * l2__
Definition: leafPair.h:126
virtual Idx nbModa() const =0
double likelyhood1__
Definition: leafPair.h:128
virtual double total() const =0
+ Here is the call graph for this function:

Member Data Documentation

◆ l1__

AbstractLeaf* gum::LeafPair::l1__
private

Definition at line 125 of file leafPair.h.

◆ l2__

AbstractLeaf* gum::LeafPair::l2__
private

Definition at line 126 of file leafPair.h.

◆ likelyhood1__

double gum::LeafPair::likelyhood1__
private

Definition at line 128 of file leafPair.h.

◆ likelyhood2__

double gum::LeafPair::likelyhood2__
private

Definition at line 129 of file leafPair.h.


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