42 public AlgebraicDecisionTree<Key> {
47 typedef std::shared_ptr<DecisionTreeFactor> shared_ptr;
48 typedef AlgebraicDecisionTree<Key> ADT;
53 using Base::UnaryAssignment;
84 const std::vector<double>& table);
107 template <
class SOURCE>
127 const std::string& s =
"DecisionTreeFactor:\n",
141 using DiscreteFactor::operator();
165 return std::make_shared<DecisionTreeFactor>(
166 apply([s](
const double& a) {
return Ring::mul(a, s); }));
171 return apply(f, Ring::mul);
174 static double safe_div(
const double& a,
const double& b);
186 return apply(f, safe_div);
204 return combine(nrFrontals, Ring::add);
217 return combine(nrFrontals, Ring::max);
259 shared_ptr combine(
size_t nrFrontals, Binary op)
const;
267 shared_ptr combine(
const Ordering& keys, Binary op)
const;
270 std::vector<std::pair<DiscreteValues, double>> enumerate()
const;
273 std::vector<double> probabilities()
const;
284 double computeThreshold(
const size_t N)
const;
317 void dot(std::ostream& os,
319 bool showZero =
true)
const;
322 void dot(
const std::string& name,
324 bool showZero =
true)
const;
328 bool showZero =
true)
const;
338 const Names& names = {})
const override;
347 std::string html(
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
348 const Names& names = {})
const override;
358 double error(
const HybridValues& values)
const override;
363#if GTSAM_ENABLE_BOOST_SERIALIZATION
365 friend class boost::serialization::access;
366 template <
class ARCHIVE>
367 void serialize(ARCHIVE& ar,
const unsigned int ) {
368 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
369 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(ADT);
specialized key for discrete variables
Algebraic Decision Trees.
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:38
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition DiscreteValues.cpp:155
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
DecisionTree< L, Y > apply(const DecisionTree< L, Y > &f, const typename DecisionTree< L, Y >::Unary &op)
free versions of apply
Definition DecisionTree.h:467
double dot(const V1 &a, const V2 &b)
Dot product.
Definition Vector.h:191
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Template to create a binary predicate.
Definition Testable.h:112
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
double max() const
Definition AlgebraicDecisionTree.h:235
An assignment from labels to value index (size_t).
Definition Assignment.h:37
const Y & operator()(const Assignment< L > &x) const
evaluate
Definition DecisionTree-inl.h:997
size_t nrLeaves() const
Return the number of leaves in the tree.
Definition DecisionTree-inl.h:935
A discrete probabilistic factor.
Definition DecisionTreeFactor.h:42
DecisionTreeFactor operator*(const DecisionTreeFactor &f) const override
multiply two factors
Definition DecisionTreeFactor.h:170
virtual double evaluate(const Assignment< Key > &values) const override
Calculate probability for given values, is just look up in AlgebraicDecisionTree.
Definition DecisionTreeFactor.h:136
DecisionTreeFactor apply(Unary op) const
Apply unary operator (*this) "op" f.
Definition DecisionTreeFactor.cpp:135
shared_ptr combine(size_t nrFrontals, Binary op) const
Combine frontal variables using binary operator "op".
Definition DecisionTreeFactor.cpp:170
DiscreteFactor::shared_ptr max(size_t nrFrontals) const override
Create new factor by maximizing over all values with the same separator.
Definition DecisionTreeFactor.h:216
DiscreteFactor::shared_ptr max(const Ordering &keys) const override
Create new factor by maximizing over all values with the same separator.
Definition DecisionTreeFactor.h:221
double max() const override
Find the maximum value in the factor.
Definition DecisionTreeFactor.h:213
DiscreteFactor Base
Typedef to base class.
Definition DecisionTreeFactor.h:46
uint64_t nrValues() const override
Get the number of non-zero values contained in this factor.
Definition DecisionTreeFactor.h:310
DiscreteFactor::shared_ptr sum(const Ordering &keys) const override
Create new factor by summing all values with the same separator values.
Definition DecisionTreeFactor.h:208
DecisionTreeFactor(const DiscreteKey &key, SOURCE table)
Single-key specialization.
Definition DecisionTreeFactor.h:108
DiscreteFactor::shared_ptr sum(size_t nrFrontals) const override
Create new factor by summing all values with the same separator values.
Definition DecisionTreeFactor.h:203
DecisionTreeFactor toDecisionTreeFactor() const override
Convert into a decision tree.
Definition DecisionTreeFactor.h:194
DiscreteFactor::shared_ptr operator*(double s) const override
multiply with a scalar
Definition DecisionTreeFactor.h:164
DecisionTreeFactor()
Default constructor for I/O.
Definition DecisionTreeFactor.cpp:34
DecisionTreeFactor operator/(const DecisionTreeFactor &f) const
Divide by factor f (safely).
Definition DecisionTreeFactor.h:185
DecisionTreeFactor(const DiscreteKey &key, const std::vector< double > &row)
Single-key specialization, with vector of doubles.
Definition DecisionTreeFactor.h:112
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition DiscreteConditional.h:40
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition DiscreteFactor.h:41
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition DiscreteFactor.h:46
DiscreteFactor()
Default constructor creates empty factor.
Definition DiscreteFactor.h:65
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:41
A map from keys to values.
Definition DiscreteValues.h:34
A discrete probabilistic factor optimized for sparsity.
Definition TableFactor.h:51
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:37
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143