aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::FusionContext< isInitial > Class Template Reference

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

#include <fusionContext.h>

+ Collaboration diagram for gum::FusionContext< isInitial >:

Public Member Functions

std::string toString ()
 
Constructor & destructor.
 FusionContext (AbstractLeaf *)
 Default constructor. More...
 
 ~FusionContext ()
 Default destructor. More...
 
void * operator new (size_t s)
 Allocators and Deallocators redefinition. More...
 
void operator delete (void *p)
 Default constructor. More...
 
Pair handling methods
bool addPair (LeafPair *p)
 
bool updatePair (LeafPair *p)
 
bool removePair (LeafPair *p)
 
pair_iterator beginPairs ()
 
pair_iterator endPairs ()
 
Best Pair access methods
LeafPairtop ()
 
double topLikelyhood ()
 

Associated Leaves Handling methods

bool containsAssociatedLeaf (AbstractLeaf *l)
 
bool associateLeaf (AbstractLeaf *l)
 
bool updateAssociatedLeaf (AbstractLeaf *l)
 
bool updateAllAssociatedLeaves ()
 
bool deassociateLeaf (AbstractLeaf *l)
 
bool _containsAssociatedLeaf_ (AbstractLeaf *l, Int2Type< false >)
 
bool _containsAssociatedLeaf_ (AbstractLeaf *, Int2Type< true >)
 
bool _associateLeaf_ (AbstractLeaf *, Int2Type< false >)
 
bool _associateLeaf_ (AbstractLeaf *, Int2Type< true >)
 
bool _updateAssociatedLeaf_ (AbstractLeaf *, Int2Type< false >)
 
bool _updateAssociatedLeaf_ (AbstractLeaf *, Int2Type< true >)
 
bool _updateAllAssociatedLeaves_ (Int2Type< false >)
 
bool _updateAllAssociatedLeaves_ (Int2Type< true >)
 
bool _deassociateLeaf_ (AbstractLeaf *, Int2Type< false >)
 
bool _deassociateLeaf_ (AbstractLeaf *, Int2Type< true >)
 

FusionContext Leaf and associated pairs handling methods

AbstractLeafleaf ()
 
LeafPairleafAssociatedPair (AbstractLeaf *l)
 
Set< LeafPair *> associatedPairs ()
 
Set< LeafPair *> _associatedPairs_ (Int2Type< false >)
 
Set< LeafPair *> _associatedPairs_ (Int2Type< true >)
 

Detailed Description

template<bool isInitial = false>
class gum::FusionContext< isInitial >

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

Contains leaves situation after a merging have been made

Definition at line 56 of file fusionContext.h.

Constructor & Destructor Documentation

◆ FusionContext()

template<bool isInitial>
gum::FusionContext< isInitial >::FusionContext ( AbstractLeaf leaf)

Default constructor.

Definition at line 44 of file fusionContext_tpl.h.

44  : _leaf_(leaf) {
45  GUM_CONSTRUCTOR(FusionContext);
46  }
AbstractLeaf * leaf()
FusionContext(AbstractLeaf *)
Default constructor.
AbstractLeaf * _leaf_

◆ ~FusionContext()

template<bool isInitial>
gum::FusionContext< isInitial >::~FusionContext ( )

Default destructor.

Definition at line 52 of file fusionContext_tpl.h.

52  {
53  GUM_DESTRUCTOR(FusionContext);
54 
55  for (auto leafIter = _leaf2Pair_.beginSafe(); leafIter != _leaf2Pair_.endSafe(); ++leafIter)
56  delete leafIter.val();
57 
58  delete _leaf_;
59  }
FusionContext(AbstractLeaf *)
Default constructor.
HashTable< AbstractLeaf *, LeafPair *> _leaf2Pair_
AbstractLeaf * _leaf_

Member Function Documentation

◆ _associatedPairs_() [1/2]

template<bool isInitial>
Set< LeafPair *> gum::FusionContext< isInitial >::_associatedPairs_ ( Int2Type< false >  )
private

