DiscreteLookupDAG.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 
18 #pragma once
19 
23 
24 #include <memory>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 namespace gtsam {
30 
31 class DiscreteBayesNet;
32 
40 class GTSAM_EXPORT DiscreteLookupTable : public DiscreteConditional {
41  public:
43  using shared_ptr = std::shared_ptr<This>;
45 
53  DiscreteLookupTable(size_t nFrontals, const DiscreteKeys& keys,
54  const ADT& potentials)
55  : DiscreteConditional(nFrontals, keys, potentials) {}
56 
58  void print(
59  const std::string& s = "Discrete Lookup Table: ",
60  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
61 
67  size_t argmax(const DiscreteValues& parentsValues) const;
68 
73  void argmaxInPlace(DiscreteValues* parentsValues) const;
74 };
75 
77 class GTSAM_EXPORT DiscreteLookupDAG : public BayesNet<DiscreteLookupTable> {
78  public:
81  using shared_ptr = std::shared_ptr<This>;
82 
85 
88 
90  static DiscreteLookupDAG FromBayesNet(const DiscreteBayesNet& bayesNet);
91 
93 
96 
98  bool equals(const This& bn, double tol = 1e-9) const;
99 
101 
104 
106  template <typename... Args>
107  void add(Args&&... args) {
108  emplace_shared<DiscreteLookupTable>(std::forward<Args>(args)...);
109  }
110 
122  DiscreteValues argmax(DiscreteValues given = DiscreteValues()) const;
124 
125  private:
126 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
127 
128  friend class boost::serialization::access;
129  template <class ARCHIVE>
130  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
131  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
132  }
133 #endif
134 };
135 
136 // traits
137 template <>
138 struct traits<DiscreteLookupDAG> : public Testable<DiscreteLookupDAG> {};
139 
140 } // namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
DiscreteLookupDAG()
Construct empty DAG.
std::string serialize(const T &input)
serializes to a string
Definition: pytypes.h:2012
Bayes network.
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
DiscreteLookupTable(size_t nFrontals, const DiscreteKeys &keys, const ADT &potentials)
Construct a new Discrete Lookup Table object.
DiscreteLookupTable table for max-productInherits from discrete conditional for convenience, but is not normalized. Is used in the max-product algorithm.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
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
traits
Definition: chartTesting.h:28
std::shared_ptr< DecisionTreeFactor > shared_ptr
Factor Graph Base Class.
const G double tol
Definition: Group.h:86
const KeyVector keys
std::shared_ptr< This > shared_ptr
void add(Args &&... args)
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:10