gtsam  4.0.0
gtsam
Potentials.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 
22 #include <gtsam/inference/Key.h>
23 
24 #include <boost/shared_ptr.hpp>
25 #include <set>
26 
27 namespace gtsam {
28 
32  class Potentials: public AlgebraicDecisionTree<Key> {
33 
34  public:
35 
37 
38  protected:
39 
41  std::map<Key,size_t> cardinalities_;
42 
44  Potentials(const ADT& potentials) :
45  ADT(potentials) {
46  }
47 
48  // Safe division for probabilities
49  GTSAM_EXPORT static double safe_div(const double& a, const double& b);
50 
51 // // Apply either a permutation or a reduction
52 // template<class P>
53 // void remapIndices(const P& remapping);
54 
55  public:
56 
58  GTSAM_EXPORT Potentials();
59 
61  GTSAM_EXPORT Potentials(const DiscreteKeys& keys, const ADT& decisionTree);
62 
64  template<class SOURCE>
65  Potentials(const DiscreteKeys& keys, SOURCE table) :
66  ADT(keys, table), cardinalities_(keys.cardinalities()) {
67  }
68 
69  // Testable
70  GTSAM_EXPORT bool equals(const Potentials& other, double tol = 1e-9) const;
71  GTSAM_EXPORT void print(const std::string& s = "Potentials: ",
72  const KeyFormatter& formatter = DefaultKeyFormatter) const;
73 
74  size_t cardinality(Key j) const { return cardinalities_.at(j);}
75 
76 // /**
77 // * @brief Permutes the keys in Potentials
78 // *
79 // * This permutes the Indices and performs necessary re-ordering of ADD.
80 // * This is virtual so that derived types e.g. DecisionTreeFactor can
81 // * re-implement it.
82 // */
83 // GTSAM_EXPORT virtual void permuteWithInverse(const Permutation& inversePermutation);
84 //
85 // /**
86 // * Apply a reduction, which is a remapping of variable indices.
87 // */
88 // GTSAM_EXPORT virtual void reduceWithInverse(const internal::Reduction& inverseReduction);
89 
90  }; // Potentials
91 
92 // traits
93 template<> struct traits<Potentials> : public Testable<Potentials> {};
94 template<> struct traits<Potentials::ADT> : public Testable<Potentials::ADT> {};
95 
96 
97 } // namespace gtsam
specialized key for discrete variables
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
A base class for both DiscreteFactor and DiscreteConditional.
Definition: Potentials.h:32
Algebraic Decision Trees fix the range to double Just has some nice constructors and some syntactic s...
Definition: AlgebraicDecisionTree.h:31
Template to create a binary predicate.
Definition: Testable.h:110
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Potentials(const ADT &potentials)
Constructor from ColumnIndex, and ADT.
Definition: Potentials.h:44
Potentials(const DiscreteKeys &keys, SOURCE table)
Constructor from Indices and (string or doubles)
Definition: Potentials.h:65
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Algebraic Decision Trees.
std::map< Key, size_t > cardinalities_
Cardinality for each key, used in combine.
Definition: Potentials.h:41
GTSAM_EXPORT Potentials()
Default constructor for I/O.
Definition: Potentials.cpp:39
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:37