45 typedef std::shared_ptr<DiscreteFactor>
51 using Unary = std::function<double(
const double&)>;
52 using UnaryAssignment =
54 using Binary = std::function<double(
const double,
const double)>;
72 template <
typename CONTAINER>
74 const std::map<Key, size_t> cardinalities = {})
75 : Base(keys), cardinalities_(cardinalities) {}
82 virtual bool equals(
const DiscreteFactor& lf,
double tol = 1e-9)
const;
86 const std::string& s =
"DiscreteFactor\n",
98 std::map<Key, size_t> cardinalities()
const {
return cardinalities_; }
100 size_t cardinality(Key j)
const {
return cardinalities_.at(j); }
128 virtual AlgebraicDecisionTree<Key> errorTree()
const;
163 virtual double max()
const = 0;
205 const Names& names = {})
const = 0;
216 const Names& names = {})
const = 0;
221#if GTSAM_ENABLE_BOOST_SERIALIZATION
223 friend class boost::serialization::access;
224 template <
class ARCHIVE>
225 void serialize(ARCHIVE& ar,
const unsigned int ) {
226 ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
227 ar& BOOST_SERIALIZATION_NVP(cardinalities_);
Concept check for values that can be used in unit tests.
Algebraic Decision Trees.
The base class for all factors.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
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
An assignment from labels to value index (size_t).
Definition Assignment.h:37
A discrete probabilistic factor.
Definition DecisionTreeFactor.h:42
virtual DiscreteFactor::shared_ptr multiply(const DiscreteFactor::shared_ptr &f) const override
Multiply factors, DiscreteFactor::shared_ptr edition.
Definition DecisionTreeFactor.cpp:68
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition DiscreteConditional.h:40
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition DiscreteFactor.h:41
virtual DiscreteFactor::shared_ptr sum(const Ordering &keys) const =0
Create new factor by summing all values with the same separator values.
virtual std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const =0
Render as html table.
Factor Base
Our base class.
Definition DiscreteFactor.h:47
void print(const std::string &s="DiscreteFactor\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition DiscreteFactor.h:85
virtual DiscreteFactor::shared_ptr operator*(double s) const =0
Multiply with a scalar.
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition DiscreteFactor.h:46
virtual double max() const =0
Find the maximum value in the factor.
DiscreteFactor(const CONTAINER &keys, const std::map< Key, size_t > cardinalities={})
Construct from container of keys and map of cardinalities.
Definition DiscreteFactor.h:73
virtual DiscreteFactor::shared_ptr operator/(const DiscreteFactor::shared_ptr &df) const =0
divide by DiscreteFactor::shared_ptr f (safely)
DiscreteFactor::shared_ptr scale() const
Scale the factor values by the maximum to prevent underflow/overflow.
Definition DiscreteFactor.cpp:95
DiscreteValues Values
backwards compatibility
Definition DiscreteFactor.h:49
virtual DiscreteFactor::shared_ptr max(size_t nrFrontals) const =0
Create new factor by maximizing over all values with the same separator.
virtual double evaluate(const Assignment< Key > &values) const =0
Calculate probability for given values.
virtual DiscreteFactor::shared_ptr restrict(const DiscreteValues &assignment) const =0
Restrict the factor to the given assignment.
std::map< Key, size_t > cardinalities_
Map of Keys and their cardinalities.
Definition DiscreteFactor.h:58
virtual DiscreteFactor::shared_ptr sum(size_t nrFrontals) const =0
Create new factor by summing all values with the same separator values.
virtual TableFactor toTableFactor() const
Convert to a sparse table, falling back through a decision tree.
Definition DiscreteFactor.cpp:90
DiscreteValues::Names Names
Translation table from values to strings.
Definition DiscreteFactor.h:194
double operator()(const DiscreteValues &values) const
Find value for given assignment of values to variables.
Definition DiscreteFactor.h:114
DiscreteFactor This
This class.
Definition DiscreteFactor.h:44
virtual DecisionTreeFactor operator*(const DecisionTreeFactor &) const =0
Multiply in a DecisionTreeFactor and return the result as DecisionTreeFactor.
virtual DiscreteFactor::shared_ptr max(const Ordering &keys) const =0
Create new factor by maximizing over all values with the same separator.
virtual std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const =0
Render as markdown table.
virtual uint64_t nrValues() const =0
Get the number of non-zero values contained in this factor.
DiscreteFactor()
Default constructor creates empty factor.
Definition DiscreteFactor.h:65
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:41
A map from keys to values.
Definition DiscreteValues.h:34
std::map< Key, std::vector< std::string > > Names
Translation table from values to strings.
Definition DiscreteValues.h:167
A discrete probabilistic factor optimized for sparsity.
Definition TableFactor.h:51
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:37
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143
Factor()
Default constructor for I/O.
Definition Factor.h:94
virtual void print(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print
Definition Factor.cpp:29