AlgebraicDecisionTree.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #pragma once
20 
22 
23 namespace gtsam {
24 
30  template<typename L>
31  class AlgebraicDecisionTree: public DecisionTree<L, double> {
32 
33  public:
34 
36 
38  struct Ring {
39  static inline double zero() {
40  return 0.0;
41  }
42  static inline double one() {
43  return 1.0;
44  }
45  static inline double add(const double& a, const double& b) {
46  return a + b;
47  }
48  static inline double max(const double& a, const double& b) {
49  return std::max(a, b);
50  }
51  static inline double mul(const double& a, const double& b) {
52  return a * b;
53  }
54  static inline double div(const double& a, const double& b) {
55  return a / b;
56  }
57  static inline double id(const double& x) {
58  return x;
59  }
60  };
61 
63  Super(1.0) {
64  }
65 
66  AlgebraicDecisionTree(const Super& add) :
67  Super(add) {
68  }
69 
71  AlgebraicDecisionTree(const L& label, double y1, double y2) :
72  Super(label, y1, y2) {
73  }
74 
76  AlgebraicDecisionTree(const typename Super::LabelC& labelC, double y1, double y2) :
77  Super(labelC, y1, y2) {
78  }
79 
82  (const std::vector<typename Super::LabelC>& labelCs, const std::vector<double>& ys) {
83  this->root_ = Super::create(labelCs.begin(), labelCs.end(), ys.begin(),
84  ys.end());
85  }
86 
89  (const std::vector<typename Super::LabelC>& labelCs, const std::string& table) {
90  // Convert string to doubles
91  std::vector<double> ys;
92  std::istringstream iss(table);
93  std::copy(std::istream_iterator<double>(iss),
94  std::istream_iterator<double>(), std::back_inserter(ys));
95 
96  // now call recursive Create
97  this->root_ = Super::create(labelCs.begin(), labelCs.end(), ys.begin(),
98  ys.end());
99  }
100 
102  template<typename Iterator>
103  AlgebraicDecisionTree(Iterator begin, Iterator end, const L& label) :
104  Super(nullptr) {
105  this->root_ = compose(begin, end, label);
106  }
107 
109  template<typename M>
111  const std::map<M, L>& map) {
112  this->root_ = this->template convert<M, double>(other.root_, map,
113  Ring::id);
114  }
115 
118  return this->apply(g, &Ring::add);
119  }
120 
123  return this->apply(g, &Ring::mul);
124  }
125 
128  return this->apply(g, &Ring::div);
129  }
130 
132  AlgebraicDecisionTree sum(const L& label, size_t cardinality) const {
133  return this->combine(label, cardinality, &Ring::add);
134  }
135 
137  AlgebraicDecisionTree sum(const typename Super::LabelC& labelC) const {
138  return this->combine(labelC, &Ring::add);
139  }
140 
141  };
142 // AlgebraicDecisionTree
143 
144 }
145 // namespace gtsam
#define max(a, b)
Definition: datatypes.h:20
static double add(const double &a, const double &b)
DecisionTree apply(const Unary &op) const
MatrixXd L
Definition: LLT_example.cpp:6
static double max(const double &a, const double &b)
void g(const string &key, int i)
Definition: testBTree.cpp:43
AlgebraicDecisionTree operator+(const AlgebraicDecisionTree &g) const
static double mul(const double &a, const double &b)
Array33i a
DecisionTree combine(const L &label, size_t cardinality, const Binary &op) const
NodePtr compose(Iterator begin, Iterator end, const L &label) const
static double div(const double &a, const double &b)
AlgebraicDecisionTree sum(const typename Super::LabelC &labelC) const
AlgebraicDecisionTree(Iterator begin, Iterator end, const L &label)
const G & b
Definition: Group.h:83
traits
Definition: chartTesting.h:28
NodePtr create(It begin, It end, ValueIt beginY, ValueIt endY) const
ArrayXXf table(10, 4)
static double id(const double &x)
AlgebraicDecisionTree(const typename Super::LabelC &labelC, double y1, double y2)
AlgebraicDecisionTree operator*(const AlgebraicDecisionTree &g) const
DecisionTree< L, double > Super
AlgebraicDecisionTree(const AlgebraicDecisionTree< M > &other, const std::map< M, L > &map)
AlgebraicDecisionTree sum(const L &label, size_t cardinality) const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
AlgebraicDecisionTree(const L &label, double y1, double y2)
AlgebraicDecisionTree operator/(const AlgebraicDecisionTree &g) const
std::pair< Key, size_t > LabelC
Definition: DecisionTree.h:45


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:36