GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
DiscreteFactor.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 
22 #include <gtsam/inference/Factor.h>
23 #include <gtsam/base/Testable.h>
24 
25 #include <string>
26 namespace gtsam {
27 
28 class DecisionTreeFactor;
29 class DiscreteConditional;
30 class HybridValues;
31 
38 class GTSAM_EXPORT DiscreteFactor: public Factor {
39 
40 public:
41 
42  // typedefs needed to play nice with gtsam
43  typedef DiscreteFactor This;
44  typedef std::shared_ptr<DiscreteFactor> shared_ptr;
45  typedef Factor Base;
46 
48 
49 public:
50 
53 
56 
59  template<typename CONTAINER>
60  DiscreteFactor(const CONTAINER& keys) : Base(keys) {}
61 
65 
67  virtual bool equals(const DiscreteFactor& lf, double tol = 1e-9) const = 0;
68 
70  void print(
71  const std::string& s = "DiscreteFactor\n",
72  const KeyFormatter& formatter = DefaultKeyFormatter) const override {
73  Base::print(s, formatter);
74  }
75 
79 
81  virtual double operator()(const DiscreteValues&) const = 0;
82 
84  double error(const DiscreteValues& values) const;
85 
90  double error(const HybridValues& c) const override;
91 
93  virtual DecisionTreeFactor operator*(const DecisionTreeFactor&) const = 0;
94 
95  virtual DecisionTreeFactor toDecisionTreeFactor() const = 0;
96 
100 
103 
111  virtual std::string markdown(
112  const KeyFormatter& keyFormatter = DefaultKeyFormatter,
113  const Names& names = {}) const = 0;
114 
122  virtual std::string html(
123  const KeyFormatter& keyFormatter = DefaultKeyFormatter,
124  const Names& names = {}) const = 0;
125 
127 };
128 // DiscreteFactor
129 
130 // traits
131 template<> struct traits<DiscreteFactor> : public Testable<DiscreteFactor> {};
132 
133 
150 std::vector<double> expNormalize(const std::vector<double> &logProbs);
151 
152 
153 }// namespace gtsam
void print(const std::string &s="DiscreteFactor\, const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition: DiscreteFactor.h:70
Definition: HybridValues.h:38
std::string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteValues::Names &names={})
Free version of markdown.
Concept check for values that can be used in unit tests.
Definition: Factor.h:69
Definition: Testable.h:152
Definition: Group.h:43
Definition: DecisionTreeFactor.h:44
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:52
DiscreteFactor This
This class.
Definition: DiscreteFactor.h:43
Definition: Testable.h:112
DiscreteFactor()
Definition: DiscreteFactor.h:55
GTSAM_EXPORT void print(const Matrix &A, const std::string &s, std::ostream &stream)
Definition: DiscreteValues.h:34
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
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:44
DiscreteValues::Names Names
Translation table from values to strings.
Definition: DiscreteFactor.h:102
Definition: chartTesting.h:28
Definition: DiscreteFactor.h:38
Factor Base
Our base class.
Definition: DiscreteFactor.h:45
std::string html(const DiscreteValues &values, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteValues::Names &names={})
Free version of html.
std::vector< double > expNormalize(const std::vector< double > &logProbs)
Normalize a set of log probabilities.
DiscreteFactor(const CONTAINER &keys)
Definition: DiscreteFactor.h:60
std::map< Key, std::vector< std::string > > Names
Translation table from values to strings.
Definition: DiscreteValues.h:95
The base class for all factors.