DecisionTreeFactor.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 
24 
25 #include <boost/shared_ptr.hpp>
26 
27 #include <vector>
28 #include <exception>
29 #include <stdexcept>
30 
31 namespace gtsam {
32 
33  class DiscreteConditional;
34 
38  class GTSAM_EXPORT DecisionTreeFactor: public DiscreteFactor, public Potentials {
39 
40  public:
41 
42  // typedefs needed to play nice with gtsam
44  typedef DiscreteFactor Base;
45  typedef boost::shared_ptr<DecisionTreeFactor> shared_ptr;
46 
47  public:
48 
51 
54 
56  DecisionTreeFactor(const DiscreteKeys& keys, const ADT& potentials);
57 
59  template<class SOURCE>
61  DiscreteFactor(keys.indices()), Potentials(keys, table) {
62  }
63 
66 
70 
72  bool equals(const DiscreteFactor& other, double tol = 1e-9) const override;
73 
74  // print
75  void print(const std::string& s = "DecisionTreeFactor:\n",
76  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
77 
81 
83  double operator()(const Values& values) const override {
84  return Potentials::operator()(values);
85  }
86 
89  return apply(f, ADT::Ring::mul);
90  }
91 
94  return apply(f, safe_div);
95  }
96 
99  return *this;
100  }
101 
103  shared_ptr sum(size_t nrFrontals) const {
104  return combine(nrFrontals, ADT::Ring::add);
105  }
106 
108  shared_ptr sum(const Ordering& keys) const {
109  return combine(keys, ADT::Ring::add);
110  }
111 
113  shared_ptr max(size_t nrFrontals) const {
114  return combine(nrFrontals, ADT::Ring::max);
115  }
116 
120 
127 
134  shared_ptr combine(size_t nrFrontals, ADT::Binary op) const;
135 
142  shared_ptr combine(const Ordering& keys, ADT::Binary op) const;
143 
144 
145 // /**
146 // * @brief Permutes the keys in Potentials and DiscreteFactor
147 // *
148 // * This re-implements the permuteWithInverse() in both Potentials
149 // * and DiscreteFactor by doing both of them together.
150 // */
151 //
152 // void permuteWithInverse(const Permutation& inversePermutation){
153 // DiscreteFactor::permuteWithInverse(inversePermutation);
154 // Potentials::permuteWithInverse(inversePermutation);
155 // }
156 //
157 // /**
158 // * Apply a reduction, which is a remapping of variable indices.
159 // */
160 // virtual void reduceWithInverse(const internal::Reduction& inverseReduction) {
161 // DiscreteFactor::reduceWithInverse(inverseReduction);
162 // Potentials::reduceWithInverse(inverseReduction);
163 // }
164 
166 };
167 // DecisionTreeFactor
168 
169 // traits
170 template<> struct traits<DecisionTreeFactor> : public Testable<DecisionTreeFactor> {};
171 
172 }// namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
DecisionTreeFactor operator*(const DecisionTreeFactor &f) const override
multiply two factors
#define max(a, b)
Definition: datatypes.h:20
double mul(const double &a, const double &b)
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
Definition: DecisionTree.h:216
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
shared_ptr sum(const Ordering &keys) const
Create new factor by summing all values with the same separator values.
leaf::MyValues values
boost::function< double(const double &, const double &)> Binary
Definition: DecisionTree.h:42
double operator()(const Values &values) const override
Value is just look up in AlgebraicDecisonTree.
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
graph add(boost::make_shared< UnaryFactor >(1, 0.0, 0.0, unaryNoise))
DecisionTreeFactor toDecisionTreeFactor() const override
Convert into a decisiontree.
DecisionTreeFactor(const DiscreteKeys &keys, SOURCE table)
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
shared_ptr sum(size_t nrFrontals) const
Create new factor by summing all values with the same separator values.
DiscreteFactor Base
Typedef to base class.
DecisionTreeFactor operator/(const DecisionTreeFactor &f) const
divide by factor f (safely)
traits
Definition: chartTesting.h:28
const double & operator()(const Assignment< Key > &x) const
ArrayXXf table(10, 4)
boost::shared_ptr< DecisionTreeFactor > shared_ptr
shared_ptr max(size_t nrFrontals) const
Create new factor by maximizing over all values with the same separator values.
const G double tol
Definition: Group.h:83
const KeyVector keys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:37


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