Loading...
Searching...
No Matches
gtsam::AlgebraicDecisionTree< L > Class Template Reference
Discrete

## Detailed Description

template<typename L>
class gtsam::AlgebraicDecisionTree< L >

An algebraic decision tree fixes the range of a DecisionTree to double.

Just has some nice constructors and some syntactic sugar. TODO(dellaert): consider eliminating this class altogether?

Inheritance diagram for gtsam::AlgebraicDecisionTree< L >:

## Public Member Functions

| AlgebraicDecisionTree (double leaf=1.0)
| AlgebraicDecisionTree (const Base &add)
| AlgebraicDecisionTree (const L &label, double y1, double y2)
| Create a new leaf function splitting on a variable.
| AlgebraicDecisionTree (const typename Base::LabelC &labelC, double y1, double y2)
| Create a new leaf function splitting on a variable.
| AlgebraicDecisionTree (const std::vector< typename Base::LabelC > &labelCs, const std::vector< double > &ys)
| Create from keys with cardinalities and a vector table.
| AlgebraicDecisionTree (const std::vector< typename Base::LabelC > &labelCs, const std::string &table)
| Create from keys and string table.
template<typename Iterator>
| AlgebraicDecisionTree (Iterator begin, Iterator end, const L &label)
| Create a range of decision trees, splitting on a single variable.
template<typename M>
| AlgebraicDecisionTree (const AlgebraicDecisionTree< M > &other, const std::map< M, L > &map)
| Convert labels from type M to type L.
AlgebraicDecisionTree | operator+ (const AlgebraicDecisionTree &g) const
| sum
AlgebraicDecisionTree | operator* (const AlgebraicDecisionTree &g) const
| product
AlgebraicDecisionTree | operator/ (const AlgebraicDecisionTree &g) const
| division
AlgebraicDecisionTree | sum (const L &label, size_t cardinality) const
| sum out variable
AlgebraicDecisionTree | sum (const typename Base::LabelC &labelC) const
| sum out variable
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.
Public Member Functions inherited from gtsam::DecisionTree< L, double >
| DecisionTree ()
| Default constructor (for serialization).
| DecisionTree (const double &y)
| Create a constant.
| DecisionTree (const L &label, const double &y1, const double &y2)
| Create tree with 2 assignments y1, y2, splitting on variable label.
| DecisionTree (const LabelC &label, const double &y1, const double &y2)
| Allow Label+Cardinality for convenience.
| DecisionTree (const std::vector< LabelC > &labelCs, const std::vector< double > &ys)
| Create from keys and a corresponding vector of values.
| DecisionTree (const std::vector< LabelC > &labelCs, const std::string &table)
| Create from keys and string table.
| DecisionTree (Iterator begin, Iterator end, const L &label)
| Create DecisionTree from others.
| DecisionTree (const L &label, const DecisionTree &f0, const DecisionTree &f1)
| Create DecisionTree from two others.
| DecisionTree (const DecisionTree< L, X > &other, Func Y_of_X)
| Convert from a different value type.
| DecisionTree (const DecisionTree< M, X > &other, const std::map< M, L > &map, Func Y_of_X)
| Convert from a different value type X to value type Y, also transate labels via map from type M to L.
void | print (const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const
| GTSAM-style print.
bool | equals (const DecisionTree &other, const CompareFunc &compare=&DefaultCompare) const
virtual | ~DecisionTree ()=default
| Make virtual.
bool | empty () const
| Check if tree is empty.
bool | operator== (const DecisionTree &q) const
| equality
const double & | operator() (const Assignment< L > &x) const
| evaluate
void | visit (Func f) const
| Visit all leaves in depth-first fashion.
void | visitLeaf (Func f) const
| Visit all leaves in depth-first fashion.
void | visitWith (Func f) const
| Visit all leaves in depth-first fashion.
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.
std::set< L > | labels () const
| Retrieve all unique labels as a set.
DecisionTree | apply (const Unary &op) const
| apply Unary operation "op" to f
DecisionTree | apply (const UnaryAssignment &op) const
| Apply Unary operation "op" to f while also providing the corresponding assignment.
DecisionTree | apply (const DecisionTree &g, const Binary &op) const
| apply binary operation "op" to f and g
DecisionTree | choose (const L &label, size_t index) const
| create a new function where value(label)==index It's like "restrict" in Darwiche09book pg329, 330?
DecisionTree | combine (const L &label, size_t cardinality, const Binary &op) const
| combine subtrees on key with binary operation "op"
DecisionTree | combine (const LabelC &labelC, const Binary &op) const
| combine with LabelC for convenience
void | dot (std::ostream &os, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const
| output to graphviz format, stream version
void | dot (const std::string &name, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const
| output to graphviz format, open a file
std::string | dot (const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const
| output to graphviz format string
| DecisionTree (const NodePtr &root)
NodePtr | compose (Iterator begin, Iterator end, const L &label) const

## Public Types

using | Base = DecisionTree<L, double>
Public Types inherited from gtsam::DecisionTree< L, double >
using | LabelFormatter
using | ValueFormatter
using | CompareFunc
using | Unary
| Handy typedefs for unary and binary function types.
using | UnaryAssignment
using | Binary
using | LabelC
| A label annotated with cardinality.
using | NodePtr
| ---------------------— Node base class ------------------------—

## Classes

struct | Ring
| The Real ring with addition and multiplication. More...

## Additional Inherited Members

Public Attributes inherited from gtsam::DecisionTree< L, double >
NodePtr | root_
| A DecisionTree just contains the root. TODO(dellaert): make protected.
Protected Member Functions inherited from gtsam::DecisionTree< L, double >
NodePtr | create (It begin, It end, ValueIt beginY, ValueIt endY) const
| Internal recursive function to create from keys, cardinalities, and Y values.
NodePtr | convertFrom (const typename DecisionTree< M, X >::NodePtr &f, std::function< L(const M &)> L_of_M, std::function< double(const X &)> Y_of_X) const
| Convert from a DecisionTree<M, X> to DecisionTree<L, Y>.
Static Protected Member Functions inherited from gtsam::DecisionTree< L, double >
static bool | DefaultCompare (const double &a, const double &b)
| Default method for comparison of two objects of type Y.

## Constructor & Destructor Documentation

## AlgebraicDecisionTree() [1/5]

template<typename L>

gtsam::AlgebraicDecisionTree< L >::AlgebraicDecisionTree | ( | const typename Base::LabelC & | labelC,
|  | double | y1,
|  | double | y2 )

inline

Create a new leaf function splitting on a variable.

Parameters

  labelC | The label with cardinality 2
  y1 | The value for the first key
  y2 | The value for the second key

Example:

std::pair<string, size_t> A {"a", 2};
AlgebraicDecisionTree<string> a(A, 0.6, 0.4);
gtsam::AlgebraicDecisionTree
An algebraic decision tree fixes the range of a DecisionTree to double.
Definition AlgebraicDecisionTree.h:38

## AlgebraicDecisionTree() [2/5]

template<typename L>

gtsam::AlgebraicDecisionTree< L >::AlgebraicDecisionTree | ( | const std::vector< typename Base::LabelC > & | labelCs,
|  | const std::vector< double > & | ys )

inline

Create from keys with cardinalities and a vector table.

Parameters

  labelCs | The keys, with cardinalities, given as pairs
  ys | The vector table

Example with three keys, A, B, and C, with cardinalities 2, 3, and 2, respectively, and a vector table of size 12:

DiscreteKey A(0, 2), B(1, 3), C(2, 2);
const vector<double> cpt{
1.0 / 3, 2.0 / 3, 3.0 / 7, 4.0 / 7, 5.0 / 11, 6.0 / 11, //
1.0 / 9, 8.0 / 9, 3.0 / 6, 3.0 / 6, 5.0 / 10, 5.0 / 10};
AlgebraicDecisionTree<Key> expected(A & B & C, cpt);
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:36

The table is given in the following order: A=0, B=0, C=0 A=0, B=0, C=1 ... A=1, B=1, C=1 Hence, the first line in the table is for A==0, and the second for A==1. In each line, the first two entries are for B==0, the next two for B==1, and the last two for B==2. Each pair is for a C value of 0 and 1.

## AlgebraicDecisionTree() [3/5]

template<typename L>

gtsam::AlgebraicDecisionTree< L >::AlgebraicDecisionTree | ( | const std::vector< typename Base::LabelC > & | labelCs,
|  | const std::string & | table )

inline

Create from keys and string table.

Parameters

  labelCs | The keys, with cardinalities, given as pairs
  table | The string table, given as a string of doubles.

Note
  Table needs to be in same order as the vector table in the other constructor.

## AlgebraicDecisionTree() [4/5]

template<typename L>
template<typename Iterator>

gtsam::AlgebraicDecisionTree< L >::AlgebraicDecisionTree | ( | Iterator | begin,
|  | Iterator | end,
|  | const L & | label )

inline

Create a range of decision trees, splitting on a single variable.

Parameters

  begin | Iterator to beginning of a range of decision trees
  end | Iterator to end of a range of decision trees
  label | The label to split on

## AlgebraicDecisionTree() [5/5]

template<typename L>
template<typename M>

gtsam::AlgebraicDecisionTree< L >::AlgebraicDecisionTree | ( | const AlgebraicDecisionTree< M > & | other,
|  | const std::map< M, L > & | map )

inline

Convert labels from type M to type L.

Parameters

  other | The AlgebraicDecisionTree with label type M to convert.
  map | Map from label type M to label type L.

The documentation for this class was generated from the following file:

- /build/gtsam-gchP9J/gtsam-4.2.2+dfsg/gtsam/discrete/AlgebraicDecisionTree.h