aGrUM  0.20.3
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) { GUM_CONSTRUCTOR(LeafPair); }
AbstractLeaf * _l2_
Definition: leafPair.h:119
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: leafPair.h:60
AbstractLeaf * _l1_
Definition: leafPair.h:118

◆ ~LeafPair()

gum::LeafPair::~LeafPair ( )
inline

Default destructor.

Definition at line 65 of file leafPair.h.

65  {
66  GUM_DESTRUCTOR(LeafPair);
67  ;
68  }
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 106 of file leafPair.h.

106 { return _l1_->contains(testedId) || _l2_->contains(testedId); }
virtual bool contains(NodeId testedId) const
Returns true if abstractleaf has leaf in it.
Definition: abstractLeaf.h:91
AbstractLeaf * _l2_
Definition: leafPair.h:119
AbstractLeaf * _l1_
Definition: leafPair.h:118

◆ convert2Leaf()

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

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

Definition at line 111 of file leafPair.h.

111 { return new ComposedLeaf(leafId, _l1_, _l2_); }
AbstractLeaf * _l2_
Definition: leafPair.h:119
AbstractLeaf * _l1_
Definition: leafPair.h:118

◆ firstLeaf()

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

Definition at line 100 of file leafPair.h.

100 { return _l1_; }
AbstractLeaf * _l1_
Definition: leafPair.h:118

◆ likelyhood()

double gum::LeafPair::likelyhood ( )

Updates GStatistic.

Definition at line 73 of file leafPair.cpp.

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

73  {
74  // updateLikelyhood();
75  return 1
77  (_l1_->nbModa() - 1));
78  }
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:114
double _likelyhood2_
Definition: leafPair.h:122
AbstractLeaf * _l1_
Definition: leafPair.h:118
double _likelyhood1_
Definition: leafPair.h:121
+ Here is the call graph for this function:

◆ operator delete()

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

Default constructor.

Definition at line 74 of file leafPair.h.

74  {
76  }
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 73 of file leafPair.h.

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

◆ otherLeaf()

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

Definition at line 113 of file leafPair.h.

113 { return l == _l1_ ? _l2_ : _l1_; }
AbstractLeaf * _l2_
Definition: leafPair.h:119
AbstractLeaf * _l1_
Definition: leafPair.h:118

◆ secondLeaf()

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

Definition at line 101 of file leafPair.h.

101 { return _l2_; }
AbstractLeaf * _l2_
Definition: leafPair.h:119

◆ toString()

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

Definition at line 80 of file leafPair.cpp.

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

80  {
81  std::stringstream ss;
82  ss << "\t[ Leaf1 : " << _l1_->toString() << " - Leaf2 : " << _l2_->toString();
83  // ss << " - L1 Total : " << _l1_->total() << " - L2 Total : " <<
84  // _l2_->total();
85  // for( Idx moda = 0; moda < _l1_->nbModa(); ++moda )
86  // ss << "~ M=" << moda << ".L1=" << _l1_->effectif(moda) << ".L2="
87  // << _l2_->effectif(moda) << " ~";
88  ss << " - GStat : " << this->likelyhood() << " ]";
89  return ss.str();
90  }
AbstractLeaf * _l2_
Definition: leafPair.h:119
virtual std::string toString()=0
AbstractLeaf * _l1_
Definition: leafPair.h:118
double likelyhood()
Updates GStatistic.
Definition: leafPair.cpp:73
+ 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 * (_l1_->effectif(moda) + _l2_->effectif(moda))));
59  _likelyhood1_ += add;
60  }
61  if (_l2_->effectif(moda)) {
62  double add = _l2_->effectif(moda)
63  * std::log(_l2_->effectif(moda)
64  / (scaleFactor2 * (_l1_->effectif(moda) + _l2_->effectif(moda))));
65  _likelyhood2_ += add;
66  }
67  }
68 
69  _likelyhood1_ *= 2;
70  _likelyhood2_ *= 2;
71  }
virtual double effectif(Idx) const =0
Gaves the leaf effectif for given modality.
AbstractLeaf * _l2_
Definition: leafPair.h:119
virtual Idx nbModa() const =0
double _likelyhood2_
Definition: leafPair.h:122
AbstractLeaf * _l1_
Definition: leafPair.h:118
double _likelyhood1_
Definition: leafPair.h:121
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 118 of file leafPair.h.

◆ _l2_

AbstractLeaf* gum::LeafPair::_l2_
private

Definition at line 119 of file leafPair.h.

◆ _likelyhood1_

double gum::LeafPair::_likelyhood1_
private

Definition at line 121 of file leafPair.h.

◆ _likelyhood2_

double gum::LeafPair::_likelyhood2_
private

Definition at line 122 of file leafPair.h.


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