gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClusterTree.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <gtsam/base/Testable.h>
13 #include <gtsam/base/FastVector.h>
14 #include <gtsam/inference/Key.h>
15 
16 namespace gtsam
17 {
18 
25  template<class BAYESTREE, class GRAPH>
26  class ClusterTree
27  {
28  public:
29  typedef GRAPH FactorGraphType;
30  typedef typename GRAPH::FactorType FactorType;
32  typedef boost::shared_ptr<This> shared_ptr;
33  typedef boost::shared_ptr<FactorType> sharedFactor;
34  typedef BAYESTREE BayesTreeType;
36  typedef boost::shared_ptr<ConditionalType> sharedConditional;
38 
39  struct Cluster {
40  typedef FastVector<Key> Keys;
43 
47  int problemSize_;
48 
49  int problemSize() const { return problemSize_; }
50 
52  void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
53  };
54 
55  typedef boost::shared_ptr<Cluster> sharedCluster;
56  typedef Cluster Node;
58 
61 
62  protected:
64  FastVector<sharedFactor> remainingFactors_;
65 
68 
71  ClusterTree(const This& other) { *this = other; }
72 
74 
75  public:
78 
80  void print(const std::string& s = "", const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
81 
83 
86 
92  std::pair<boost::shared_ptr<BayesTreeType>, boost::shared_ptr<FactorGraphType> >
93  eliminate(const Eliminate& function) const;
94 
96 
99 
101  const FastVector<sharedNode>& roots() const { return roots_; }
102 
104  const FastVector<sharedFactor>& remainingFactors() const { return remainingFactors_; }
105 
107 
108  protected:
110 
113  This& operator=(const This& other);
114 
117 
119 
120  };
121 
122 
123 }
124 
125 
const FastVector< sharedNode > & roots() const
Return the set of roots (one for a tree, multiple for a forest)
Definition: ClusterTree.h:101
ClusterTree< BAYESTREE, GRAPH > This
This class.
Definition: ClusterTree.h:31
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor...
Definition: DiscreteFactor.h:33
Cluster Node
Define Node=Cluster for compatibility with tree traversal functions.
Definition: ClusterTree.h:56
boost::shared_ptr< Cluster > sharedCluster
Shared pointer to Cluster.
Definition: ClusterTree.h:55
GRAPH::FactorType FactorType
The type of factors.
Definition: ClusterTree.h:30
Definition: ClusterTree.h:39
boost::shared_ptr< This > shared_ptr
Shared pointer to this class.
Definition: ClusterTree.h:32
ClusterTree(const This &other)
Copy constructor - makes a deep copy of the tree structure, but only pointers to factors are copied...
Definition: ClusterTree.h:71
std::pair< boost::shared_ptr< BayesTreeType >, boost::shared_ptr< FactorGraphType > > eliminate(const Eliminate &function) const
Eliminate the factors to a Bayes tree and remaining factor graph.
Definition: ClusterTree-inst.h:156
boost::shared_ptr< FactorType > sharedFactor
Shared pointer to a factor.
Definition: ClusterTree.h:33
FactorGraphType::Eliminate Eliminate
Typedef for an eliminate subroutine.
Definition: ClusterTree.h:37
GTSAM_CONCEPT_TESTABLE_TYPE(FactorType)
concept check
Concept check for values that can be used in unit tests.
BAYESTREE BayesTreeType
The BayesTree type produced by elimination.
Definition: ClusterTree.h:34
boost::function< EliminationResult(const FactorGraphType &, const Ordering &)> Eliminate
The function type that does a single dense elimination step on a subgraph.
Definition: EliminateableFactorGraph.h:89
Keys keys
Frontal keys of this node.
Definition: ClusterTree.h:44
const FastVector< sharedFactor > & remainingFactors() const
Return the remaining factors that are not pulled into elimination.
Definition: ClusterTree.h:104
boost::shared_ptr< ConditionalType > sharedConditional
Shared pointer to a conditional.
Definition: ClusterTree.h:36
ClusterTree()
Default constructor to be used in derived classes.
Definition: ClusterTree.h:116
This & operator=(const This &other)
Assignment operator - makes a deep copy of the tree structure, but only pointers to factors are copie...
Definition: ClusterTree-inst.h:141
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print the cluster tree.
Definition: ClusterTree-inst.h:133
Factors factors
Factors associated with this node.
Definition: ClusterTree.h:45
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition: DiscreteConditional.h:33
GRAPH FactorGraphType
The factor graph type.
Definition: ClusterTree.h:29
Children children
sub-trees
Definition: ClusterTree.h:46
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print this node
Definition: ClusterTree-inst.h:122
sharedCluster sharedNode
Define Node=Cluster for compatibility with tree traversal functions.
Definition: ClusterTree.h:57
A thin wrapper around std::vector that uses boost's pool_allocator.
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62
BayesTreeType::ConditionalType ConditionalType
The type of conditionals.
Definition: ClusterTree.h:35
A cluster-tree is associated with a factor graph and is defined as in Koller-Friedman: each node k re...
Definition: BayesTree.h:33