21#include <gtsam/discrete/DecisionTree-inl.h>
39 static inline double zero() {
42 static inline double one() {
45 static inline double add(
const double& a,
const double& b) {
48 static inline double max(
const double& a,
const double& b) {
49 return std::max(a, b);
51 static inline double mul(
const double& a,
const double& b) {
54 static inline double div(
const double& a,
const double& b) {
57 static inline double id(
const double& x) {
72 Super(label, y1, y2) {
77 Super(labelC, y1, y2) {
82 (
const std::vector<typename Super::LabelC>& labelCs,
const std::vector<double>& ys) {
83 this->root_ =
Super::create(labelCs.begin(), labelCs.end(), ys.begin(),
89 (
const std::vector<typename Super::LabelC>& labelCs,
const std::string& table) {
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));
97 this->root_ =
Super::create(labelCs.begin(), labelCs.end(), ys.begin(),
102 template<
typename Iterator>
105 this->root_ = compose(begin, end, label);
111 const std::map<M, L>& map) {
112 this->root_ = this->
template convert<M, double>(other.root_, map,
118 return this->
apply(g, &Ring::add);
123 return this->
apply(g, &Ring::mul);
128 return this->
apply(g, &Ring::div);
133 return this->
combine(label, cardinality, &Ring::add);
138 return this->
combine(labelC, &Ring::add);
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Algebraic Decision Trees fix the range to double Just has some nice constructors and some syntactic s...
Definition: AlgebraicDecisionTree.h:31
AlgebraicDecisionTree operator/(const AlgebraicDecisionTree &g) const
division
Definition: AlgebraicDecisionTree.h:127
AlgebraicDecisionTree sum(const L &label, size_t cardinality) const
sum out variable
Definition: AlgebraicDecisionTree.h:132
AlgebraicDecisionTree(const AlgebraicDecisionTree< M > &other, const std::map< M, L > &map)
Convert.
Definition: AlgebraicDecisionTree.h:110
AlgebraicDecisionTree(const L &label, double y1, double y2)
Create a new leaf function splitting on a variable.
Definition: AlgebraicDecisionTree.h:71
AlgebraicDecisionTree(const typename Super::LabelC &labelC, double y1, double y2)
Create a new leaf function splitting on a variable.
Definition: AlgebraicDecisionTree.h:76
AlgebraicDecisionTree operator+(const AlgebraicDecisionTree &g) const
sum
Definition: AlgebraicDecisionTree.h:117
AlgebraicDecisionTree sum(const typename Super::LabelC &labelC) const
sum out variable
Definition: AlgebraicDecisionTree.h:137
AlgebraicDecisionTree operator*(const AlgebraicDecisionTree &g) const
product
Definition: AlgebraicDecisionTree.h:122
AlgebraicDecisionTree(Iterator begin, Iterator end, const L &label)
Create a new function splitting on a variable.
Definition: AlgebraicDecisionTree.h:103
The Real ring with addition and multiplication.
Definition: AlgebraicDecisionTree.h:38
Decision Tree L = label for variables Y = function range (any algebra), e.g., bool,...
Definition: DecisionTree.h:38
DecisionTree apply(const Unary &op) const
apply Unary operation "op" to f
Definition: DecisionTree-inl.h:624
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
std::pair< L, size_t > LabelC
A label annotated with cardinality.
Definition: DecisionTree.h:47
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