Dynamic tree structure with weighted items in each node which are markable through out the tree.
More...
|
| template<class Ts> |
| void | seed (const Ts &items) |
| | Take the item set and insert them into the top node of the hough space.
|
| |
| template<class AItemInDomainMeasure> |
| std::vector< std::pair< ADomain, std::vector< T > > > | findHeavyLeavesDisjoint (AItemInDomainMeasure &weightItemInDomain, int maxLevel, double minWeight) |
| | Find all children node at maximum level and add them to the result list. Skip nodes if their weight is below minWeight.
|
| |
| template<class AItemInDomainMeasure, class ASkipNodePredicate> |
| std::vector< std::pair< ADomain, std::vector< T > > > | findLeavesDisjoint (AItemInDomainMeasure &weightItemInDomain, int maxLevel, ASkipNodePredicate &skipNode) |
| | Find all children node at maximum level and add them to the result list. Skip nodes if skipNode returns true.
|
| |
| template<class AItemInDomainMeasure, class ASkipNodePredicate> |
| std::vector< std::pair< ADomain, std::vector< T > > > | findHeaviestLeafRepeated (AItemInDomainMeasure &weightItemInDomain, int maxLevel, ASkipNodePredicate &skipNode) |
| | Go through all children until maxLevel is reached and find the heaviest leaves.
|
| |
| template<class AItemInDomainMeasure, class ASkipNodePredicate> |
| std::unique_ptr< std::pair< ADomain, std::vector< T > > > | findHeaviestLeafSingle (AItemInDomainMeasure &weightItemInDomain, int maxLevel, ASkipNodePredicate &skipNode) |
| | Go through all children until the maxLevel is reached and find the leaf with the highest weight.
|
| |
| template<class AItemInDomainMeasure, class ASkipNodePredicate> |
| Node * | findHeaviestLeaf (AItemInDomainMeasure &weightItemInDomain, int maxLevel, ASkipNodePredicate &skipNode) |
| | Go through all children until the maxLevel is reached and find the leaf with the highest weight.
|
| |
| template<class AItemInDomainMeasure, class AIsLeafPredicate> |
| void | fillWalk (AItemInDomainMeasure &weightItemInDomain, AIsLeafPredicate &isLeaf, bool isLeafMarksItems=true) |
| | Walk through the children and fill them if necessary until isLeaf returns true.
|
| |
| template<class ATreeWalker> |
| void | walkHeighWeightFirst (ATreeWalker &walker, bool walkerMarksItems=true) |
| | Walk the tree investigating the heaviest children with priority.
|
| |
| void | fell () |
| | Fell to tree meaning deleting all child nodes from the tree. Keeps the top node.
|
| |
| void | raze () |
| | Like fell but also releases all memory the tree has acquired during long executions.
|
| |
| Node & | getTopNode () |
| | Getter for the top node of the tree.
|
| |
| const Node & | getTopNode () const |
| | Constant getter for the top node of the tree.
|
| |
| Node & | getTopNode () |
| | Getter for the top node of the tree.
|
| |
| const Node & | getTopNode () const |
| | Constant getter for the top node of the tree.
|
| |
| int | getNNodes () const |
| | Gets the number of nodes currently contained in the tree Also demonstrates how to walk over the tree.
|
| |
| int | getNNodes () const |
| | Gets the number of nodes currently contained in the tree Also demonstrates how to walk over the tree.
|
| |
| std::map< int, int > | getNNodesByLevel () const |
| | Gets the number of nodes by level in the tree Also demonstrates how to walk over the tree.
|
| |
| std::map< int, int > | getNNodesByLevel () const |
| | Gets the number of nodes by level in the tree Also demonstrates how to walk over the tree.
|
| |
| void | walk (AWalker &walker) |
| | Forward walk to the top node.
|
| |
| void | walk (AWalker &walker, APriorityMeasure &priority) |
| | Forward walk to the top node.
|
| |
| void | walk (AWalker &walker) |
| | Forward walk to the top node.
|
| |
| void | walk (AWalker &walker, APriorityMeasure &priority) |
| | Forward walk to the top node.
|
| |
template<class T, class ADomain, class ADomainDivsion>
class Belle2::TrackFindingCDC::WeightedFastHoughTree< T, ADomain, ADomainDivsion >
Dynamic tree structure with weighted items in each node which are markable through out the tree.
Used to build fast hough type algorithms, where objects are allowed to carry weights relative to the hough space part (here called a ADomain) they are contained in. The shared marks allow for iterative extraction of hough peaks such that other areas of the hough space notice that certain element have already been consumed.
Definition at line 51 of file WeightedFastHoughTree.h.
template<class T, class ADomain, class ADomainDivsion>
template<class AItemInDomainMeasure, class AIsLeafPredicate>
| void fillWalk |
( |
AItemInDomainMeasure & | weightItemInDomain, |
|
|
AIsLeafPredicate & | isLeaf, |
|
|
bool | isLeafMarksItems = true ) |
|
inline |
Walk through the children and fill them if necessary until isLeaf returns true.
Uses the weightItemInDomain to create weights for the items (or decide if an item belongs to a mode or not).
Definition at line 243 of file WeightedFastHoughTree.h.
246 {
247 auto walker = [&weightItemInDomain, &isLeaf](Node * node) {
248
249
250 if (isLeaf(node)) {
251
252 return false;
253 }
254
255
256
257
258 typename Node::Children* children = node->getChildren();
259 if (not children) {
260 node->createChildren();
261 children = node->getChildren();
262 if constexpr(std::is_invocable_v<AItemInDomainMeasure&, const T&, Node*>) {
263
264
265 for (const WithSharedMark<T>& markableItem : *node) {
266
267 const T& item(markableItem);
268 for (Node& childNode : *children) {
269 const TrackingUtilities::Weight weight = weightItemInDomain(item, &childNode);
270 if (not std::isnan(weight)) {
271 childNode.insert(markableItem, weight);
272 }
273 }
274 }
275 } else {
276 for (Node& childNode : *children) {
277 assert(childNode.getChildren() == nullptr);
278 assert(childNode.size() == 0);
279 auto measure =
280
281 [&childNode, &weightItemInDomain](WithSharedMark<T>& markableItem) -> TrackingUtilities::Weight {
282
283 T & item(markableItem);
284 return weightItemInDomain(item, &childNode);
285 };
286 childNode.insert(*node, measure);
287 }
288 }
289 }
290
291 return true;
292 };
293 walkHeighWeightFirst(walker, isLeafMarksItems);
294 }
template<class T, class ADomain, class ADomainDivsion>
template<class AItemInDomainMeasure, class ASkipNodePredicate>
| Node * findHeaviestLeaf |
( |
AItemInDomainMeasure & | weightItemInDomain, |
|
|
int | maxLevel, |
|
|
ASkipNodePredicate & | skipNode ) |
|
inline |
Go through all children until the maxLevel is reached and find the leaf with the highest weight.
If no node could be found, return a nullptr. A node is skipped if skipNode is returns true for this node.
Definition at line 203 of file WeightedFastHoughTree.h.
206 {
207 Node* heaviestNode = nullptr;
208 TrackingUtilities::Weight heighestWeigth = NAN;
209 auto isLeaf = [&heaviestNode, &heighestWeigth, maxLevel, &skipNode](Node * node) {
210
211 if (skipNode(node)) {
212 return true;
213 }
214
215 TrackingUtilities::Weight nodeWeight = node->getWeight();
216
217 if (not std::isnan(heighestWeigth) and not(nodeWeight > heighestWeigth)) {
218 return true;
219 }
220
221
222
223
224 if (node->getLevel() >= maxLevel) {
225 heaviestNode = node;
226 heighestWeigth = nodeWeight;
227 return true;
228 }
229 return false;
230 };
231
232 const bool isLeafMarksItems = false;
233 fillWalk(weightItemInDomain, isLeaf, isLeafMarksItems);
234 return heaviestNode;
235 }
template<class T, class ADomain, class ADomainDivsion>
template<class AItemInDomainMeasure, class ASkipNodePredicate>
| std::vector< std::pair< ADomain, std::vector< T > > > findHeaviestLeafRepeated |
( |
AItemInDomainMeasure & | weightItemInDomain, |
|
|
int | maxLevel, |
|
|
ASkipNodePredicate & | skipNode ) |
|
inline |
Go through all children until maxLevel is reached and find the heaviest leaves.
For this, the single heaviest leaf is found and added to an internal list. The process is repeated until no leaf can be found anymore. A node is skipped if skipNode is returns true for this node.
Definition at line 156 of file WeightedFastHoughTree.h.
159 {
160 std::vector<std::pair<ADomain, std::vector<T> > > found;
161 Node* node = findHeaviestLeaf(weightItemInDomain, maxLevel, skipNode);
162 while (node) {
163 const ADomain* domain = node;
164 found.emplace_back(*domain, std::vector<T>(node->begin(), node->end()));
165 for (WithSharedMark<T>& markableItem : *node) {
166 markableItem.mark();
167 }
168 node = findHeaviestLeaf(weightItemInDomain, maxLevel, skipNode);
169 }
170 return found;
171 }
template<class T, class ADomain, class ADomainDivsion>
template<class AItemInDomainMeasure>
| static std::vector< std::pair< ADomain, std::vector< T > > > findHeaviestLeafRepeated |
( |
AItemInDomainMeasure & | weightItemInDomain, |
|
|
int | maxLevel, |
|
|
const TrackingUtilities::Weight | minWeight = NAN ) |
|
inlinestatic |
Go through all children until maxLevel is reached and find the heaviest leaves.
For this, the single heaviest leaf is found and added to an internal list. The process is repeated until no leaf can be found anymore. A node is skipped if the weight is below minWeight.
Definition at line 137 of file WeightedFastHoughTree.h.
140 {
141 auto skipLowWeightNode = [minWeight](const Node * node) {
142 return not(node->getWeight() >= minWeight);
143 };
144 return findHeaviestLeafRepeated(weightItemInDomain, maxLevel, skipLowWeightNode);
145 }
template<class T, class ADomain, class ADomainDivsion>
template<class AItemInDomainMeasure, class ASkipNodePredicate>
| std::unique_ptr< std::pair< ADomain, std::vector< T > > > findHeaviestLeafSingle |
( |
AItemInDomainMeasure & | weightItemInDomain, |
|
|
int | maxLevel, |
|
|
ASkipNodePredicate & | skipNode ) |
|
inline |
Go through all children until the maxLevel is reached and find the leaf with the highest weight.
If no node could be found, return an empty list, otherwise return a list with just on element. A node is skipped if skipNode is returns true for this node.
Definition at line 180 of file WeightedFastHoughTree.h.
183 {
184 using Result = std::pair<ADomain, std::vector<T> >;
185 std::unique_ptr<Result> found = nullptr;
186 Node* node = findHeaviestLeaf(weightItemInDomain, maxLevel, skipNode);
187 if (node) {
188 const ADomain* domain = node;
189 found.reset(new Result(*domain, std::vector<T>(node->begin(), node->end())));
190 for (WithSharedMark<T>& markableItem : *node) {
191 markableItem.mark();
192 }
193 }
194 return found;
195 }
template<class T, class ADomain, class ADomainDivsion>
template<class ATreeWalker>
| void walkHeighWeightFirst |
( |
ATreeWalker & | walker, |
|
|
bool | walkerMarksItems = true ) |
|
inline |
Walk the tree investigating the heaviest children with priority.
If the walker is known not to mark items and no item is marked yet, the removal of marked items can be skipped as it would never erase anything.
Clear items that have been marked as used before evaluating the weight.
Definition at line 302 of file WeightedFastHoughTree.h.
303 {
304 if (not walkerMarksItems and std::find(m_marks.begin(), m_marks.end(), true) == m_marks.end()) {
305 auto unmarkedPriority = [](Node * node) -> float {
306 return node->getWeight();
307 };
308 this->walk(walker, unmarkedPriority);
309 return;
310 }
311
312 auto priority = [](Node * node) -> float {
314 auto isMarked = [](const WithSharedMark<T>& markableItem) -> bool {
315 return markableItem.isMarked();
316 };
317 node->eraseIf(isMarked);
318 return node->getWeight();
319 };
320
321 this->walk(walker, priority);
322 }