Go to the documentation of this file.
26 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
27 #include <boost/serialization/nvp.hpp>
62 template<
typename L,
typename Y>
78 using Binary = std::function<
Y(
const Y&,
const Y&)>;
89 using Ptr = std::shared_ptr<const Node>;
91 #ifdef DT_DEBUG_MEMORY
97 #ifdef DT_DEBUG_MEMORY
98 std::cout << ++nrNodes <<
" constructed " <<
id() << std::endl;
105 #ifdef DT_DEBUG_MEMORY
106 std::cout << --nrNodes <<
" destructed " <<
id() << std::endl;
112 const void*
id()
const {
return this; }
115 virtual void print(
const std::string&
s,
120 bool showZero)
const = 0;
132 virtual Ptr choose(
const L& label,
size_t index)
const = 0;
133 virtual bool isLeaf()
const = 0;
136 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
138 friend class boost::serialization::access;
139 template <
class ARCHIVE>
140 void serialize(ARCHIVE& ar,
const unsigned int ) {}
157 template <
typename It,
typename ValueIt>
165 template <
typename It,
typename ValueIt>
178 template <
typename M,
typename X>
180 std::function<
L(
const M&)> L_of_M,
181 std::function<
Y(
const X&)> Y_of_X)
const;
206 DecisionTree(
const std::vector<LabelC>& labelCs,
const std::vector<Y>& ys);
212 template<
typename Iterator>
226 template <
typename X,
typename Func>
239 template <
typename M,
typename X,
typename Func>
291 template <
typename Func>
308 template <
typename Func>
325 template <
typename Func>
346 template <
typename Func,
typename X>
350 std::set<L>
labels()
const;
381 return combine(labelC.first, labelC.second, op);
395 bool showZero =
true)
const;
404 template<
typename Iterator>
NodePtr
405 compose(Iterator begin, Iterator
end,
const L& label)
const;
410 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
412 friend class boost::serialization::access;
413 template <
class ARCHIVE>
414 void serialize(ARCHIVE& ar,
const unsigned int ) {
415 ar& BOOST_SERIALIZATION_NVP(
root_);
420 template <
class L,
class Y>
425 template<
typename L,
typename Y>
433 template<
typename L,
typename Y>
440 template<
typename L,
typename Y>
444 return f.apply(
g, op);
453 template <
typename L,
typename T1,
typename T2>
NodePtr create(It begin, It end, ValueIt beginY, ValueIt endY) const
std::function< std::string(Key)> LabelFormatter
Annotation for function names.
std::function< bool(const double &, const double &)> CompareFunc
static sharedNode Leaf(Key key, const SymbolicFactorGraph &factors)
Typedefs for easier changing of types.
Concept check for values that can be used in unit tests.
bool empty() const
Check if tree is empty.
bool equals(const DecisionTree &other, const CompareFunc &compare=&DefaultCompare) 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
std::function< std::string(double)> ValueFormatter
std::set< L > labels() const
virtual const Y & operator()(const Assignment< L > &x) const =0
void print(const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const
GTSAM-style print.
DecisionTree choose(const L &label, size_t index) const
ofstream os("timeSchurFactors.csv")
virtual bool equals(const Node &other, const CompareFunc &compare=&DefaultCompare) const =0
static bool DefaultCompare(const Y &a, const Y &b)
Default method for comparison of two objects of type Y.
std::shared_ptr< const Node > Ptr
virtual bool isLeaf() const =0
virtual Ptr apply_f_op_g(const Node &, const Binary &) const =0
DecisionTree combine(const LabelC &labelC, const Binary &op) const
std::function< double(const double &)> Unary
NodePtr root_
A DecisionTree just contains the root. TODO(dellaert): make protected.
virtual Ptr apply_g_op_fL(const Leaf &, const Binary &) const =0
EIGEN_DEVICE_FUNC const Scalar & q
virtual Ptr choose(const L &label, size_t index) const =0
std::function< double(const double &, const double &)> Binary
An assignment from labels to a discrete value index (size_t)
void visit(Func f) const
Visit all leaves in depth-first fashion.
void dot(std::ostream &os, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero=true) const
void visitWith(Func f) const
Visit all leaves in depth-first fashion.
DecisionTree apply(const Unary &op) const
virtual void dot(std::ostream &os, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter, bool showZero) const =0
void g(const string &key, int i)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
a decision tree is a function from assignments to values.
virtual bool sameLeaf(const Leaf &q) const =0
virtual ~DecisionTree()=default
Make virtual.
virtual Ptr apply(const Unary &op) const =0
bool operator==(const DecisionTree &q) const
std::function< double(const Assignment< Key > &, const double &)> UnaryAssignment
std::pair< Key, size_t > LabelC
NodePtr compose(Iterator begin, Iterator end, const L &label) const
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
Apply unary operator op to DecisionTree f.
size_t nrLeaves() const
Return the number of leaves in the tree.
typename Node::Ptr NodePtr
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
DecisionTree combine(const L &label, size_t cardinality, const Binary &op) const
static const EIGEN_DEPRECATED end_t end
std::pair< DecisionTree< L, T1 >, DecisionTree< L, T2 > > unzip(const DecisionTree< L, std::pair< T1, T2 > > &input)
unzip a DecisionTree with std::pair values.
static std::string valueFormatter(const double &v)
X fold(Func f, X x0) const
Fold a binary function over the tree, returning accumulator.
NodePtr convertFrom(const typename DecisionTree< M, X >::NodePtr &f, std::function< L(const M &)> L_of_M, std::function< Y(const X &)> Y_of_X) const
Convert from a DecisionTree<M, X> to DecisionTree<L, Y>.
const Y & operator()(const Assignment< L > &x) const
NodePtr build(It begin, It end, ValueIt beginY, ValueIt endY) const
virtual void print(const std::string &s, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const =0
void visitLeaf(Func f) const
Visit all leaves in depth-first fashion.
virtual Ptr apply_g_op_fC(const Choice &, const Binary &) const =0
Matrix< RealScalar, Dynamic, Dynamic > M
gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:02:10