aGrUM  0.16.0
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 58 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();
56  leafIter != __leaf2Pair.endSafe();
57  ++leafIter)
58  delete leafIter.val();
59 
60  delete __leaf;
61  }
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 181 of file fusionContext_tpl.h.

Referenced by gum::FusionContext< true >::associatedPairs().

181  {
182  Set< LeafPair* > retBag;
183  for (auto pairIter = __leaf2Pair.beginSafe();
184  pairIter != __leaf2Pair.endSafe();
185  ++pairIter)
186  retBag << pairIter.val();
187 
188  return retBag;
189  }
HashTable< AbstractLeaf *, LeafPair *> __leaf2Pair
+ Here is the caller graph for this function:

◆ __associatedPairs() [2/2]

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

Definition at line 232 of file fusionContext.h.

232  {
233  return Set< LeafPair* >();
234  }

◆ __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 71 of file fusionContext_tpl.h.

Referenced by gum::FusionContext< true >::associateLeaf().

72  {
73  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
74  ;
75  LeafPair* p = new LeafPair(l, __leaf);
76  __leaf2Pair.insert(l, p);
77  __leaf2Pair[l]->updateLikelyhood();
78  __pairsHeap.insert(p, p->likelyhood());
79 
80  return ptop != __pairsHeap.top();
81  }
HashTable< AbstractLeaf *, LeafPair *> __leaf2Pair
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
AbstractLeaf * __leaf
+ Here is the caller graph for this function:

◆ __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 118 of file fusionContext.h.

