aGrUM  0.14.2
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 55 of file fusionContext.h.

Constructor & Destructor Documentation

◆ FusionContext()

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

Default constructor.

Definition at line 41 of file fusionContext_tpl.h.

41  : __leaf(leaf) {
42  GUM_CONSTRUCTOR(FusionContext);
43  }
AbstractLeaf * leaf()
FusionContext(AbstractLeaf *)
Default constructor.
AbstractLeaf * __leaf

◆ ~FusionContext()

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

Default destructor.

Definition at line 49 of file fusionContext_tpl.h.

49  {
50  GUM_DESTRUCTOR(FusionContext);
51 
52  for (auto leafIter = __leaf2Pair.beginSafe();
53  leafIter != __leaf2Pair.endSafe();
54  ++leafIter)
55  delete leafIter.val();
56 
57  delete __leaf;
58  }
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 178 of file fusionContext_tpl.h.

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

178  {
179  Set< LeafPair* > retBag;
180  for (auto pairIter = __leaf2Pair.beginSafe();
181  pairIter != __leaf2Pair.endSafe();
182  ++pairIter)
183  retBag << pairIter.val();
184 
185  return retBag;
186  }
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 229 of file fusionContext.h.

229  {
230  return Set< LeafPair* >();
231  }

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

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

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  }
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 115 of file fusionContext.h.

115 { 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 98 of file fusionContext.h.

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

98  {
99  return __leaf2Pair.exists(l);
100  }
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 101 of file fusionContext.h.

101  {
102  return false;
103  }

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

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

118  {
119  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
120  __pairsHeap.erase(__leaf2Pair[l]);
121  __leaf2Pair.erase(l);
122 
123  LeafPair* ctop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
124 
125  return ptop != ctop;
126  }
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 152 of file fusionContext.h.

152 { 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 98 of file fusionContext_tpl.h.

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

98  {
99  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
100  ;
101  for (HashTableConstIteratorSafe< AbstractLeaf*, LeafPair* > pairIter =
102  __leaf2Pair.cbeginSafe();
103  pairIter != __leaf2Pair.cendSafe();
104  ++pairIter) {
105  pairIter.val()->updateLikelyhood();
106  __pairsHeap.setPriority(pairIter.val(), pairIter.val()->likelyhood());
107  }
108  LeafPair* ctop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
109 
110  return ptop != ctop;
111  }
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 137 of file fusionContext.h.

137 { 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.

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

85  {
86  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
87  ;
88  __leaf2Pair[l]->updateLikelyhood();
89  __pairsHeap.setPriority(__leaf2Pair[l], __leaf2Pair[l]->likelyhood());
90 
91  return ptop != __pairsHeap.top();
92  }
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 128 of file fusionContext.h.

128 { return false; }

◆ addPair()

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

Definition at line 137 of file fusionContext_tpl.h.

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

137  {
138  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
139  __pairsHeap.insert(p, p->likelyhood());
140 
141  return ptop != __pairsHeap.top();
142  }
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 223 of file fusionContext.h.

223  {
224  return __associatedPairs(Int2Type< isInitial >());
225  }
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 109 of file fusionContext.h.

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

109  {
110  return __associateLeaf(l, Int2Type< isInitial >());
111  }
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 178 of file fusionContext.h.

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

178 { 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 93 of file fusionContext.h.

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

93  {
94  return __containsAssociatedLeaf(l, Int2Type< isInitial >());
95  }
bool __containsAssociatedLeaf(AbstractLeaf *l, Int2Type< false >)
Definition: fusionContext.h:98
+ 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 146 of file fusionContext.h.

146  {
147  return __deassociateLeaf(l, Int2Type< isInitial >());
148  }
bool __deassociateLeaf(AbstractLeaf *, Int2Type< false >)

◆ endPairs()

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

Definition at line 179 of file fusionContext.h.

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

179 { 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 210 of file fusionContext.h.

210 { return __leaf; }
AbstractLeaf * __leaf

◆ leafAssociatedPair()

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

Definition at line 215 of file fusionContext.h.

215  {
216  return __leaf2Pair.getWithDefault(l, nullptr);
217  }
HashTable< AbstractLeaf *, LeafPair *> __leaf2Pair

◆ operator delete()

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

Default constructor.

Definition at line 78 of file fusionContext.h.

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

75  {
77  }
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 159 of file fusionContext_tpl.h.

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

159  {
160  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
161  __pairsHeap.erase(p);
162 
163  LeafPair* ctop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
164 
165  return ptop != ctop;
166  }
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 191 of file fusionContext.h.

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

191 { 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 196 of file fusionContext.h.

196  {
197  return !__pairsHeap.empty() ? __pairsHeap.topPriority() : 1.0;
198  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > __pairsHeap

◆ toString()

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

Definition at line 190 of file fusionContext_tpl.h.

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

190  {
191  std::stringstream ss;
192  if (__leaf)
193  ss << "Associated Leaf : " << __leaf->toString() << std::endl
194  << "Leaves Heap : " << std::endl;
195 
196  // for( HashTableConstIteratorSafe<LeafPair*, std::vector<Size>>
197  // leafIter = __pairsHeap.allValues().cbeginSafe();
198  // leafIter != __pairsHeap.allValues().cendSafe(); ++leafIter ){
199  // ss << leafIter.key()->toString() << std::endl;
200  // }
201  if (!__pairsHeap.empty())
202  ss << "Top pair : " << __pairsHeap.top()->toString() << std::endl;
203 
204  return ss.str();
205  }
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 131 of file fusionContext.h.

131  {
132  return __updateAllAssociatedLeaves(Int2Type< isInitial >());
133  }
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 122 of file fusionContext.h.

122  {
123  return __updateAssociatedLeaf(l, Int2Type< isInitial >());
124  }
bool __updateAssociatedLeaf(AbstractLeaf *, Int2Type< false >)

◆ updatePair()

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

Definition at line 148 of file fusionContext_tpl.h.

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

148  {
149  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
150  __pairsHeap.setPriority(p, p->likelyhood());
151 
152  return ptop != __pairsHeap.top();
153  }
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 242 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: