GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
gtsam::AlgebraicDecisionTree< L > Class Template Reference

#include <AlgebraicDecisionTree.h>

Inheritance diagram for gtsam::AlgebraicDecisionTree< L >:
Inheritance graph
[legend]
Collaboration diagram for gtsam::AlgebraicDecisionTree< L >:
Collaboration graph
[legend]

Classes

struct  Ring
 

Public Types

using Base = DecisionTree< L, double >
 
using LabelFormatter = std::function< std::string(L)>
 
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< L > &, const double &)>
 
using Binary = std::function< double(const double &, const double &)>
 
using LabelC = std::pair< L, size_t >
 
using NodePtr = typename Node::Ptr
 

Public Member Functions

 AlgebraicDecisionTree (double leaf=1.0)
 
 AlgebraicDecisionTree (const Base &add)
 
 AlgebraicDecisionTree (const L &label, double y1, double y2)
 
 AlgebraicDecisionTree (const typename Base::LabelC &labelC, double y1, double y2)
 
 AlgebraicDecisionTree (const std::vector< typename Base::LabelC > &labelCs, const std::vector< double > &ys)
 
 AlgebraicDecisionTree (const std::vector< typename Base::LabelC > &labelCs, const std::string &table)
 
template<typename Iterator >
 AlgebraicDecisionTree (Iterator begin, Iterator end, const L &label)
 
template<typename M >
 AlgebraicDecisionTree (const AlgebraicDecisionTree< M > &other, const std::map< M, L > &map)
 
AlgebraicDecisionTree operator+ (const AlgebraicDecisionTree &g) const
 
AlgebraicDecisionTree operator* (const AlgebraicDecisionTree &g) const
 
AlgebraicDecisionTree operator/ (const AlgebraicDecisionTree &g) const
 
AlgebraicDecisionTree sum (const L &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.
 
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< L > &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.
 
fold (Func f, X x0) const
 Fold a binary function over the tree, returning accumulator. More...
 
std::set< L > 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 L &label, size_t index) const
 
