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