gtsam
Loading...
Searching...
No Matches
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
17
18#pragma once
19
24
25#include <memory>
26#include <string>
27#include <utility>
28#include <vector>
29
30namespace gtsam {
31
33
41class GTSAM_EXPORT DiscreteLookupTable : public DiscreteConditional {
42 public:
43 using This = DiscreteLookupTable;
44 using shared_ptr = std::shared_ptr<This>;
45 using BaseConditional = Conditional<DecisionTreeFactor, 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
90class GTSAM_EXPORT DiscreteLookupDAG : public BayesNet<DiscreteLookupTable> {
91 public:
93 using This = DiscreteLookupDAG;
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
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
150template <>
151struct traits<DiscreteLookupDAG> : public Testable<DiscreteLookupDAG> {};
152
153} // namespace gtsam
Factor Graph Base Class.
Bayes network.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
DecisionTreeFactor toDecisionTreeFactor() const override
Convert into a decision tree.
Definition DecisionTreeFactor.h:194
A Bayes net made from discrete conditional distributions.
Definition DiscreteBayesNet.h:38
DiscreteConditional()
Default constructor needed for serialization.
Definition DiscreteConditional.h:55
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:41
DiscreteLookupTable(size_t nFrontals, const DiscreteKeys &keys, const ADT &potentials)
Construct a new Discrete Lookup Table object.
Definition DiscreteLookupDAG.h:54
DiscreteLookupTable(size_t nFrontals, const DiscreteKeys &keys, const TableFactor &potentials)
Construct a new Discrete Lookup Table object.
Definition DiscreteLookupDAG.h:65
A DAG made from lookup tables, as defined above.
Definition DiscreteLookupDAG.h:90
bool equals(const This &bn, double tol=1e-9) const
Check equality.
DiscreteLookupDAG()
Construct empty DAG.
Definition DiscreteLookupDAG.h:100
void add(Args &&... args)
Add a DiscreteLookupTable.
Definition DiscreteLookupDAG.h:120
A map from keys to values.
Definition DiscreteValues.h:34
A discrete probabilistic factor optimized for sparsity.
Definition TableFactor.h:51
BayesNet()
Definition BayesNet.h:48
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition FactorGraph.h:153
Definition Conditional.h:64
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143