Definition at line 174 of file fusionContext_tpl.h.

174  {
175  Set< LeafPair* > retBag;
176  for (auto pairIter = _leaf2Pair_.beginSafe(); pairIter != _leaf2Pair_.endSafe(); ++pairIter)
177  retBag << pairIter.val();
178 
179  return retBag;
180  }
HashTable< AbstractLeaf *, LeafPair *> _leaf2Pair_

◆ _associatedPairs_() [2/2]

template<bool isInitial = false>
Set< LeafPair* > gum::FusionContext< isInitial >::_associatedPairs_ ( Int2Type< true >  )
inlineprivate

Definition at line 216 of file fusionContext.h.

216 { return Set< LeafPair* >(); }

◆ _associateLeaf_() [1/2]

template<bool isInitial>
bool gum::FusionContext< isInitial >::_associateLeaf_ ( AbstractLeaf l,
Int2Type< false >   
)
private
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 69 of file fusionContext_tpl.h.

69  {
70  LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
71  ;
72  LeafPair* p = new LeafPair(l, _leaf_);
73  _leaf2Pair_.insert(l, p);
74  _leaf2Pair_[l]->updateLikelyhood();
75  _pairsHeap_.insert(p, p->likelyhood());
76 
77  return ptop != _pairsHeap_.top();
78  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_
HashTable< AbstractLeaf *, LeafPair *> _leaf2Pair_
AbstractLeaf * _leaf_

◆ _associateLeaf_() [2/2]

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::_associateLeaf_ ( AbstractLeaf ,
Int2Type< true >   
)
inlineprivate
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 110 of file fusionContext.h.

110 { return false; }

◆ _containsAssociatedLeaf_() [1/2]

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::_containsAssociatedLeaf_ ( AbstractLeaf l,
Int2Type< false >   
)
inlineprivate
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 97 of file fusionContext.h.

97  {
98  return _leaf2Pair_.exists(l);
99  }
HashTable< AbstractLeaf *, LeafPair *> _leaf2Pair_

◆ _containsAssociatedLeaf_() [2/2]

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::_containsAssociatedLeaf_ ( AbstractLeaf ,
Int2Type< true >   
)
inlineprivate
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 100 of file fusionContext.h.

100 { return false; }

◆ _deassociateLeaf_() [1/2]

template<bool isInitial>
bool gum::FusionContext< isInitial >::_deassociateLeaf_ ( AbstractLeaf l,
Int2Type< false >   
)
private
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 115 of file fusionContext_tpl.h.

115  {
116  LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
117  _pairsHeap_.erase(_leaf2Pair_[l]);
118  _leaf2Pair_.erase(l);
119 
120  LeafPair* ctop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
121 
122  return ptop != ctop;
123  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_
HashTable< AbstractLeaf *, LeafPair *> _leaf2Pair_

◆ _deassociateLeaf_() [2/2]

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::_deassociateLeaf_ ( AbstractLeaf ,
Int2Type< true >   
)
inlineprivate
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 145 of file fusionContext.h.

145 { return false; }

◆ _updateAllAssociatedLeaves_() [1/2]

template<bool isInitial>
bool gum::FusionContext< isInitial >::_updateAllAssociatedLeaves_ ( Int2Type< false >  )
private
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 97 of file fusionContext_tpl.h.

97  {
98  LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
99  ;
100  for (HashTableConstIteratorSafe< AbstractLeaf*, LeafPair* > pairIter = _leaf2Pair_.cbeginSafe();
101  pairIter != _leaf2Pair_.cendSafe();
102  ++pairIter) {
103  pairIter.val()->updateLikelyhood();
104  _pairsHeap_.setPriority(pairIter.val(), pairIter.val()->likelyhood());
105  }
106  LeafPair* ctop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
107 
108  return ptop != ctop;
109  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_
HashTable< AbstractLeaf *, LeafPair *> _leaf2Pair_

◆ _updateAllAssociatedLeaves_() [2/2]

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::_updateAllAssociatedLeaves_ ( Int2Type< true >  )
inlineprivate
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 132 of file fusionContext.h.

132 { return false; }

◆ _updateAssociatedLeaf_() [1/2]

template<bool isInitial>
bool gum::FusionContext< isInitial >::_updateAssociatedLeaf_ ( AbstractLeaf l,
Int2Type< false >   
)
private
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 84 of file fusionContext_tpl.h.

84  {
85  LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
86  ;
87  _leaf2Pair_[l]->updateLikelyhood();
88  _pairsHeap_.setPriority(_leaf2Pair_[l], _leaf2Pair_[l]->likelyhood());
89 
90  return ptop != _pairsHeap_.top();
91  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_
HashTable< AbstractLeaf *, LeafPair *> _leaf2Pair_

◆ _updateAssociatedLeaf_() [2/2]

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::_updateAssociatedLeaf_ ( AbstractLeaf ,
Int2Type< true >   
)
inlineprivate
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 123 of file fusionContext.h.

123 { return false; }

◆ addPair()

template<bool isInitial>
bool gum::FusionContext< isInitial >::addPair ( LeafPair p)

Definition at line 134 of file fusionContext_tpl.h.

134  {
135  LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
136  _pairsHeap_.insert(p, p->likelyhood());
137 
138  return ptop != _pairsHeap_.top();
139  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_

◆ associatedPairs()

template<bool isInitial = false>
Set< LeafPair* > gum::FusionContext< isInitial >::associatedPairs ( )
inline

Definition at line 212 of file fusionContext.h.

212 { return _associatedPairs_(Int2Type< isInitial >()); }
Set< LeafPair *> _associatedPairs_(Int2Type< false >)

◆ associateLeaf()

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::associateLeaf ( AbstractLeaf l)
inline
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 106 of file fusionContext.h.

106 { return _associateLeaf_(l, Int2Type< isInitial >()); }
bool _associateLeaf_(AbstractLeaf *, Int2Type< false >)

◆ beginPairs()

template<bool isInitial = false>
pair_iterator gum::FusionContext< isInitial >::beginPairs ( )
inline

Definition at line 171 of file fusionContext.h.

171 { return _pairsHeap_.allValues().beginSafe(); }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_

◆ containsAssociatedLeaf()

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::containsAssociatedLeaf ( AbstractLeaf l)
inline
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 92 of file fusionContext.h.

92  {
93  return _containsAssociatedLeaf_(l, Int2Type< isInitial >());
94  }
bool _containsAssociatedLeaf_(AbstractLeaf *l, Int2Type< false >)
Definition: fusionContext.h:97

◆ deassociateLeaf()

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::deassociateLeaf ( AbstractLeaf l)
inline
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 141 of file fusionContext.h.

141 { return _deassociateLeaf_(l, Int2Type< isInitial >()); }
bool _deassociateLeaf_(AbstractLeaf *, Int2Type< false >)

◆ endPairs()

template<bool isInitial = false>
pair_iterator gum::FusionContext< isInitial >::endPairs ( )
inline

Definition at line 172 of file fusionContext.h.

172 { return _pairsHeap_.allValues().endSafe(); }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_

◆ leaf()

template<bool isInitial = false>
AbstractLeaf* gum::FusionContext< isInitial >::leaf ( )
inline

Definition at line 201 of file fusionContext.h.

201 { return _leaf_; }
AbstractLeaf * _leaf_

◆ leafAssociatedPair()

template<bool isInitial = false>
LeafPair* gum::FusionContext< isInitial >::leafAssociatedPair ( AbstractLeaf l)
inline

Definition at line 206 of file fusionContext.h.

206 { return _leaf2Pair_.getWithDefault(l, nullptr); }
HashTable< AbstractLeaf *, LeafPair *> _leaf2Pair_

◆ operator delete()

template<bool isInitial = false>
void gum::FusionContext< isInitial >::operator delete ( void *  p)
inline

Default constructor.

Definition at line 77 of file fusionContext.h.

77  {
79  }
FusionContext(AbstractLeaf *)
Default constructor.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
static SmallObjectAllocator & instance()

◆ operator new()

template<bool isInitial = false>
void* gum::FusionContext< isInitial >::operator new ( size_t  s)
inline

Allocators and Deallocators redefinition.

Definition at line 76 of file fusionContext.h.

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

◆ removePair()

template<bool isInitial>
bool gum::FusionContext< isInitial >::removePair ( LeafPair p)

Definition at line 156 of file fusionContext_tpl.h.

156  {
157  LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
158  _pairsHeap_.erase(p);
159 
160  LeafPair* ctop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
161 
162  return ptop != ctop;
163  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_

◆ top()

template<bool isInitial = false>
LeafPair* gum::FusionContext< isInitial >::top ( )
inline

Definition at line 184 of file fusionContext.h.

184 { return !_pairsHeap_.empty() ? _pairsHeap_.top() : nullptr; }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_

◆ topLikelyhood()

template<bool isInitial = false>
double gum::FusionContext< isInitial >::topLikelyhood ( )
inline

Definition at line 189 of file fusionContext.h.

189 { return !_pairsHeap_.empty() ? _pairsHeap_.topPriority() : 1.0; }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_

◆ toString()

template<bool isInitial>
std::string gum::FusionContext< isInitial >::toString ( )

Definition at line 184 of file fusionContext_tpl.h.

184  {
185  std::stringstream ss;
186  if (_leaf_)
187  ss << "Associated Leaf : " << _leaf_->toString() << std::endl
188  << "Leaves Heap : " << std::endl;
189 
190  // for( HashTableConstIteratorSafe<LeafPair*, std::vector<Size>>
191  // leafIter = _pairsHeap_.allValues().cbeginSafe();
192  // leafIter != _pairsHeap_.allValues().cendSafe(); ++leafIter ){
193  // ss << leafIter.key()->toString() << std::endl;
194  // }
195  if (!_pairsHeap_.empty()) ss << "Top pair : " << _pairsHeap_.top()->toString() << std::endl;
196 
197  return ss.str();
198  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_
virtual std::string toString()=0
AbstractLeaf * _leaf_

◆ updateAllAssociatedLeaves()

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::updateAllAssociatedLeaves ( )
inline
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 126 of file fusionContext.h.

126  {
127  return _updateAllAssociatedLeaves_(Int2Type< isInitial >());
128  }
bool _updateAllAssociatedLeaves_(Int2Type< false >)

◆ updateAssociatedLeaf()

template<bool isInitial = false>
bool gum::FusionContext< isInitial >::updateAssociatedLeaf ( AbstractLeaf l)
inline
Warning
: won't delete Associated Pair created (because subsequent fusioncontexts might be using it)

Definition at line 117 of file fusionContext.h.

117  {
118  return _updateAssociatedLeaf_(l, Int2Type< isInitial >());
119  }
bool _updateAssociatedLeaf_(AbstractLeaf *, Int2Type< false >)

◆ updatePair()

template<bool isInitial>
bool gum::FusionContext< isInitial >::updatePair ( LeafPair p)

Definition at line 145 of file fusionContext_tpl.h.

145  {
146  LeafPair* ptop = _pairsHeap_.empty() ? nullptr : _pairsHeap_.top();
147  _pairsHeap_.setPriority(p, p->likelyhood());
148 
149  return ptop != _pairsHeap_.top();
150  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > _pairsHeap_

Member Data Documentation

◆ _leaf2Pair_

template<bool isInitial = false>
HashTable< AbstractLeaf*, LeafPair* > gum::FusionContext< isInitial >::_leaf2Pair_
private

Definition at line 225 of file fusionContext.h.

◆ _leaf_

template<bool isInitial = false>
AbstractLeaf* gum::FusionContext< isInitial >::_leaf_
private

Definition at line 227 of file fusionContext.h.

◆ _pairsHeap_

template<bool isInitial = false>
MultiPriorityQueue< LeafPair*, double, std::less< double > > gum::FusionContext< isInitial >::_pairsHeap_
private

Definition at line 223 of file fusionContext.h.


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