aGrUM 3.1.1
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.
AbstractLeafconvert2Leaf (NodeId leafId) const
 Returns a leaf matching data and having given id as id.
AbstractLeafotherLeaf (AbstractLeaf *l) const
std::string toString ()
Constructor & destructor.
 LeafPair (AbstractLeaf *l1, AbstractLeaf *l2)
 Default constructor.
 ~LeafPair ()
 Default destructor.
void * operator new (size_t s)
 Allocators and Deallocators redefinition.
void operator delete (void *p)
 Default constructor.
Likelyhood Methods
void updateLikelyhood ()
 Updates GStatistic.
double likelyhood ()
 Updates GStatistic.

Private Attributes

AbstractLeaf_l1_
AbstractLeaf_l2_
double _likelyhood1_
double _likelyhood2_

Detailed Description

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

Handles a pair of leaves

Definition at line 69 of file leafPair.h.

Constructor & Destructor Documentation

◆ LeafPair()

INLINE gum::LeafPair::LeafPair ( AbstractLeaf * l1,
AbstractLeaf * l2 )

Default constructor.

Definition at line 48 of file leafPair_inl.h.

48 : _l1_(l1), _l2_(l2) {
49 GUM_CONSTRUCTOR(LeafPair);
50 }
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
AbstractLeaf * _l1_
Definition leafPair.h:134
AbstractLeaf * _l2_
Definition leafPair.h:135

References LeafPair(), _l1_, and _l2_.

Referenced by LeafPair(), ~LeafPair(), and operator delete().

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

◆ ~LeafPair()

INLINE gum::LeafPair::~LeafPair ( )

Default destructor.

Definition at line 52 of file leafPair_inl.h.

52 {
53 GUM_DESTRUCTOR(LeafPair);
54 ;
55 }

References LeafPair().

Here is the call graph for this function:

Member Function Documentation

◆ contains()

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

Returns true if pair has leaf in it.

Definition at line 69 of file leafPair_inl.h.

69 {
70 return _l1_->contains(testedId) || _l2_->contains(testedId);
71 }

References _l1_, and _l2_.

◆ convert2Leaf()

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

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

Definition at line 73 of file leafPair_inl.h.

73 {
74 return new ComposedLeaf(leafId, _l1_, _l2_);
75 }

References _l1_, and _l2_.

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

Here is the caller graph for this function:

◆ firstLeaf()

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

Definition at line 65 of file leafPair_inl.h.

65{ return _l1_; }

References _l1_.

◆ likelyhood()

double gum::LeafPair::likelyhood ( )

Updates GStatistic.

Definition at line 99 of file leafPair.cpp.

99 {
100 // updateLikelyhood();
101 return 1
103 (_l1_->nbModa() - 1));
104 }
static double probaChi2(double x, Size df)
computes the probability of chi2 value (used by the cache)
double _likelyhood1_
Definition leafPair.h:137
double _likelyhood2_
Definition leafPair.h:138

References _l1_, _likelyhood1_, _likelyhood2_, and gum::ChiSquare::probaChi2().

Referenced by gum::LeafAggregator::update(), and gum::FusionContext< isInitial >::updatePair().

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

◆ operator delete()

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

Default constructor.

Definition at line 61 of file leafPair_inl.h.

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

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

Here is the call graph for this function:

◆ operator new()

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

Allocators and Deallocators redefinition.

Definition at line 57 of file leafPair_inl.h.

57 {
59 }
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:

◆ otherLeaf()

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

Definition at line 77 of file leafPair_inl.h.

77 {
78 return l == _l1_ ? _l2_ : _l1_;
79 }

References _l1_, and _l2_.

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

Here is the caller graph for this function:

◆ secondLeaf()

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

Definition at line 67 of file leafPair_inl.h.

67{ return _l2_; }

References _l2_.

◆ toString()

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

Definition at line 106 of file leafPair.cpp.

106 {
107 // std::format("~ M={}.L1={}.L2={} ~", moda, _l1_->effectif(moda), _l2_->effectif(moda))
108 return std::format("\t[ Leaf1 : {} - Leaf2 : {} - GStat : {} ]",
109 _l1_->toString(),
110 _l2_->toString(),
111 this->likelyhood());
112 }

References _l1_, and _l2_.

◆ updateLikelyhood()

void gum::LeafPair::updateLikelyhood ( )

Updates GStatistic.

Definition at line 68 of file leafPair.cpp.

68 {
69 _likelyhood1_ = 0.0;
70 _likelyhood2_ = 0.0;
71
72 if (!_l1_->total() || !_l2_->total()) {
73 _likelyhood1_ = std::numeric_limits< double >::max();
74 _likelyhood2_ = std::numeric_limits< double >::max();
75 return;
76 }
77
78 double scaleFactor1 = _l1_->total() / (_l1_->total() + _l2_->total());
79 double scaleFactor2 = _l2_->total() / (_l1_->total() + _l2_->total());
80 for (Idx moda = 0; moda < _l1_->nbModa(); ++moda) {
81 if (_l1_->effectif(moda)) {
82 double add = _l1_->effectif(moda)
83 * std::log(_l1_->effectif(moda)
84 / (scaleFactor1 * (_l1_->effectif(moda) + _l2_->effectif(moda))));
85 _likelyhood1_ += add;
86 }
87 if (_l2_->effectif(moda)) {
88 double add = _l2_->effectif(moda)
89 * std::log(_l2_->effectif(moda)
90 / (scaleFactor2 * (_l1_->effectif(moda) + _l2_->effectif(moda))));
91 _likelyhood2_ += add;
92 }
93 }
94
95 _likelyhood1_ *= 2;
96 _likelyhood2_ *= 2;
97 }
Size Idx
Type for indexes.
Definition types.h:79

References _l1_, _l2_, _likelyhood1_, and _likelyhood2_.

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

Here is the caller graph for this function:

Member Data Documentation

◆ _l1_

AbstractLeaf* gum::LeafPair::_l1_
private

◆ _l2_

AbstractLeaf* gum::LeafPair::_l2_
private

◆ _likelyhood1_

double gum::LeafPair::_likelyhood1_
private

Definition at line 137 of file leafPair.h.

Referenced by likelyhood(), and updateLikelyhood().

◆ _likelyhood2_

double gum::LeafPair::_likelyhood2_
private

Definition at line 138 of file leafPair.h.

Referenced by likelyhood(), and updateLikelyhood().


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