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
gtsam::DiscreteLookupTable::DiscreteLookupTable
DiscreteLookupTable(size_t nFrontals, const DiscreteKeys &keys, const ADT &potentials)
Construct a new Discrete Lookup Table object.
Definition: DiscreteLookupDAG.h:53
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:44
gtsam::BayesNet
Definition: BayesNet.h:35
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::DiscreteLookupDAG::add
void add(Args &&... args)
Definition: DiscreteLookupDAG.h:107
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::DiscreteLookupDAG
Definition: DiscreteLookupDAG.h:77
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
gtsam::DecisionTreeFactor::shared_ptr
std::shared_ptr< DecisionTreeFactor > shared_ptr
Definition: DecisionTreeFactor.h:50
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::AlgebraicDecisionTree< Key >
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
different_sigmas::bayesNet
const HybridBayesNet bayesNet
Definition: testHybridBayesNet.cpp:242
gtsam::DiscreteBayesNet
Definition: DiscreteBayesNet.h:38
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::Conditional
Definition: Conditional.h:63
BayesNet.h
Bayes network.
gtsam::equals
Definition: Testable.h:112
gtsam::DiscreteConditional
Definition: DiscreteConditional.h:37
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
FactorGraph.h
Factor Graph Base Class.
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
DiscreteDistribution.h
args
Definition: pytypes.h:2210
gtsam::DiscreteLookupTable
DiscreteLookupTable table for max-product.
Definition: DiscreteLookupDAG.h:40
This
#define This
Definition: ActiveSetSolver-inl.h:27
gtsam::DiscreteLookupDAG::DiscreteLookupDAG
DiscreteLookupDAG()
Construct empty DAG.
Definition: DiscreteLookupDAG.h:87
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::DiscreteLookupDAG::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: DiscreteLookupDAG.h:81
Base
Definition: test_virtual_functions.cpp:156


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:32:26