23 #include <boost/function.hpp> 35 template<
typename L,
typename Y>
41 typedef boost::function<Y(
const Y&)>
Unary;
42 typedef boost::function<Y(
const Y&,
const Y&)> Binary;
54 typedef boost::shared_ptr<const Node> Ptr;
56 #ifdef DT_DEBUG_MEMORY 62 #ifdef DT_DEBUG_MEMORY 63 std::cout << ++nrNodes <<
" constructed " << id() << std::endl; std::cout.flush();
69 #ifdef DT_DEBUG_MEMORY 70 std::cout << --nrNodes <<
" destructed " << id() << std::endl; std::cout.flush();
75 const void* id()
const {
return this; }
78 virtual void print(
const std::string& s =
"")
const = 0;
79 virtual void dot(std::ostream& os,
bool showZero)
const = 0;
80 virtual bool sameLeaf(
const Leaf& q)
const = 0;
81 virtual bool sameLeaf(
const Node& q)
const = 0;
82 virtual bool equals(
const Node& other,
double tol = 1e-9)
const = 0;
83 virtual const Y& operator()(
const Assignment<L>& x)
const = 0;
84 virtual Ptr apply(
const Unary& op)
const = 0;
85 virtual Ptr apply_f_op_g(
const Node&,
const Binary&)
const = 0;
86 virtual Ptr apply_g_op_fL(
const Leaf&,
const Binary&)
const = 0;
87 virtual Ptr apply_g_op_fC(
const Choice&,
const Binary&)
const = 0;
88 virtual Ptr choose(
const L& label,
size_t index)
const = 0;
89 virtual bool isLeaf()
const = 0;
104 template<
typename It,
typename ValueIt>
105 NodePtr create(It begin, It end, ValueIt beginY, ValueIt endY)
const;
108 template<
typename M,
typename X>
NodePtr 110 L>& map, boost::function<Y(
const X&)> op);
130 DecisionTree(
const std::vector<LabelC>& labelCs,
const std::vector<Y>& ys);
133 DecisionTree(
const std::vector<LabelC>& labelCs,
const std::string& table);
136 template<
typename Iterator>
137 DecisionTree(Iterator begin, Iterator end,
const L& label);
144 template<
typename M,
typename X>
146 const std::map<M, L>& map, boost::function<Y(
const X&)> op);
153 void print(
const std::string& s =
"DecisionTree")
const;
190 return combine(labelC.first, labelC.second, op);
194 void dot(std::ostream& os,
bool showZero =
true)
const;
197 void dot(
const std::string& name,
bool showZero =
true)
const;
206 template<
typename Iterator>
NodePtr 207 compose(Iterator begin, Iterator end,
const L& label)
const;
215 template<
typename Y,
typename L>
221 template<
typename Y,
typename L>
222 DecisionTree<L, Y>
apply(
const DecisionTree<L, Y>& f,
223 const DecisionTree<L, Y>& g,
224 const typename DecisionTree<L, Y>::Binary& op) {
225 return f.apply(g, op);
Definition: DecisionTree-inl.h:52
const Y & operator()(const Assignment< L > &x) const
evaluate
Definition: DecisionTree-inl.h:619
NodePtr create(It begin, It end, ValueIt beginY, ValueIt endY) const
Internal recursive function to create from keys, cardinalities, and Y values.
Definition: DecisionTree-inl.h:531
DecisionTree apply(const Unary &op) const
apply Unary operation "op" to f
Definition: DecisionTree-inl.h:624
Template to create a binary predicate.
Definition: Testable.h:110
DecisionTree combine(const L &label, size_t cardinality, const Binary &op) const
combine subtrees on key with binary operation "op"
Definition: DecisionTree-inl.h:649
boost::function< Y(const Y &)> Unary
Handy typedefs for unary and binary function types.
Definition: DecisionTree.h:41
Decision Tree L = label for variables Y = function range (any algebra), e.g., bool,...
Definition: DecisionTree.h:36
An assignment from labels to a discrete value index (size_t)
DecisionTree choose(const L &label, size_t index) const
create a new function where value(label)==index It's like "restrict" in Darwiche09book pg329,...
Definition: DecisionTree.h:180
An assignment from labels to value index (size_t).
Definition: Assignment.h:34
NodePtr convert(const typename DecisionTree< M, X >::NodePtr &f, const std::map< M, L > &map, boost::function< Y(const X &)> op)
Convert to a different type.
Definition: DecisionTree-inl.h:569
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
free versions of apply
Definition: DecisionTree.h:216
Definition: DecisionTree-inl.h:142
std::pair< L, size_t > LabelC
A label annotated with cardinality.
Definition: DecisionTree.h:45
---------------------— Node base class ------------------------—
Definition: DecisionTree.h:52
bool operator==(const DecisionTree &q) const
equality
Definition: DecisionTree-inl.h:614
DecisionTree()
Default constructor.
Definition: DecisionTree-inl.h:372
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
virtual ~DecisionTree()
Make virtual.
Definition: DecisionTree.h:163
void print(const std::string &s="DecisionTree") const
GTSAM-style print.
Definition: DecisionTree-inl.h:609
DecisionTree combine(const LabelC &labelC, const Binary &op) const
combine with LabelC for convenience
Definition: DecisionTree.h:189
Node::Ptr NodePtr
---------------------— Node base class ------------------------—
Definition: DecisionTree.h:96
void dot(std::ostream &os, bool showZero=true) const
output to graphviz format, stream version
Definition: DecisionTree-inl.h:661