#include <AlgebraicDecisionTree.h>
Public Types | |
using | Base = DecisionTree< L, double > |
![]() | |
using | Binary = std::function< double(const double &, const double &)> |
using | CompareFunc = std::function< bool(const double &, const double &)> |
using | LabelC = std::pair< L, size_t > |
using | LabelFormatter = std::function< std::string(L)> |
using | NodePtr = typename Node::Ptr |
using | Unary = std::function< double(const double &)> |
using | UnaryAssignment = std::function< double(const Assignment< L > &, const double &)> |
using | ValueFormatter = std::function< std::string(double)> |
Public Member Functions | |
template<typename M > | |
AlgebraicDecisionTree (const AlgebraicDecisionTree< M > &other, const std::map< M, L > &map) | |
AlgebraicDecisionTree (const Base &add) | |
template<typename X , typename Func > | |
AlgebraicDecisionTree (const DecisionTree< L, X > &other, Func f) | |
Create from an arbitrary DecisionTree<L, X> by operating on it with a functional f . More... | |
AlgebraicDecisionTree (const L &label, double y1, double y2) | |
AlgebraicDecisionTree (const std::vector< typename Base::LabelC > &labelCs, const std::string &table) | |
Create from keys and string table. More... | |
AlgebraicDecisionTree (const std::vector< typename Base::LabelC > &labelCs, const std::vector< double > &ys) | |
Create from keys with cardinalities and a vector table. More... | |
AlgebraicDecisionTree (const typename Base::LabelC &labelC, double y1, double y2) | |
Create a new leaf function splitting on a variable. More... | |
AlgebraicDecisionTree (const typename Base::NodePtr root) | |
Constructor which accepts root pointer. More... | |
AlgebraicDecisionTree (double leaf=1.0) | |
template<typename Iterator > | |
AlgebraicDecisionTree (Iterator begin, Iterator end, const L &label) | |
Create a range of decision trees, splitting on a single variable. More... | |
bool | equals (const AlgebraicDecisionTree &other, double tol=1e-9) const |
Equality method customized to value type double . More... | |
double | max () const |
Find the maximum values amongst all leaves. More... | |
double | min () const |
Find the minimum values amongst all leaves. More... | |
AlgebraicDecisionTree | normalize () const |
Helper method to perform normalization such that all leaves in the tree sum to 1. More... | |
AlgebraicDecisionTree | operator* (const AlgebraicDecisionTree &g) const |
AlgebraicDecisionTree | operator+ (const AlgebraicDecisionTree &g) const |
AlgebraicDecisionTree | operator- () const |
AlgebraicDecisionTree | operator- (const AlgebraicDecisionTree &g) const |
AlgebraicDecisionTree | operator/ (const AlgebraicDecisionTree &g) const |
void | print (const std::string &s="", const typename Base::LabelFormatter &labelFormatter=&DefaultFormatter) const |
print method customized to value type double . More... | |
double | sum () const |
Compute sum of all values. More... | |
AlgebraicDecisionTree | sum (const L &label, size_t cardinality) const |
AlgebraicDecisionTree | sum (const typename Base::LabelC &labelC) const |
![]() | |
DecisionTree () | |
DecisionTree (const double &y) | |
DecisionTree (const L &label, const double &y1, const double &y2) | |
Create tree with 2 assignments y1 , y2 , splitting on variable label More... | |
DecisionTree (const LabelC &label, const double &y1, const double &y2) | |
DecisionTree (const std::vector< LabelC > &labelCs, const std::vector< double > &ys) | |
DecisionTree (const std::vector< LabelC > &labelCs, const std::string &table) | |
DecisionTree (Iterator begin, Iterator end, const L &label) | |
DecisionTree (const L &label, const DecisionTree &f0, const DecisionTree &f1) | |
DecisionTree (const Unary &op, DecisionTree &&other) noexcept | |
Move constructor for DecisionTree. Very efficient as does not allocate anything, just changes in-place. But other is consumed. More... | |
DecisionTree (const DecisionTree< L, X > &other, Func Y_of_X) | |
Convert from a different value type. More... | |
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 translate labels via map from type M to L. More... | |
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 |
virtual | ~DecisionTree ()=default |
Make virtual. More... | |
bool | empty () const |
Check if tree is empty. More... | |
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. More... | |
X | 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 | restrict (const Assignment< L > &assignment) 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 |
std::pair< DecisionTree< L, A >, DecisionTree< L, B > > | split (std::function< std::pair< A, B >(const double &)> AB_of_Y) const |
Convert into two trees with value types A and B. More... | |
DecisionTree (const NodePtr &root) | |
Static Private Member Functions | |
static std::string | DefaultFormatter (const L &x) |
Default method used by labelFormatter or valueFormatter when printing. More... | |
Additional Inherited Members | |
![]() | |
static NodePtr | compose (Iterator begin, Iterator end, const L &label) |
![]() | |
NodePtr | root_ |
A DecisionTree just contains the root. TODO(dellaert): make protected. More... | |
![]() | |
static NodePtr | build (It begin, It end, ValueIt beginY, ValueIt endY) |
static NodePtr | convertFrom (const typename DecisionTree< L, X >::NodePtr &f, std::function< double(const X &)> Y_of_X) |
Convert from a DecisionTree<L, X> to DecisionTree<L, Y>. More... | |
static 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) |
Convert from a DecisionTree<M, X> to DecisionTree<L, Y>. More... | |
static NodePtr | create (It begin, It end, ValueIt beginY, ValueIt endY) |
static bool | DefaultCompare (const double &a, const double &b) |
Default method for comparison of two objects of type Y. More... | |
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?
Definition at line 41 of file AlgebraicDecisionTree.h.
using gtsam::AlgebraicDecisionTree< L >::Base = DecisionTree<L, double> |
Definition at line 56 of file AlgebraicDecisionTree.h.
|
inline |
Definition at line 58 of file AlgebraicDecisionTree.h.
|
inline |
Constructor which accepts root pointer.
Definition at line 61 of file AlgebraicDecisionTree.h.
|
inline |
Definition at line 64 of file AlgebraicDecisionTree.h.
|
inline |
Create a new leaf function splitting on a variable
Definition at line 67 of file AlgebraicDecisionTree.h.
|
inline |
Create a new leaf function splitting on a variable.
labelC | The label with cardinality 2 |
y1 | The value for the first key |
y2 | The value for the second key |
Example:
Definition at line 83 of file AlgebraicDecisionTree.h.
|
inline |
Create from keys with cardinalities and a vector table.
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:
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.
Definition at line 112 of file AlgebraicDecisionTree.h.
|
inline |
Create from keys and string table.
labelCs | The keys, with cardinalities, given as pairs |
table | The string table, given as a string of doubles. |
Definition at line 127 of file AlgebraicDecisionTree.h.
|
inline |
Create a range of decision trees, splitting on a single variable.
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 |
Definition at line 148 of file AlgebraicDecisionTree.h.
|
inline |
Convert labels from type M to type L.
other | The AlgebraicDecisionTree with label type M to convert. |
map | Map from label type M to label type L. |
Definition at line 160 of file AlgebraicDecisionTree.h.
|
inline |
Create from an arbitrary DecisionTree<L, X> by operating on it with a functional f
.
X | The type of the leaf of the original DecisionTree |
Func | Type signature of functional f . |
other | The original DecisionTree from which the AlgbraicDecisionTree is constructed. |
f | Functional used to operate on the leaves of the input DecisionTree. |
Definition at line 182 of file AlgebraicDecisionTree.h.
|
inlinestaticprivate |
Default method used by labelFormatter
or valueFormatter
when printing.
x | The value passed to format. |
Definition at line 49 of file AlgebraicDecisionTree.h.
|
inline |
Equality method customized to value type double
.
Definition at line 266 of file AlgebraicDecisionTree.h.
|
inline |
Find the maximum values amongst all leaves.
Definition at line 235 of file AlgebraicDecisionTree.h.
|
inline |
Find the minimum values amongst all leaves.
Definition at line 227 of file AlgebraicDecisionTree.h.
|
inline |
Helper method to perform normalization such that all leaves in the tree sum to 1.
Definition at line 224 of file AlgebraicDecisionTree.h.
|
inline |
product
Definition at line 201 of file AlgebraicDecisionTree.h.
|
inline |
sum
Definition at line 186 of file AlgebraicDecisionTree.h.
|
inline |
negation
Definition at line 191 of file AlgebraicDecisionTree.h.
|
inline |
subtract
Definition at line 196 of file AlgebraicDecisionTree.h.
|
inline |
division
Definition at line 206 of file AlgebraicDecisionTree.h.
|
inline |
print method customized to value type double
.
Definition at line 254 of file AlgebraicDecisionTree.h.
|
inline |
Compute sum of all values.
Definition at line 211 of file AlgebraicDecisionTree.h.
|
inline |
sum out variable
Definition at line 244 of file AlgebraicDecisionTree.h.
|
inline |
sum out variable
Definition at line 249 of file AlgebraicDecisionTree.h.