DecisionTree combine (const L &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 L &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< 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>. More...
 

Static Protected Member Functions

static bool DefaultCompare (const double &a, const double &b)
 Default method for comparison of two objects of type Y.
 

Detailed Description

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

Algebraic Decision Trees fix the range to double Just has some nice constructors and some syntactic sugar TODO: consider eliminating this class altogether?

Member Typedef Documentation

◆ LabelC

using gtsam::DecisionTree< L, double >::LabelC = std::pair<L, size_t>
inherited

A label annotated with cardinality

◆ NodePtr

using gtsam::DecisionTree< L, double >::NodePtr = typename Node::Ptr
inherited

------------------—— Node base class ---------------------—— A function is a shared pointer to the root of a DT

◆ Unary

using gtsam::DecisionTree< L, double >::Unary = std::function<double (const double &)>
inherited

Handy typedefs for unary and binary function types

Constructor & Destructor Documentation

◆ AlgebraicDecisionTree() [1/6]

template<typename L>
gtsam::AlgebraicDecisionTree< L >::AlgebraicDecisionTree ( const L &  label,
double  y1,
double  y2 
)
inline

Create a new leaf function splitting on a variable

◆ AlgebraicDecisionTree() [2/6]

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

◆ AlgebraicDecisionTree() [3/6]

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

Create from keys and vector table

◆ AlgebraicDecisionTree() [4/6]

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

◆ AlgebraicDecisionTree() [5/6]

template<typename L>
template<typename Iterator >
gtsam::AlgebraicDecisionTree< L >::AlgebraicDecisionTree ( Iterator  begin,
Iterator  end,
const L &  label 
)
inline

Create a new function splitting on a variable

◆ AlgebraicDecisionTree() [6/6]

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
otherThe AlgebraicDecisionTree with label type M to convert.
mapMap from label type M to label type L.

Member Function Documentation

◆ apply() [1/3]

DecisionTree< L, double > gtsam::DecisionTree< L, double >::apply ( const Unary op) const
inherited

apply Unary operation "op" to f

◆ apply() [2/3]

DecisionTree< L, double > gtsam::DecisionTree< L, double >::apply ( const UnaryAssignment &  op) const
inherited

Apply Unary operation "op" to f while also providing the corresponding assignment.

Apply unary operator with assignment.

Parameters
opFunction which takes Assignment<L> and Y as input and returns object of type Y.
Returns
DecisionTree

◆ apply() [3/3]

DecisionTree< L, double > gtsam::DecisionTree< L, double >::apply ( const DecisionTree< L, double > &  g,
const Binary &  op 
) const
inherited

apply binary operation "op" to f and g

◆ choose()

DecisionTree gtsam::DecisionTree< L, double >::choose ( const L &  label,
size_t  index 
) const
inlineinherited

create a new function where value(label)==index It's like "restrict" in Darwiche09book pg329, 330?

◆ combine() [1/2]

DecisionTree< L, double > gtsam::DecisionTree< L, double >::combine ( const L &  label,
size_t  cardinality,
const Binary &  op 
) const
inherited

combine subtrees on key with binary operation "op"

◆ combine() [2/2]

DecisionTree gtsam::DecisionTree< L, double >::combine ( const LabelC labelC,
const Binary &  op 
) const
inlineinherited

combine with LabelC for convenience

◆ convertFrom()

DecisionTree< L, double >::NodePtr gtsam::DecisionTree< L, double >::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
protectedinherited

Convert from a DecisionTree<M, X> to DecisionTree<L, Y>.

Template Parameters
MThe previous label type.
XThe previous value type.
Parameters
fThe node pointer to the root of the previous DecisionTree.
L_of_MFunctor to convert from label type M to type L.
Y_of_XFunctor to convert from value type X to type Y.
Returns
NodePtr

◆ create()

DecisionTree< L, double >::NodePtr gtsam::DecisionTree< L, double >::create ( It  begin,
It  end,
ValueIt  beginY,
ValueIt  endY 
) const
protectedinherited

Internal recursive function to create from keys, cardinalities, and Y values

◆ dot() [1/3]

void gtsam::DecisionTree< L, double >::dot ( std::ostream &  os,
const LabelFormatter &  labelFormatter,
const ValueFormatter &  valueFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format, stream version

◆ dot() [2/3]

void gtsam::DecisionTree< L, double >::dot ( const std::string &  name,
const LabelFormatter &  labelFormatter,
const ValueFormatter &  valueFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format, open a file

◆ dot() [3/3]

std::string gtsam::DecisionTree< L, double >::dot ( const LabelFormatter &  labelFormatter,
const ValueFormatter &  valueFormatter,
bool  showZero = true 
) const
inherited

output to graphviz format string

◆ fold()

X gtsam::DecisionTree< L, double >::fold ( Func  f,
x0 
) const
inherited

Fold a binary function over the tree, returning accumulator.

Template Parameters
Xtype for accumulator.
Parameters
fbinary function: Y * X -> X returning an updated accumulator.
x0initial value for accumulator.
Returns
X final value for accumulator.
Note
X is always passed by value.
Due to pruning, leaves might not exhaust choices.

Example: auto add = [](const double& y, double x) { return y + x; }; double sum = tree.fold(add, 0.0);

◆ labels()

std::set< L > gtsam::DecisionTree< L, double >::labels ( ) const
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.

◆ operator()()

const double & gtsam::DecisionTree< L, double >::operator() ( const Assignment< L > &  x) const
inherited

evaluate

◆ operator*()

template<typename L>
AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< L >::operator* ( const AlgebraicDecisionTree< L > &  g) const
inline

product

◆ operator+()

template<typename L>
AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< L >::operator+ ( const AlgebraicDecisionTree< L > &  g) const
inline

sum

◆ operator/()

template<typename L>
AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< L >::operator/ ( const AlgebraicDecisionTree< L > &  g) const
inline

division

◆ operator==()

bool gtsam::DecisionTree< L, double >::operator== ( const DecisionTree< L, double > &  q) const
inherited

equality

◆ print()

void gtsam::DecisionTree< L, double >::print ( const std::string &  s,
const LabelFormatter &  labelFormatter,
const ValueFormatter &  valueFormatter 
) const
inherited

GTSAM-style print.

Parameters
sPrefix string.
labelFormatterFunctor to format the node label.
valueFormatterFunctor to format the node value.

◆ sum() [1/2]

template<typename L>
AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< L >::sum ( const L &  label,
size_t  cardinality 
) const
inline

sum out variable

◆ sum() [2/2]

template<typename L>
AlgebraicDecisionTree gtsam::AlgebraicDecisionTree< L >::sum ( const typename Base::LabelC labelC) const
inline

sum out variable

◆ visit()

void gtsam::DecisionTree< L, double >::visit ( Func  f) const
inherited

Visit all leaves in depth-first fashion.

Parameters
f(side-effect) Function taking the value of the leaf node.
Note
Due to pruning, the number of leaves may not be the same as the number of assignments. E.g. if we have a tree on 2 binary variables with all values being 1, then there are 2^2=4 assignments, but only 1 leaf.

Example: int sum = 0; auto visitor = [&](int y) { sum += y; }; tree.visit(visitor);

◆ visitLeaf()

void gtsam::DecisionTree< L, double >::visitLeaf ( Func  f) const
inherited

Visit all leaves in depth-first fashion.

Parameters
f(side-effect) Function taking the leaf node pointer.
Note
Due to pruning, the number of leaves may not be the same as the number of assignments. E.g. if we have a tree on 2 binary variables with all values being 1, then there are 2^2=4 assignments, but only 1 leaf.

Example: int sum = 0; auto visitor = [&](const Leaf& leaf) { sum += leaf.constant(); }; tree.visitLeaf(visitor);

◆ visitWith()

void gtsam::DecisionTree< L, double >::visitWith ( Func  f) const
inherited

Visit all leaves in depth-first fashion.

Parameters
f(side-effect) Function taking an assignment and a value.
Note
Due to pruning, the number of leaves may not be the same as the number of assignments. E.g. if we have a tree on 2 binary variables with all values being 1, then there are 2^2=4 assignments, but only 1 leaf.

Example: int sum = 0; auto visitor = [&](const Assignment<L>& assignment, int y) { sum += y; }; tree.visitWith(visitor);


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