aGrUM  0.20.2
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 57 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.
AbstractLeaf * leaf__
HashTable< AbstractLeaf *, LeafPair *> leaf2Pair__

Member Function Documentation

◆ addPair()

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

Definition at line 140 of file fusionContext_tpl.h.

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__

◆ associatedPairs()

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

Definition at line 225 of file fusionContext.h.

225  {
226  return associatedPairs__(Int2Type< isInitial >());
227  }
Set< LeafPair *> associatedPairs__(Int2Type< false >)

◆ associatedPairs__() [1/2]

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

Definition at line 181 of file fusionContext_tpl.h.

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__

◆ associatedPairs__() [2/2]

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

Definition at line 231 of file fusionContext.h.

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

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

111  {
112  return associateLeaf__(l, Int2Type< isInitial >());
113  }
bool associateLeaf__(AbstractLeaf *, Int2Type< false >)

◆ 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.

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  }
MultiPriorityQueue< LeafPair *, double, std::less< double > > pairsHeap__
AbstractLeaf * leaf__
HashTable< AbstractLeaf *, LeafPair *> leaf2Pair__

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

117 { return false; }

◆ beginPairs()

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

Definition at line 180 of file fusionContext.h.

180 { 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 95 of file fusionContext.h.

95  {
96  return containsAssociatedLeaf__(l, Int2Type< isInitial >());
97  }
bool containsAssociatedLeaf__(AbstractLeaf *l, Int2Type< 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 100 of file fusionContext.h.

100  {
101  return leaf2Pair__.exists(l);
102  }
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 103 of file fusionContext.h.

103  {
104  return false;
105  }

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

148  {
149  return deassociateLeaf__(l, Int2Type< isInitial >());
150  }
bool deassociateLeaf__(AbstractLeaf *, Int2Type< 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 120 of file fusionContext_tpl.h.

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

154 { return false; }

◆ endPairs()

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

Definition at line 181 of file fusionContext.h.

181 { 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 212 of file fusionContext.h.

212 { return leaf__; }
AbstractLeaf * leaf__

◆ leafAssociatedPair()

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

Definition at line 217 of file fusionContext.h.

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

◆ operator delete()

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

Default constructor.

Definition at line 80 of file fusionContext.h.

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

77  {
79  }
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.

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__

◆ top()

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

Definition at line 193 of file fusionContext.h.

193 { 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 198 of file fusionContext.h.

198  {
199  return !pairsHeap__.empty() ? pairsHeap__.topPriority() : 1.0;
200  }
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.

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

133  {
134  return updateAllAssociatedLeaves__(Int2Type< isInitial >());
135  }
bool updateAllAssociatedLeaves__(Int2Type< 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.

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

139 { return 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 124 of file fusionContext.h.

124  {
125  return updateAssociatedLeaf__(l, Int2Type< isInitial >());
126  }
bool updateAssociatedLeaf__(AbstractLeaf *, Int2Type< 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.

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

130 { return false; }

◆ updatePair()

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

Definition at line 151 of file fusionContext_tpl.h.

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__

Member Data Documentation

◆ leaf2Pair__

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

Definition at line 242 of file fusionContext.h.

◆ leaf__

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

Definition at line 244 of file fusionContext.h.

◆ pairsHeap__

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

Definition at line 240 of file fusionContext.h.


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