gtsam 4.1.1
gtsam
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
31namespace 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
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>
60 DecisionTreeFactor(const DiscreteKeys& keys, SOURCE table) :
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
126 DecisionTreeFactor apply(const DecisionTreeFactor& f, ADT::Binary op) const;
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
170template<> struct traits<DecisionTreeFactor> : public Testable<DecisionTreeFactor> {};
171
172}// namespace gtsam
Variable ordering for the elimination algorithm.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
free versions of apply
Definition: DecisionTree.h:218
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Template to create a binary predicate.
Definition: Testable.h:111
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:151
An assignment from labels to value index (size_t).
Definition: Assignment.h:34
const double & operator()(const Assignment< Key > &x) const
evaluate
Definition: DecisionTree-inl.h:619
A discrete probabilistic factor.
Definition: DecisionTreeFactor.h:38
DecisionTreeFactor(const DiscreteKeys &keys, SOURCE table)
Constructor from Indices and (string or doubles)
Definition: DecisionTreeFactor.h:60
shared_ptr sum(const Ordering &keys) const
Create new factor by summing all values with the same separator values.
Definition: DecisionTreeFactor.h:108
DecisionTreeFactor operator*(const DecisionTreeFactor &f) const override
multiply two factors
Definition: DecisionTreeFactor.h:88
shared_ptr max(size_t nrFrontals) const
Create new factor by maximizing over all values with the same separator values.
Definition: DecisionTreeFactor.h:113
double operator()(const Values &values) const override
Value is just look up in AlgebraicDecisonTree.
Definition: DecisionTreeFactor.h:83
DiscreteFactor Base
Typedef to base class.
Definition: DecisionTreeFactor.h:44
shared_ptr sum(size_t nrFrontals) const
Create new factor by summing all values with the same separator values.
Definition: DecisionTreeFactor.h:103
DecisionTreeFactor toDecisionTreeFactor() const override
Convert into a decisiontree.
Definition: DecisionTreeFactor.h:98
DecisionTreeFactor operator/(const DecisionTreeFactor &f) const
divide by factor f (safely)
Definition: DecisionTreeFactor.h:93
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition: DiscreteConditional.h:36
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition: DiscreteFactor.h:34
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:37
A base class for both DiscreteFactor and DiscreteConditional.
Definition: Potentials.h:32
Definition: Ordering.h:34