gtsam 4.2.0
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
18#pragma once
19
23
24#include <boost/shared_ptr.hpp>
25#include <string>
26#include <utility>
27#include <vector>
28
29namespace gtsam {
30
31class DiscreteBayesNet;
32
40class GTSAM_EXPORT DiscreteLookupTable : public DiscreteConditional {
41 public:
43 using shared_ptr = boost::shared_ptr<This>;
44 using BaseConditional = Conditional<DecisionTreeFactor, 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
77class GTSAM_EXPORT DiscreteLookupDAG : public BayesNet<DiscreteLookupTable> {
78 public:
80 using This = DiscreteLookupDAG;
81 using shared_ptr = boost::shared_ptr<This>;
82
85
88
90 static DiscreteLookupDAG FromBayesNet(const DiscreteBayesNet& bayesNet);
91
93 virtual ~DiscreteLookupDAG() {}
94
96
99
101 bool equals(const This& bn, double tol = 1e-9) const;
102
104
107
109 template <typename... Args>
110 void add(Args&&... args) {
111 emplace_shared<DiscreteLookupTable>(std::forward<Args>(args)...);
112 }
113
125 DiscreteValues argmax(DiscreteValues given = DiscreteValues()) const;
127
128 private:
130 friend class boost::serialization::access;
131 template <class ARCHIVE>
132 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
133 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
134 }
135};
136
137// traits
138template <>
139struct traits<DiscreteLookupDAG> : public Testable<DiscreteLookupDAG> {};
140
141} // namespace gtsam
Bayes network.
Factor Graph Base Class.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
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 concepts.h:30
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
A Bayes net made from discrete conditional distributions.
Definition DiscreteBayesNet.h:38
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition DiscreteConditional.h:40
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:39
DiscreteLookupTable table for max-product.
Definition DiscreteLookupDAG.h:40
DiscreteLookupTable(size_t nFrontals, const DiscreteKeys &keys, const ADT &potentials)
Construct a new Discrete Lookup Table object.
Definition DiscreteLookupDAG.h:53
A DAG made from lookup tables, as defined above.
Definition DiscreteLookupDAG.h:77
bool equals(const This &bn, double tol=1e-9) const
Check equality.
DiscreteLookupDAG()
Construct empty DAG.
Definition DiscreteLookupDAG.h:87
void add(Args &&... args)
Add a DiscreteLookupTable.
Definition DiscreteLookupDAG.h:110
virtual ~DiscreteLookupDAG()
Destructor.
Definition DiscreteLookupDAG.h:93
A map from keys to values.
Definition DiscreteValues.h:34
A BayesNet is a tree of conditionals, stored in elimination order.
Definition BayesNet.h:35
Definition Conditional.h:64