gtsam
Loading...
Searching...
No Matches
EliminateableFactorGraph-inst.h
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
18
19#pragma once
20
25
26#ifdef GTSAM_USE_TBB
27#include <mutex>
28#endif
29#include <unordered_set>
30
31namespace gtsam {
32
33 /* ************************************************************************* */
34 template<class FACTORGRAPH>
35 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
37 OptionalOrderingType orderingType, const Eliminate& function,
38 OptionalVariableIndex variableIndex) const {
39 if(!variableIndex) {
40 // If no VariableIndex provided, compute one and call this function again IMPORTANT: we check
41 // for no variable index first so that it's always computed if we need to call COLAMD because
42 // no Ordering is provided. When removing optional from VariableIndex, create VariableIndex
43 // before creating ordering.
44 VariableIndex computedVariableIndex(asDerived());
45 return eliminateSequential(orderingType, function, std::cref(computedVariableIndex));
46 }
47 else {
48 // Compute an ordering and call this function again. We are guaranteed to have a
49 // VariableIndex already here because we computed one if needed in the previous 'if' block.
50 if (orderingType == Ordering::METIS) {
51 Ordering computedOrdering = Ordering::Metis(asDerived());
52 return eliminateSequential(computedOrdering, function, variableIndex);
53 } else if (orderingType == Ordering::COLAMD) {
54 Ordering computedOrdering = Ordering::Colamd((*variableIndex).get());
55 return eliminateSequential(computedOrdering, function, variableIndex);
56 } else if (orderingType == Ordering::NATURAL) {
57 Ordering computedOrdering = Ordering::Natural(asDerived());
58 return eliminateSequential(computedOrdering, function, variableIndex);
59 } else {
60 Ordering computedOrdering = EliminationTraitsType::DefaultOrderingFunc(
61 asDerived(), *variableIndex);
62 return eliminateSequential(computedOrdering, function, variableIndex);
63 }
64 }
65 }
66
67 /* ************************************************************************* */
68 template<class FACTORGRAPH>
69 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
71 const Ordering& ordering, const Eliminate& function,
72 OptionalVariableIndex variableIndex) const
73 {
74 if(!variableIndex) {
75 // If no VariableIndex provided, compute one and call this function again
76 VariableIndex computedVariableIndex(asDerived());
77 return eliminateSequential(ordering, function, std::cref(computedVariableIndex));
78 } else {
80 // Do elimination
81 EliminationTreeType etree(asDerived(), (*variableIndex).get(), ordering);
82 const auto [bayesNet, factorGraph] = etree.eliminate(function);
83 // If any factors are remaining, the ordering was incomplete
84 if(!factorGraph->empty()) {
85 throw InconsistentEliminationRequested(factorGraph->keys());
86 }
87 // Return the Bayes net
88 return bayesNet;
89 }
90 }
91
92 /* ************************************************************************* */
93 template <class FACTORGRAPH>
94 std::shared_ptr<
97 OptionalOrderingType orderingType, const Eliminate& function,
98 OptionalVariableIndex variableIndex) const {
99 if (!variableIndex) {
100 // If no VariableIndex provided, compute one and call this function again
101 // IMPORTANT: we check for no variable index first so that it's always
102 // computed if we need to call COLAMD because no Ordering is provided.
103 // When removing optional from VariableIndex, create VariableIndex before
104 // creating ordering.
105 VariableIndex computedVariableIndex(asDerived());
106 return eliminateMultifrontal(orderingType, function,
107 std::cref(computedVariableIndex));
108 } else {
109 // Compute an ordering and call this function again. We are guaranteed to
110 // have a VariableIndex already here because we computed one if needed in
111 // the previous 'if' block.
112 if (orderingType == Ordering::METIS) {
113 Ordering computedOrdering = Ordering::Metis(asDerived());
114 return eliminateMultifrontal(computedOrdering, function, variableIndex);
115 } else if (orderingType == Ordering::COLAMD) {
116 Ordering computedOrdering = Ordering::Colamd((*variableIndex).get());
117 return eliminateMultifrontal(computedOrdering, function, variableIndex);
118 } else if (orderingType == Ordering::NATURAL) {
119 Ordering computedOrdering = Ordering::Natural(asDerived());
120 return eliminateMultifrontal(computedOrdering, function, variableIndex);
121 } else {
122 Ordering computedOrdering = EliminationTraitsType::DefaultOrderingFunc(
123 asDerived(), *variableIndex);
124 return eliminateMultifrontal(computedOrdering, function, variableIndex);
125 }
126 }
127 }
128
129 /* ************************************************************************* */
130 template<class FACTORGRAPH>
131 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
133 const Ordering& ordering, const Eliminate& function,
134 OptionalVariableIndex variableIndex) const
135 {
136 if(!variableIndex) {
137 // If no VariableIndex provided, compute one and call this function again
138 VariableIndex computedVariableIndex(asDerived());
139 return eliminateMultifrontal(ordering, function, std::cref(computedVariableIndex));
140 } else {
142 // Do elimination with given ordering
143 EliminationTreeType etree(asDerived(), (*variableIndex).get(), ordering);
144 JunctionTreeType junctionTree(etree);
145 const auto [bayesTree, factorGraph] = junctionTree.eliminate(function);
146 // If any factors are remaining, the ordering was incomplete
147 if(!factorGraph->empty()) {
148 throw InconsistentEliminationRequested(factorGraph->keys());
149 }
150 // Return the Bayes tree
151 return bayesTree;
152 }
153 }
154
155 /* ************************************************************************* */
156 template <class FACTORGRAPH>
159 const Ordering& ordering,
160 const std::unordered_set<Key>& fixedKeys) const {
161 return IndexedJunctionTree(asDerived(), ordering, fixedKeys);
162 }
163
164 /* ************************************************************************* */
165 template <class FACTORGRAPH>
166 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
168 const IndexedJunctionTree& indexedJunctionTree,
169 const Eliminate& function) const {
171
172 using BayesTreeNode = typename BayesTreeType::Node;
173 using SharedFactor = typename FactorGraphType::sharedFactor;
175 // Elimination traversal data - stores a pointer to the parent data and collects
176 // the factors resulting from elimination of the children. Also sets up BayesTree
177 // cliques with parent and child pointers.
178 struct ClusterEliminationData {
179 ClusterEliminationData* const parentData;
180 size_t myIndexInParent;
181 FastVector<SharedFactor> childFactors;
182 std::shared_ptr<BayesTreeNode> bayesTreeNode;
183#ifdef GTSAM_USE_TBB
184 std::shared_ptr<std::mutex> writeLock;
185#endif
186
187 ClusterEliminationData(ClusterEliminationData* _parentData, size_t nChildren)
188 : parentData(_parentData), bayesTreeNode(std::make_shared<BayesTreeNode>())
189#ifdef GTSAM_USE_TBB
190 , writeLock(std::make_shared<std::mutex>())
191#endif
192 {
193 if (parentData) {
194#ifdef GTSAM_USE_TBB
195 parentData->writeLock->lock();
196#endif
197 myIndexInParent = parentData->childFactors.size();
198 parentData->childFactors.push_back(SharedFactor());
199#ifdef GTSAM_USE_TBB
200 parentData->writeLock->unlock();
201#endif
202 } else {
203 myIndexInParent = 0;
204 }
205 if (parentData) {
206 if (parentData->parentData)
207 bayesTreeNode->parent_ = parentData->bayesTreeNode;
208 parentData->bayesTreeNode->children.push_back(bayesTreeNode);
209 }
210 }
211
212 static ClusterEliminationData EliminationPreOrderVisitor(
213 const SymbolicJunctionTree::sharedNode& node,
214 ClusterEliminationData& parentData) {
215 assert(node);
216 ClusterEliminationData myData(&parentData, node->nrChildren());
217 myData.bayesTreeNode->problemSize_ = node->problemSize();
218 return myData;
219 }
220 };
221
222 // Elimination post-order visitor - gather factors, eliminate, store results.
223 class EliminationPostOrderVisitor {
224 const FactorGraphType& graph_;
225 const Eliminate& eliminationFunction_;
226
227 public:
228 EliminationPostOrderVisitor(
229 const FactorGraphType& graph,
230 const Eliminate& eliminationFunction)
231 : graph_(graph), eliminationFunction_(eliminationFunction) {}
232
233 void operator()(const SymbolicJunctionTree::sharedNode& node,
234 ClusterEliminationData& myData) {
235 assert(node);
236
237 FactorGraphType gatheredFactors;
238 gatheredFactors.reserve(node->factors.size() + node->nrChildren());
239
240 for (const auto& factor : node->factors) {
241 auto indexed =
242 std::static_pointer_cast<internal::IndexedSymbolicFactor>(factor);
243 gatheredFactors.push_back(graph_.at(indexed->index_));
244 }
245 gatheredFactors.push_back(myData.childFactors);
246
247 auto eliminationResult =
248 eliminationFunction_(gatheredFactors, node->orderedFrontalKeys);
249
250 myData.bayesTreeNode->setEliminationResult(eliminationResult);
251
252 if (!eliminationResult.second->empty()) {
253#ifdef GTSAM_USE_TBB
254 myData.parentData->writeLock->lock();
255#endif
256 myData.parentData->childFactors[myData.myIndexInParent] =
257 eliminationResult.second;
258#ifdef GTSAM_USE_TBB
259 myData.parentData->writeLock->unlock();
260#endif
261 }
262 }
263 };
264
265 // Do elimination (depth-first traversal). The rootsContainer stores a 'dummy'
266 // BayesTree node that contains all of the roots as its children. rootsContainer
267 // also stores the remaining un-eliminated factors passed up from the roots.
268 std::shared_ptr<BayesTreeType> result = std::make_shared<BayesTreeType>();
269
270 ClusterEliminationData rootsContainer(0, indexedJunctionTree.nrRoots());
271
272 EliminationPostOrderVisitor visitorPost(asDerived(), function);
273 {
274 TbbOpenMPMixedScope threadLimiter;
276 indexedJunctionTree, rootsContainer,
277 ClusterEliminationData::EliminationPreOrderVisitor, visitorPost, 10);
278 }
279
280 // Create BayesTree from roots stored in the dummy BayesTree node.
281 for (const auto& rootClique : rootsContainer.bayesTreeNode->children)
282 result->insertRoot(rootClique);
283
284 // If any factors are remaining, the ordering was incomplete.
285 KeySet remainingKeys;
286 for (const auto& factor : rootsContainer.childFactors) {
287 if (!factor || factor->empty()) continue;
288 remainingKeys.insert(factor->begin(), factor->end());
289 }
290 if (!remainingKeys.empty()) {
291 throw InconsistentEliminationRequested(remainingKeys);
292 }
293
294 return result;
295 }
296
297 /* ************************************************************************* */
298 template<class FACTORGRAPH>
299 std::pair<std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>, std::shared_ptr<FACTORGRAPH> >
301 const Ordering& ordering, const Eliminate& function, OptionalVariableIndex variableIndex) const
302 {
303 if(variableIndex) {
305 // Do elimination
306 EliminationTreeType etree(asDerived(), (*variableIndex).get(), ordering);
307 return etree.eliminate(function);
308 } else {
309 // If no variable index is provided, compute one and call this function again
310 VariableIndex computedVariableIndex(asDerived());
311 return eliminatePartialSequential(ordering, function, std::cref(computedVariableIndex));
312 }
314
315 /* ************************************************************************* */
316 template<class FACTORGRAPH>
317 std::pair<std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>, std::shared_ptr<FACTORGRAPH> >
319 const KeyVector& variables, const Eliminate& function, OptionalVariableIndex variableIndex) const
320 {
321 if(variableIndex) {
323 // Compute full ordering
324 Ordering fullOrdering = Ordering::ColamdConstrainedFirst((*variableIndex).get(), variables);
325
326 // Split off the part of the ordering for the variables being eliminated
327 Ordering ordering(fullOrdering.begin(), fullOrdering.begin() + variables.size());
328 return eliminatePartialSequential(ordering, function, variableIndex);
329 } else {
330 // If no variable index is provided, compute one and call this function again
331 VariableIndex computedVariableIndex(asDerived());
332 return eliminatePartialSequential(variables, function, std::cref(computedVariableIndex));
333 }
334 }
335
336 /* ************************************************************************* */
337 template<class FACTORGRAPH>
338 std::pair<std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>, std::shared_ptr<FACTORGRAPH> >
340 const Ordering& ordering, const Eliminate& function, OptionalVariableIndex variableIndex) const
341 {
342 if(variableIndex) {
344 // Do elimination
345 EliminationTreeType etree(asDerived(), (*variableIndex).get(), ordering);
346 JunctionTreeType junctionTree(etree);
347 return junctionTree.eliminate(function);
348 } else {
349 // If no variable index is provided, compute one and call this function again
350 VariableIndex computedVariableIndex(asDerived());
351 return eliminatePartialMultifrontal(ordering, function, std::cref(computedVariableIndex));
352 }
353 }
354
355 /* ************************************************************************* */
356 template<class FACTORGRAPH>
357 std::pair<std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>, std::shared_ptr<FACTORGRAPH> >
359 const KeyVector& variables, const Eliminate& function, OptionalVariableIndex variableIndex) const
360 {
361 if(variableIndex) {
363 // Compute full ordering
364 Ordering fullOrdering = Ordering::ColamdConstrainedFirst((*variableIndex).get(), variables);
365
366 // Split off the part of the ordering for the variables being eliminated
367 Ordering ordering(fullOrdering.begin(), fullOrdering.begin() + variables.size());
368 return eliminatePartialMultifrontal(ordering, function, variableIndex);
369 } else {
370 // If no variable index is provided, compute one and call this function again
371 VariableIndex computedVariableIndex(asDerived());
372 return eliminatePartialMultifrontal(variables, function, std::cref(computedVariableIndex));
373 }
374 }
375
376 /* ************************************************************************* */
377 template<class FACTORGRAPH>
378 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
380 const Ordering& variables,
381 const Eliminate& function, OptionalVariableIndex variableIndex) const
382 {
383 if(!variableIndex) {
384 // If no variable index is provided, compute one and call this function again
385 VariableIndex index(asDerived());
386 return marginalMultifrontalBayesNet(variables, function, std::cref(index));
387 } else {
388 // No ordering was provided for the marginalized variables, so order them using constrained
389 // COLAMD.
390 constexpr bool forceOrder = true;
391 Ordering totalOrdering =
392 Ordering::ColamdConstrainedLast((*variableIndex).get(), variables, forceOrder);
393
394 // Split up ordering
395 const size_t nVars = variables.size();
396 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - nVars);
397 Ordering marginalVarsOrdering(totalOrdering.end() - nVars, totalOrdering.end());
398
399 // Call this function again with the computed orderings
400 return marginalMultifrontalBayesNet(marginalVarsOrdering, marginalizationOrdering, function, variableIndex);
401 }
402 }
403
404 /* ************************************************************************* */
405 template<class FACTORGRAPH>
406 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
408 const KeyVector& variables,
409 const Eliminate& function, OptionalVariableIndex variableIndex) const
410 {
411 if(!variableIndex) {
412 // If no variable index is provided, compute one and call this function again
413 VariableIndex index(asDerived());
414 return marginalMultifrontalBayesNet(variables, function, std::cref(index));
415 } else {
416 // No ordering was provided for the marginalized variables, so order them using constrained
417 // COLAMD.
418 const constexpr bool forceOrder = false;
419 Ordering totalOrdering =
420 Ordering::ColamdConstrainedLast((*variableIndex).get(), variables, forceOrder);
421
422 // Split up ordering
423 const size_t nVars = variables.size();
424 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - nVars);
425 Ordering marginalVarsOrdering(totalOrdering.end() - nVars, totalOrdering.end());
426
427 // Call this function again with the computed orderings
428 return marginalMultifrontalBayesNet(marginalVarsOrdering, marginalizationOrdering, function, variableIndex);
429 }
430 }
431
432 /* ************************************************************************* */
433 template<class FACTORGRAPH>
434 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
436 const Ordering& variables,
437 const Ordering& marginalizedVariableOrdering,
438 const Eliminate& function, OptionalVariableIndex variableIndex) const
439 {
440 if(!variableIndex) {
441 // If no variable index is provided, compute one and call this function again
442 VariableIndex index(asDerived());
443 return marginalMultifrontalBayesNet(variables, marginalizedVariableOrdering, function, index);
444 } else {
446 // An ordering was provided for the marginalized variables, so we can first eliminate them
447 // in the order requested.
448 const auto [bayesTree, factorGraph] =
449 eliminatePartialMultifrontal(marginalizedVariableOrdering, function, variableIndex);
450
451 // An ordering was also provided for the unmarginalized variables, so we can also
452 // eliminate them in the order requested.
453 return factorGraph->eliminateSequential(variables, function);
454 }
455 }
456
457 /* ************************************************************************* */
458 template<class FACTORGRAPH>
459 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesNetType>
461 const KeyVector& variables,
462 const Ordering& marginalizedVariableOrdering,
463 const Eliminate& function, OptionalVariableIndex variableIndex) const
464 {
465 if(!variableIndex) {
466 // If no variable index is provided, compute one and call this function again
467 VariableIndex index(asDerived());
468 return marginalMultifrontalBayesNet(variables, marginalizedVariableOrdering, function, index);
469 } else {
471 // An ordering was provided for the marginalized variables, so we can first eliminate them
472 // in the order requested.
473 const auto [bayesTree, factorGraph] =
474 eliminatePartialMultifrontal(marginalizedVariableOrdering, function, variableIndex);
475
476 // No ordering was provided for the unmarginalized variables, so order them with COLAMD.
477 return factorGraph->eliminateSequential(Ordering::COLAMD, function);
478 }
479 }
480
481 /* ************************************************************************* */
482 template<class FACTORGRAPH>
483 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
485 const Ordering& variables,
486 const Eliminate& function, OptionalVariableIndex variableIndex) const
487 {
488 if(!variableIndex) {
489 // If no variable index is provided, compute one and call this function again
490 VariableIndex computedVariableIndex(asDerived());
491 return marginalMultifrontalBayesTree(variables, function, std::cref(computedVariableIndex));
492 } else {
493 // No ordering was provided for the marginalized variables, so order them using constrained
494 // COLAMD.
495 constexpr bool forceOrder = true;
496 Ordering totalOrdering =
497 Ordering::ColamdConstrainedLast((*variableIndex).get(), variables, forceOrder);
498
499 // Split up ordering
500 const size_t nVars = variables.size();
501 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - nVars);
502 Ordering marginalVarsOrdering(totalOrdering.end() - nVars, totalOrdering.end());
503
504 // Call this function again with the computed orderings
505 return marginalMultifrontalBayesTree(marginalVarsOrdering, marginalizationOrdering, function, variableIndex);
506 }
507 }
508
509 /* ************************************************************************* */
510 template<class FACTORGRAPH>
511 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
513 const KeyVector& variables,
514 const Eliminate& function, OptionalVariableIndex variableIndex) const
515 {
516 if(!variableIndex) {
517 // If no variable index is provided, compute one and call this function again
518 VariableIndex computedVariableIndex(asDerived());
519 return marginalMultifrontalBayesTree(variables, function, std::cref(computedVariableIndex));
520 } else {
521 // No ordering was provided for the marginalized variables, so order them using constrained
522 // COLAMD.
523 constexpr bool forceOrder = false;
524 Ordering totalOrdering =
525 Ordering::ColamdConstrainedLast((*variableIndex).get(), variables, forceOrder);
526
527 // Split up ordering
528 const size_t nVars = variables.size();
529 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - nVars);
530 Ordering marginalVarsOrdering(totalOrdering.end() - nVars, totalOrdering.end());
531
532 // Call this function again with the computed orderings
533 return marginalMultifrontalBayesTree(marginalVarsOrdering, marginalizationOrdering, function, variableIndex);
534 }
535 }
536
537 /* ************************************************************************* */
538 template<class FACTORGRAPH>
539 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
541 const Ordering& variables,
542 const Ordering& marginalizedVariableOrdering,
543 const Eliminate& function, OptionalVariableIndex variableIndex) const
544 {
545 if(!variableIndex) {
546 // If no variable index is provided, compute one and call this function again
547 VariableIndex computedVariableIndex(asDerived());
548 return marginalMultifrontalBayesTree(variables, marginalizedVariableOrdering, function, std::cref(computedVariableIndex));
549 } else {
551 // An ordering was provided for the marginalized variables, so we can first eliminate them
552 // in the order requested.
553 const auto [bayesTree, factorGraph] =
554 eliminatePartialMultifrontal(marginalizedVariableOrdering, function, variableIndex);
555
556 // An ordering was also provided for the unmarginalized variables, so we can also
557 // eliminate them in the order requested.
558 return factorGraph->eliminateMultifrontal(variables, function);
559 }
560 }
561
562 /* ************************************************************************* */
563 template<class FACTORGRAPH>
564 std::shared_ptr<typename EliminateableFactorGraph<FACTORGRAPH>::BayesTreeType>
566 const KeyVector& variables,
567 const Ordering& marginalizedVariableOrdering,
568 const Eliminate& function, OptionalVariableIndex variableIndex) const
569 {
570 if(!variableIndex) {
571 // If no variable index is provided, compute one and call this function again
572 VariableIndex computedVariableIndex(asDerived());
573 return marginalMultifrontalBayesTree(variables, marginalizedVariableOrdering, function, std::cref(computedVariableIndex));
574 } else {
576 // An ordering was provided for the marginalized variables, so we can first eliminate them
577 // in the order requested.
578 const auto [bayesTree, factorGraph] =
579 eliminatePartialMultifrontal(marginalizedVariableOrdering, function, variableIndex);
580
581 // No ordering was provided for the unmarginalized variables, so order them with COLAMD.
582 return factorGraph->eliminateMultifrontal(Ordering::COLAMD, function);
583 }
584 }
585
586 /* ************************************************************************* */
587 template<class FACTORGRAPH>
588 std::shared_ptr<FACTORGRAPH>
590 const KeyVector& variables,
591 const Eliminate& function, OptionalVariableIndex variableIndex) const
592 {
593 if(variableIndex)
594 {
595 // Compute a total ordering for all variables
596 Ordering totalOrdering = Ordering::ColamdConstrainedLast((*variableIndex).get(), variables);
597
598 // Split out the part for the marginalized variables
599 Ordering marginalizationOrdering(totalOrdering.begin(), totalOrdering.end() - variables.size());
600
601 // Eliminate and return the remaining factor graph
602 return eliminatePartialMultifrontal(marginalizationOrdering, function, variableIndex).second;
603 }
604 else
605 {
606 // If no variable index is provided, compute one and call this function again
607 VariableIndex computedVariableIndex(asDerived());
608 return marginal(variables, function, std::cref(computedVariableIndex));
609 }
610 }
611
612
613}
Exceptions that may be thrown by inference algorithms.
Variable elimination algorithms for factor graphs.
Build a symbolic junction tree that stores original factor indices.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
void DepthFirstForestParallel(FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost, int problemSizeThreshold=10)
Traverse a forest depth-first with pre-order and post-order visits.
Definition treeTraversal-inst.h:181
An object whose scope defines a block where TBB and OpenMP parallelism are mixed.
Definition types.h:87
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition FactorGraph.h:147
void reserve(size_t size)
Reserve space for the specified number of factors if you know in advance how many there will be (work...
Definition FactorGraph.h:143
std::pair< std::shared_ptr< BayesNetType >, std::shared_ptr< FactorGraphType > > eliminatePartialSequential(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do sequential elimination of some variables, in ordering provided, to produce a Bayes net and a remai...
Definition EliminateableFactorGraph-inst.h:300
std::pair< std::shared_ptr< BayesTreeType >, std::shared_ptr< FactorGraphType > > eliminatePartialMultifrontal(const Ordering &ordering, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do multifrontal elimination of some variables, in ordering provided, to produce a Bayes tree and a re...
Definition EliminateableFactorGraph-inst.h:339
EliminationTraitsType::JunctionTreeType JunctionTreeType
Definition EliminateableFactorGraph.h:84
std::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
Definition EliminateableFactorGraph.h:91
EliminationTraitsType::BayesTreeType BayesTreeType
Bayes tree type produced by multifrontal elimination.
Definition EliminateableFactorGraph.h:81
std::shared_ptr< FactorGraphType > marginal(const KeyVector &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal factor graph of the requested variables.
Definition EliminateableFactorGraph-inst.h:589
std::shared_ptr< BayesNetType > marginalMultifrontalBayesNet(const Ordering &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes net.
Definition EliminateableFactorGraph-inst.h:379
IndexedJunctionTree buildIndexedJunctionTree(const Ordering &ordering, const std::unordered_set< Key > &fixedKeys={}) const
Build an IndexedJunctionTree for this factor graph and a fixed ordering.
Definition EliminateableFactorGraph-inst.h:158
EliminationTraitsType::EliminationTreeType EliminationTreeType
Elimination tree type that can do sequential elimination of this graph.
Definition EliminateableFactorGraph.h:78
std::shared_ptr< BayesTreeType > marginalMultifrontalBayesTree(const Ordering &variables, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Compute the marginal of the requested variables and return the result as a Bayes tree.
Definition EliminateableFactorGraph-inst.h:484
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do sequential elimination of all variables to produce a Bayes net.
Definition EliminateableFactorGraph-inst.h:36
std::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Do multifrontal elimination of all variables to produce a Bayes tree.
Definition EliminateableFactorGraph-inst.h:96
std::optional< std::reference_wrapper< const VariableIndex > > OptionalVariableIndex
Typedef for an optional variable index as an argument to elimination functions It is an optional to a...
Definition EliminateableFactorGraph.h:95
std::optional< Ordering::OrderingType > OptionalOrderingType
Typedef for an optional ordering type.
Definition EliminateableFactorGraph.h:98
An inference algorithm was called with inconsistent arguments.
Definition inferenceExceptions.h:32
Definition Ordering.h:33
static Ordering Natural(const FACTOR_GRAPH &fg)
Return a natural Ordering. Typically used by iterative solvers.
Definition Ordering.h:188
static Ordering Colamd(const FACTOR_GRAPH &graph)
Compute a fill-reducing ordering using COLAMD from a factor graph (see details for note on performanc...
Definition Ordering.h:93
static Ordering ColamdConstrainedLast(const FACTOR_GRAPH &graph, const KeyVector &constrainLast, bool forceOrder=false)
Compute a fill-reducing ordering using constrained COLAMD from a factor graph (see details for note o...
Definition Ordering.h:112
static Ordering Metis(const MetisIndex &met, int seed=4321)
Compute an ordering determined by METIS from a VariableIndex.
Definition Ordering.cpp:256
static Ordering ColamdConstrainedFirst(const FACTOR_GRAPH &graph, const KeyVector &constrainFirst, bool forceOrder=false)
Compute a fill-reducing ordering using constrained COLAMD from a factor graph (see details for note o...
Definition Ordering.h:139
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:41
A symbolic junction tree whose factors record the original factor indices from a corresponding (non-s...
Definition IndexedJunctionTree.h:58