118 { 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 101 of file fusionContext.h.

Referenced by gum::FusionContext< true >::containsAssociatedLeaf().

101  {
102  return __leaf2Pair.exists(l);
103  }
HashTable< AbstractLeaf *, LeafPair *> __leaf2Pair
+ Here is the caller graph for this function:

◆ __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 104 of file fusionContext.h.

104  {
105  return false;
106  }

◆ __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 120 of file fusionContext_tpl.h.

Referenced by gum::FusionContext< true >::deassociateLeaf().

121  {
122  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
123  __pairsHeap.erase(__leaf2Pair[l]);
124  __leaf2Pair.erase(l);
125 
126  LeafPair* ctop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
127 
128  return ptop != ctop;
129  }
HashTable< AbstractLeaf *, LeafPair *> __leaf2Pair
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

◆ __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 155 of file fusionContext.h.

155 { 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 101 of file fusionContext_tpl.h.

Referenced by gum::FusionContext< true >::updateAllAssociatedLeaves().

101  {
102  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
103  ;
104  for (HashTableConstIteratorSafe< AbstractLeaf*, LeafPair* > pairIter =
105  __leaf2Pair.cbeginSafe();
106  pairIter != __leaf2Pair.cendSafe();
107  ++pairIter) {
108  pairIter.val()->updateLikelyhood();
109  __pairsHeap.setPriority(pairIter.val(), pairIter.val()->likelyhood());
110  }
111  LeafPair* ctop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
112 
113  return ptop != ctop;
114  }
HashTable< AbstractLeaf *, LeafPair *> __leaf2Pair
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

◆ __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 140 of file fusionContext.h.

140 { 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 87 of file fusionContext_tpl.h.

Referenced by gum::FusionContext< true >::updateAssociatedLeaf().

88  {
89  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
90  ;
91  __leaf2Pair[l]->updateLikelyhood();
92  __pairsHeap.setPriority(__leaf2Pair[l], __leaf2Pair[l]->likelyhood());
93 
94  return ptop != __pairsHeap.top();
95  }
HashTable< AbstractLeaf *, LeafPair *> __leaf2Pair
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

◆ __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 131 of file fusionContext.h.

131 { return false; }

◆ addPair()

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

Definition at line 140 of file fusionContext_tpl.h.

Referenced by gum::LeafAggregator::__addInitialPair(), gum::FusionContext< true >::__deassociateLeaf(), and gum::LeafAggregator::update().

140  {
141  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
142  __pairsHeap.insert(p, p->likelyhood());
143 
144  return ptop != __pairsHeap.top();
145  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

◆ associatedPairs()

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

Definition at line 226 of file fusionContext.h.

226  {
227  return __associatedPairs(Int2Type< isInitial >());
228  }
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 112 of file fusionContext.h.

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

112  {
113  return __associateLeaf(l, Int2Type< isInitial >());
114  }
bool __associateLeaf(AbstractLeaf *, Int2Type< false >)
+ Here is the caller graph for this function:

◆ beginPairs()

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

Definition at line 181 of file fusionContext.h.

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

181 { return __pairsHeap.allValues().beginSafe(); }
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

◆ 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 96 of file fusionContext.h.

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

96  {
97  return __containsAssociatedLeaf(l, Int2Type< isInitial >());
98  }
bool __containsAssociatedLeaf(AbstractLeaf *l, Int2Type< false >)
+ Here is the caller graph for this function:

◆ 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 149 of file fusionContext.h.

149  {
150  return __deassociateLeaf(l, Int2Type< isInitial >());
151  }
bool __deassociateLeaf(AbstractLeaf *, Int2Type< false >)

◆ endPairs()

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

Definition at line 182 of file fusionContext.h.

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

182 { return __pairsHeap.allValues().endSafe(); }
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

◆ leaf()

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

Definition at line 213 of file fusionContext.h.

213 { return __leaf; }
AbstractLeaf * __leaf

◆ leafAssociatedPair()

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

Definition at line 218 of file fusionContext.h.

218  {
219  return __leaf2Pair.getWithDefault(l, nullptr);
220  }
HashTable< AbstractLeaf *, LeafPair *> __leaf2Pair

◆ operator delete()

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

Default constructor.

Definition at line 81 of file fusionContext.h.

81  {
83  }
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 78 of file fusionContext.h.

78  {
80  }
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 162 of file fusionContext_tpl.h.

Referenced by gum::FusionContext< true >::__deassociateLeaf(), and gum::LeafAggregator::__removeInitialPair().

162  {
163  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
164  __pairsHeap.erase(p);
165 
166  LeafPair* ctop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
167 
168  return ptop != ctop;
169  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

◆ top()

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

Definition at line 194 of file fusionContext.h.

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

194 { return !__pairsHeap.empty() ? __pairsHeap.top() : nullptr; }
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

◆ topLikelyhood()

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

Definition at line 199 of file fusionContext.h.

199  {
200  return !__pairsHeap.empty() ? __pairsHeap.topPriority() : 1.0;
201  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap

◆ toString()

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

Definition at line 193 of file fusionContext_tpl.h.

Referenced by gum::FusionContext< true >::__associatedPairs(), gum::LeafAggregator::toString(), and gum::FusionContext< true >::toString().

193  {
194  std::stringstream ss;
195  if (__leaf)
196  ss << "Associated Leaf : " << __leaf->toString() << std::endl
197  << "Leaves Heap : " << std::endl;
198 
199  // for( HashTableConstIteratorSafe<LeafPair*, std::vector<Size>>
200  // leafIter = __pairsHeap.allValues().cbeginSafe();
201  // leafIter != __pairsHeap.allValues().cendSafe(); ++leafIter ){
202  // ss << leafIter.key()->toString() << std::endl;
203  // }
204  if (!__pairsHeap.empty())
205  ss << "Top pair : " << __pairsHeap.top()->toString() << std::endl;
206 
207  return ss.str();
208  }
virtual std::string toString()=0
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
AbstractLeaf * __leaf
+ Here is the caller graph for this function:

◆ 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 134 of file fusionContext.h.

134  {
135  return __updateAllAssociatedLeaves(Int2Type< isInitial >());
136  }
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 125 of file fusionContext.h.

125  {
126  return __updateAssociatedLeaf(l, Int2Type< isInitial >());
127  }
bool __updateAssociatedLeaf(AbstractLeaf *, Int2Type< false >)

◆ updatePair()

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

Definition at line 151 of file fusionContext_tpl.h.

Referenced by gum::FusionContext< true >::__deassociateLeaf(), and gum::LeafAggregator::__updateInitialPair().

151  {
152  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
153  __pairsHeap.setPriority(p, p->likelyhood());
154 
155  return ptop != __pairsHeap.top();
156  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap
+ Here is the caller graph for this function:

Member Data Documentation

◆ __leaf

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

Definition at line 245 of file fusionContext.h.

Referenced by gum::FusionContext< true >::leaf().

◆ __leaf2Pair

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

◆ __pairsHeap


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