aGrUM  0.16.0
fusionContext_tpl.h
Go to the documentation of this file.
1 
29 // =======================================================
30 #include <agrum/core/math/math.h>
32 // =======================================================
33 
34 namespace gum {
35 
36  // ############################################################################
37  // Constructors / Destructors
38  // ############################################################################
39 
40  // ============================================================================
41  // Default constructor.
42  // ============================================================================
43  template < bool isInitial >
45  GUM_CONSTRUCTOR(FusionContext);
46  }
47 
48  // ============================================================================
49  // Default constructor.
50  // ============================================================================
51  template < bool isInitial >
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  }
62 
63  // ############################################################################
64  //
65  // ############################################################################
66 
67  // ============================================================================
68  //
69  // ============================================================================
70  template < bool isInitial >
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  }
82 
83  // ============================================================================
84  //
85  // ============================================================================
86  template < bool isInitial >
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  }
96 
97  // ============================================================================
98  //
99  // ============================================================================
100  template < bool isInitial >
102  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
103  ;
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  }
115 
116  // ============================================================================
117  //
118  // ============================================================================
119  template < bool isInitial >
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  }
130 
131 
132  // ############################################################################
133  //
134  // ############################################################################
135 
136  // ============================================================================
137  //
138  // ============================================================================
139  template < bool isInitial >
141  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
142  __pairsHeap.insert(p, p->likelyhood());
143 
144  return ptop != __pairsHeap.top();
145  }
146 
147  // ============================================================================
148  //
149  // ============================================================================
150  template < bool isInitial >
152  LeafPair* ptop = __pairsHeap.empty() ? nullptr : __pairsHeap.top();
153  __pairsHeap.setPriority(p, p->likelyhood());
154 
155  return ptop != __pairsHeap.top();
156  }
157 
158  // ============================================================================
159  //
160  // ============================================================================
161  template < bool isInitial >
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  }
170 
171 
172  // ############################################################################
173  //
174  // ############################################################################
175 
176  // ============================================================================
177  //
178  // ============================================================================
179  template < bool isInitial >
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  }
190 
191 
192  template < bool isInitial >
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  }
209 
210 } // namespace gum
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/FMDP/learning/datastructure/leaves/fusionContext.h>
Definition: fusionContext.h:58
<agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
Definition: abstractLeaf.h:53
Safe Const Iterators for hashtables.
Definition: hashTable.h:1918
<agrum/FMDP/learning/datastructure/leaves/leafPair.h>
Definition: leafPair.h:51
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
FusionContext(AbstractLeaf *)
Default constructor.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
std::string toString()
double likelyhood()
Updates GStatistic.
Definition: leafPair.cpp:77
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void updateLikelyhood()
Updates GStatistic.
Definition: leafPair.cpp:42