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 
21 #include <gtsam/base/Testable.h>
24 #include <gtsam/inference/Factor.h>
25 
26 #include <string>
27 namespace gtsam {
28 
29 class DecisionTreeFactor;
30 class DiscreteConditional;
31 class HybridValues;
32 
39 class GTSAM_EXPORT DiscreteFactor : public Factor {
40  public:
41  // typedefs needed to play nice with gtsam
42  typedef DiscreteFactor This;
43  typedef std::shared_ptr<DiscreteFactor>
45  typedef Factor Base;
46 
48 
49  protected:
51  std::map<Key, size_t> cardinalities_;
52 
53  public:
56 
59 
65  template <typename CONTAINER>
66  DiscreteFactor(const CONTAINER& keys,
67  const std::map<Key, size_t> cardinalities = {})
68  : Base(keys), cardinalities_(cardinalities) {}
69 
73 
75  virtual bool equals(const DiscreteFactor& lf, double tol = 1e-9) const = 0;
76 
78  void print(
79  const std::string& s = "DiscreteFactor\n",
80  const KeyFormatter& formatter = DefaultKeyFormatter) const override {
82  }
83 
87 
89  DiscreteKeys discreteKeys() const;
90 
91  std::map<Key, size_t> cardinalities() const { return cardinalities_; }
92 
93  size_t cardinality(Key j) const { return cardinalities_.at(j); }
94 
96  virtual double operator()(const DiscreteValues&) const = 0;
97 
99  virtual double error(const DiscreteValues& values) const;
100 
105  double error(const HybridValues& c) const override;
106 
108  virtual AlgebraicDecisionTree<Key> errorTree() const;
109 
112  virtual DecisionTreeFactor operator*(const DecisionTreeFactor&) const = 0;
113 
114  virtual DecisionTreeFactor toDecisionTreeFactor() const = 0;
115 
119 
122 
130  virtual std::string markdown(
131  const KeyFormatter& keyFormatter = DefaultKeyFormatter,
132  const Names& names = {}) const = 0;
133 
141  virtual std::string html(
142  const KeyFormatter& keyFormatter = DefaultKeyFormatter,
143  const Names& names = {}) const = 0;
144 
146 
147  private:
148 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
149 
150  friend class boost::serialization::access;
151  template <class ARCHIVE>
152  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
153  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
154  ar& BOOST_SERIALIZATION_NVP(cardinalities_);
155  }
156 #endif
157 };
158 // DiscreteFactor
159 
160 // traits
161 template <>
162 struct traits<DiscreteFactor> : public Testable<DiscreteFactor> {};
163 
180 std::vector<double> expNormalize(const std::vector<double>& logProbs);
181 
182 } // namespace gtsam
Eigen::internal::print
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: NEON/PacketMath.h:3115
gtsam::markdown
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition: DiscreteValues.cpp:130
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:44
gtsam::HybridValues
Definition: HybridValues.h:37
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::DiscreteFactor::cardinalities
std::map< Key, size_t > cardinalities() const
Definition: DiscreteFactor.h:91
Testable.h
Concept check for values that can be used in unit tests.
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::DiscreteFactor::cardinalities_
std::map< Key, size_t > cardinalities_
Map of Keys and their cardinalities.
Definition: DiscreteFactor.h:51
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::Factor
Definition: Factor.h:70
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
HybridValues
DiscreteFactor
Discrete values for.
Factor.h
The base class for all factors.
gtsam::DiscreteFactor::DiscreteFactor
DiscreteFactor()
Definition: DiscreteFactor.h:58
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::AlgebraicDecisionTree< Key >
gtsam::operator*
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:52
AlgebraicDecisionTree.h
Algebraic Decision Trees.
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
operator()
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:73
gtsam::KeyFormatter
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
gtsam::DiscreteFactor::print
void print(const std::string &s="DiscreteFactor\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition: DiscreteFactor.h:78
gtsam::DiscreteFactor::This
DiscreteFactor This
This class.
Definition: DiscreteFactor.h:42
gtsam::DiscreteFactor::DiscreteFactor
DiscreteFactor(const CONTAINER &keys, const std::map< Key, size_t > cardinalities={})
Definition: DiscreteFactor.h:66
gtsam::DiscreteFactor::cardinality
size_t cardinality(Key j) const
Definition: DiscreteFactor.h:93
process_shonan_timing_results.names
dictionary names
Definition: process_shonan_timing_results.py:175
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
DiscreteValues.h
gtsam::DiscreteFactor::shared_ptr
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:44
error
static double error
Definition: testRot3.cpp:37
gtsam::traits
Definition: Group.h:36
gtsam::DiscreteFactor::Names
DiscreteValues::Names Names
Translation table from values to strings.
Definition: DiscreteFactor.h:121
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::expNormalize
std::vector< double > expNormalize(const std::vector< double > &logProbs)
Normalize a set of log probabilities.
Definition: DiscreteFactor.cpp:70
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::DiscreteFactor::Base
Factor Base
Our base class.
Definition: DiscreteFactor.h:45
gtsam::html
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Definition: DiscreteValues.cpp:135
gtsam::DiscreteFactor
Definition: DiscreteFactor.h:39
gtsam::DiscreteValues::Names
std::map< Key, std::vector< std::string > > Names
Translation table from values to strings.
Definition: DiscreteValues.h:95
Base
Definition: test_virtual_functions.cpp:156
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:13