|
GTSAM
4.0.2
C++ library for smoothing and mapping (SAM)
|
#include <DecisionTreeFactor.h>


Public Types | |
| typedef DecisionTreeFactor | This |
| typedef DiscreteFactor | Base |
| Typedef to base class. | |
| typedef std::shared_ptr< DecisionTreeFactor > | shared_ptr |
| typedef AlgebraicDecisionTree< Key > | ADT |
| using | Values = DiscreteValues |
| backwards compatibility | |
| typedef KeyVector::iterator | iterator |
| Iterator over keys. | |
| typedef KeyVector::const_iterator | const_iterator |
| Const iterator over keys. | |
| using | LabelFormatter = std::function< std::string(Key)> |
| using | ValueFormatter = std::function< std::string(double)> |
| using | CompareFunc = std::function< bool(const double &, const double &)> |
| using | Unary = std::function< double(const double &)> |
| using | UnaryAssignment = std::function< double(const Assignment< Key > &, const double &)> |
| using | Binary = std::function< double(const double &, const double &)> |
| using | LabelC = std::pair< Key, size_t > |
| using | NodePtr = typename Node::Ptr |
Wrapper support | |
| using | Names = DiscreteValues::Names |
| Translation table from values to strings. | |
Public Member Functions | |
| AlgebraicDecisionTree | operator+ (const AlgebraicDecisionTree &g) const |
| AlgebraicDecisionTree | operator* (const AlgebraicDecisionTree &g) const |
| AlgebraicDecisionTree | operator/ (const AlgebraicDecisionTree &g) const |
| AlgebraicDecisionTree | sum (const Key &label, size_t cardinality) const |
| AlgebraicDecisionTree | sum (const typename Base::LabelC &labelC) const |
| void | print (const std::string &s="", const typename Base::LabelFormatter &labelFormatter=&DefaultFormatter) const |
print method customized to value type double. | |
| bool | equals (const AlgebraicDecisionTree &other, double tol=1e-9) const |
Equality method customized to value type double. | |
Standard Constructors | |
| DecisionTreeFactor () | |
| DecisionTreeFactor (const DiscreteKeys &keys, const ADT &potentials) | |
| DecisionTreeFactor (const DiscreteKeys &keys, const std::vector< double > &table) | |
| DecisionTreeFactor (const DiscreteKeys &keys, const std::string &table) | |
| template<class SOURCE > | |
| DecisionTreeFactor (const DiscreteKey &key, SOURCE table) | |
| Single-key specialization. | |
| DecisionTreeFactor (const DiscreteKey &key, const std::vector< double > &row) | |
| Single-key specialization, with vector of doubles. | |
| DecisionTreeFactor (const DiscreteConditional &c) | |
Testable | |
| bool | equals (const DiscreteFactor &other, double tol=1e-9) const override |
| equality | |
| void | print (const std::string &s="DecisionTreeFactor:\, const KeyFormatter &formatter=DefaultKeyFormatter) const override |
| print | |
Advanced Interface | |
| DecisionTreeFactor | apply (const DecisionTreeFactor &f, ADT::Binary op) const |
| shared_ptr | combine (size_t nrFrontals, ADT::Binary op) const |
| shared_ptr | combine (const Ordering &keys, ADT::Binary op) const |
| std::vector< std::pair< DiscreteValues, double > > | enumerate () const |
| Enumerate all values into a map from values to double. | |
| DiscreteKeys | discreteKeys () const |
| Return all the discrete keys associated with this factor. | |
| DecisionTreeFactor | prune (size_t maxNrAssignments) const |
| Prune the decision tree of discrete variables. More... | |
Wrapper support | |
| void | dot (std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const |
| void | dot (const std::string &name, const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const |
| std::string | dot (const KeyFormatter &keyFormatter=DefaultKeyFormatter, bool showZero=true) const |
| std::string | markdown (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override |
| Render as markdown table. More... | |
| std::string | html (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override |
| Render as html table. More... | |
HybridValues methods. | |
| double | error (const HybridValues &values) const override |
Testable | |
| bool | equals (const This &other, double tol=1e-9) const |
| check equality | |
| virtual void | printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const |
| print only keys | |
Standard Interface | |
| bool | empty () const |
| Whether the factor is empty (involves zero variables). | |
| Key | front () const |
| First key. | |
| Key | back () const |
| Last key. | |
| const_iterator | find (Key key) const |
| find | |
| const KeyVector & | keys () const |
| Access the factor's involved variable keys. | |
| const_iterator | begin () const |
| const_iterator | end () const |
| size_t | size () const |
Advanced Interface | |
| KeyVector & | keys () |
| iterator | begin () |
| iterator | end () |
Testable | |
| void | print (const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const |
| GTSAM-style print. More... | |
| bool | equals (const DecisionTree &other, const CompareFunc &compare=&DefaultCompare) const |
Standard Interface | |
| bool | empty () const |
| Check if tree is empty. | |
| bool | operator== (const DecisionTree &q) const |
| const double & | operator() (const Assignment< Key > &x) const |
| void | visit (Func f) const |
| Visit all leaves in depth-first fashion. More... | |
| void | visitLeaf (Func f) const |
| Visit all leaves in depth-first fashion. More... | |
| void | visitWith (Func f) const |
| Visit all leaves in depth-first fashion. More... | |
| size_t | nrLeaves () const |
| Return the number of leaves in the tree. | |
| X | fold (Func f, X x0) const |
| Fold a binary function over the tree, returning accumulator. More... | |
| std::set< Key > | labels () const |
| DecisionTree | apply (const Unary &op) const |
| DecisionTree | apply (const UnaryAssignment &op) const |
| Apply Unary operation "op" to f while also providing the corresponding assignment. More... | |
| DecisionTree | apply (const DecisionTree &g, const Binary &op) const |
| DecisionTree | choose (const Key &label, size_t index) const |
| DecisionTree | combine (const Key &label, size_t cardinality, const Binary &op) const |
| DecisionTree | combine (const LabelC &labelC, const Binary &op) const |
| void | dot (std::ostream &os, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const |
| void | dot (const std::string &name, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const |
| std::string | dot (const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const |
Advanced Interface | |
| NodePtr | compose (Iterator begin, Iterator end, const Key &label) const |
Public Attributes | |
| NodePtr | root_ |
| A DecisionTree just contains the root. TODO(dellaert): make protected. | |
Protected Member Functions | |
| NodePtr | create (It begin, It end, ValueIt beginY, ValueIt endY) const |
| NodePtr | convertFrom (const typename DecisionTree< M, X >::NodePtr &f, std::function< Key(const M &)> L_of_M, std::function< double(const X &)> Y_of_X) const |
| Convert from a DecisionTree<M, X> to DecisionTree<L, Y>. More... | |
Static Protected Member Functions | |
| static bool | DefaultCompare (const double &a, const double &b) |
| Default method for comparison of two objects of type Y. | |
Standard Constructors | |
| template<typename CONTAINER > | |
| static Factor | FromKeys (const CONTAINER &keys) |
| template<typename ITERATOR > | |
| static Factor | FromIterators (ITERATOR first, ITERATOR last) |
Protected Attributes | |
| std::map< Key, size_t > | cardinalities_ |
| KeyVector | keys_ |
| The keys involved in this factor. | |
Standard Interface | |
| double | evaluate (const DiscreteValues &values) const |
| double | operator() (const DiscreteValues &values) const override |
| Evaluate probability distribution, sugar. | |
| double | error (const DiscreteValues &values) const |
Calculate error for DiscreteValues x, is -log(probability). | |
| DecisionTreeFactor | operator* (const DecisionTreeFactor &f) const override |
| multiply two factors | |
| size_t | cardinality (Key j) const |
| DecisionTreeFactor | operator/ (const DecisionTreeFactor &f) const |
| divide by factor f (safely) | |
| DecisionTreeFactor | toDecisionTreeFactor () const override |
| Convert into a decisiontree. | |
| shared_ptr | sum (size_t nrFrontals) const |
| Create new factor by summing all values with the same separator values. | |
| shared_ptr | sum (const Ordering &keys) const |
| Create new factor by summing all values with the same separator values. | |
| shared_ptr | max (size_t nrFrontals) const |
| Create new factor by maximizing over all values with the same separator. | |
| shared_ptr | max (const Ordering &keys) const |
| Create new factor by maximizing over all values with the same separator. | |
| static double | safe_div (const double &a, const double &b) |
A discrete probabilistic factor.
|
inherited |
A label annotated with cardinality
|
inherited |
------------------—— Node base class ---------------------—— A function is a shared pointer to the root of a DT
|
inherited |
Handy typedefs for unary and binary function types
| gtsam::DecisionTreeFactor::DecisionTreeFactor | ( | ) |
Default constructor for I/O
| gtsam::DecisionTreeFactor::DecisionTreeFactor | ( | const DiscreteKeys & | keys, |
| const ADT & | potentials | ||
| ) |
Constructor from DiscreteKeys and AlgebraicDecisionTree
| gtsam::DecisionTreeFactor::DecisionTreeFactor | ( | const DiscreteKeys & | keys, |
| const std::vector< double > & | table | ||
| ) |
Constructor from doubles
| gtsam::DecisionTreeFactor::DecisionTreeFactor | ( | const DiscreteKeys & | keys, |
| const std::string & | table | ||
| ) |
Constructor from string
|
explicit |
Construct from a DiscreteConditional type
| DecisionTreeFactor gtsam::DecisionTreeFactor::apply | ( | const DecisionTreeFactor & | f, |
| ADT::Binary | op | ||
| ) | const |
Apply binary operator (*this) "op" f
| f | the second argument for op |
| op | a binary operator that operates on AlgebraicDecisionTree |
|
inherited |
apply Unary operation "op" to f
|
inherited |
Apply Unary operation "op" to f while also providing the corresponding assignment.
Apply unary operator with assignment.
| op | Function which takes Assignment<L> and Y as input and returns object of type Y. |
|
inherited |
apply binary operation "op" to f and g
|
inlineinherited |
Iterator at beginning of involved variable keys
|
inlineinherited |
Iterator at beginning of involved variable keys
|
inlineinherited |
create a new function where value(label)==index It's like "restrict" in Darwiche09book pg329, 330?
| shared_ptr gtsam::DecisionTreeFactor::combine | ( | size_t | nrFrontals, |
| ADT::Binary | op | ||
| ) | const |
Combine frontal variables using binary operator "op"
| nrFrontals | nr. of frontal to combine variables in this factor |
| op | a binary operator that operates on AlgebraicDecisionTree |
| shared_ptr gtsam::DecisionTreeFactor::combine | ( | const Ordering & | keys, |
| ADT::Binary | op | ||
| ) | const |
Combine frontal variables in an Ordering using binary operator "op"
| nrFrontals | nr. of frontal to combine variables in this factor |
| op | a binary operator that operates on AlgebraicDecisionTree |
|
inherited |
combine subtrees on key with binary operation "op"
|
inlineinherited |
combine with LabelC for convenience
|
protectedinherited |
Convert from a DecisionTree<M, X> to DecisionTree<L, Y>.
| M | The previous label type. |
| X | The previous value type. |
| f | The node pointer to the root of the previous DecisionTree. |
| L_of_M | Functor to convert from label type M to type L. |
| Y_of_X | Functor to convert from value type X to type Y. |
|
protectedinherited |
Internal recursive function to create from keys, cardinalities, and Y values
| void gtsam::DecisionTreeFactor::dot | ( | std::ostream & | os, |
| const KeyFormatter & | keyFormatter = DefaultKeyFormatter, |
||
| bool | showZero = true |
||
| ) | const |
output to graphviz format, stream version
| void gtsam::DecisionTreeFactor::dot | ( | const std::string & | name, |
| const KeyFormatter & | keyFormatter = DefaultKeyFormatter, |
||
| bool | showZero = true |
||
| ) | const |
output to graphviz format, open a file
| std::string gtsam::DecisionTreeFactor::dot | ( | const KeyFormatter & | keyFormatter = DefaultKeyFormatter, |
| bool | showZero = true |
||
| ) | const |
output to graphviz format string
|
inherited |
output to graphviz format, stream version
|
inherited |
output to graphviz format, open a file
|
inherited |
output to graphviz format string
|
inlineinherited |
Iterator at end of involved variable keys
|
inlineinherited |
Iterator at end of involved variable keys
|
overridevirtual |
Calculate error for HybridValues x, is -log(probability) Simply dispatches to DiscreteValues version.
Reimplemented from gtsam::Factor.
|
inline |
Calculate probability for given values x, is just look up in AlgebraicDecisionTree.
|
inherited |
Fold a binary function over the tree, returning accumulator.
| X | type for accumulator. |
| f | binary function: Y * X -> X returning an updated accumulator. |
| x0 | initial value for accumulator. |
Example: auto add = [](const double& y, double x) { return y + x; }; double sum = tree.fold(add, 0.0);
|
inlinestaticprotectedinherited |
Construct factor from iterator keys. This is called internally from derived factor static factor methods, as a workaround for not being able to call the protected constructors above.
|
inlinestaticprotectedinherited |
Construct factor from container of keys. This is called internally from derived factor static factor methods, as a workaround for not being able to call the protected constructors above.
|
overridevirtual |
Render as html table.
| keyFormatter | GTSAM-style Key formatter. |
| names | optional, category names corresponding to choices. |
Implements gtsam::DiscreteFactor.
Reimplemented in gtsam::DiscreteConditional.
|
inlineinherited |
|
inherited |
Retrieve all unique labels as a set.
Get (partial) labels by performing a visit.
This method performs a depth-first search to go to every leaf and records the keys assignment which leads to that leaf. Since the tree can be pruned, there might be a leaf at a lower depth which results in a partial assignment (i.e. not all keys are specified).
E.g. given a tree with 3 keys, there may be a branch where the 3rd key has the same values for all the leaves. This leads to the branch being pruned so we get a leaf which is arrived at by just the first 2 keys and their assignments.
|
overridevirtual |
Render as markdown table.
| keyFormatter | GTSAM-style Key formatter. |
| names | optional, category names corresponding to choices. |
Implements gtsam::DiscreteFactor.
Reimplemented in gtsam::DiscreteConditional.
|
inherited |
evaluate
|
inlineinherited |
product
|
inlineinherited |
sum
|
inlineinherited |
division
|
inherited |
equality
|
inherited |
GTSAM-style print.
| s | Prefix string. |
| labelFormatter | Functor to format the node label. |
| valueFormatter | Functor to format the node value. |
| DecisionTreeFactor gtsam::DecisionTreeFactor::prune | ( | size_t | maxNrAssignments | ) | const |
Prune the decision tree of discrete variables.
Pruning will set the leaves to be "pruned" to 0 indicating a 0 probability. An assignment is pruned if it is not in the top maxNrAssignments values.
A violation can occur if there are more duplicate values than maxNrAssignments. A violation here is the need to un-prune the decision tree (e.g. all assignment values are 1.0). We could have another case where some subset of duplicates exist (e.g. for a tree with 8 assignments we have 1, 1, 1, 1, 0.8, 0.7, 0.6, 0.5), but this is not a violation since the for maxNrAssignments=5 the top values are (1, 0.8).
| maxNrAssignments | The maximum number of assignments to keep. |
|
inlineinherited |
|
inlineinherited |
sum out variable
|
inlineinherited |
sum out variable
|
inherited |
Visit all leaves in depth-first fashion.
| f | (side-effect) Function taking the value of the leaf node. |
Example: int sum = 0; auto visitor = [&](int y) { sum += y; }; tree.visit(visitor);
|
inherited |
Visit all leaves in depth-first fashion.
| f | (side-effect) Function taking the leaf node pointer. |
Example: int sum = 0; auto visitor = [&](const Leaf& leaf) { sum += leaf.constant(); }; tree.visitLeaf(visitor);
|
inherited |
Visit all leaves in depth-first fashion.
| f | (side-effect) Function taking an assignment and a value. |
Example: int sum = 0; auto visitor = [&](const Assignment<L>& assignment, int y) { sum += y; }; tree.visitWith(visitor);
1.8.13