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 
24 
25 #include <memory>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace gtsam {
31 
32 class DiscreteBayesNet;
33 
41 class GTSAM_EXPORT DiscreteLookupTable : public DiscreteConditional {
42  public:
44  using shared_ptr = std::shared_ptr<This>;
46 
54  DiscreteLookupTable(size_t nFrontals, const DiscreteKeys& keys,
55  const ADT& potentials)
56  : DiscreteConditional(nFrontals, keys, potentials) {}
57 
65  DiscreteLookupTable(size_t nFrontals, const DiscreteKeys& keys,
66  const TableFactor& potentials)
67  : DiscreteConditional(nFrontals, keys,
68  potentials.toDecisionTreeFactor()) {}
69 
71  void print(
72  const std::string& s = "Discrete Lookup Table: ",
73  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
74 
80  size_t argmax(const DiscreteValues& parentsValues) const;
81 
86  void argmaxInPlace(DiscreteValues* parentsValues) const;
87 };
88 
90 class GTSAM_EXPORT DiscreteLookupDAG : public BayesNet<DiscreteLookupTable> {
91  public:
94  using shared_ptr = std::shared_ptr<This>;
95 
98 
101 
103  static DiscreteLookupDAG FromBayesNet(const DiscreteBayesNet& bayesNet);
104 
106 
109 
111  bool equals(const This& bn, double tol = 1e-9) const;
112 
114 
117 
119  template <typename... Args>
120  void add(Args&&... args) {
121  emplace_shared<DiscreteLookupTable>(std::forward<Args>(args)...);
122  }
123 
135  DiscreteValues argmax(DiscreteValues given = DiscreteValues()) const;
137 
138  private:
139 #if GTSAM_ENABLE_BOOST_SERIALIZATION
140 
141  friend class boost::serialization::access;
142  template <class ARCHIVE>
143  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
144  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
145  }
146 #endif
147 };
148 
149 // traits
150 template <>
151 struct traits<DiscreteLookupDAG> : public Testable<DiscreteLookupDAG> {};
152 
153 } // namespace gtsam
gtsam::TableFactor
Definition: TableFactor.h:54
gtsam::DiscreteLookupTable::DiscreteLookupTable
DiscreteLookupTable(size_t nFrontals, const DiscreteKeys &keys, const ADT &potentials)
Construct a new Discrete Lookup Table object.
Definition: DiscreteLookupDAG.h:54
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:45
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:120
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::DiscreteLookupDAG
Definition: DiscreteLookupDAG.h:90
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:51
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:156
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.
TableFactor.h
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::DiscreteLookupTable::DiscreteLookupTable
DiscreteLookupTable(size_t nFrontals, const DiscreteKeys &keys, const TableFactor &potentials)
Construct a new Discrete Lookup Table object.
Definition: DiscreteLookupDAG.h:65
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:41
This
#define This
Definition: ActiveSetSolver-inl.h:27
gtsam::DiscreteLookupDAG::DiscreteLookupDAG
DiscreteLookupDAG()
Construct empty DAG.
Definition: DiscreteLookupDAG.h:100
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::DiscreteLookupDAG::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: DiscreteLookupDAG.h:94
Base
Definition: test_virtual_functions.cpp:156


gtsam
Author(s):
autogenerated on Tue Jan 7 2025 04:02:11