Potentials.cpp
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 
20 
21 #include <boost/format.hpp>
22 
23 #include <string>
24 
25 using namespace std;
26 
27 namespace gtsam {
28 
29 // explicit instantiation
30 template class DecisionTree<Key, double>;
31 template class AlgebraicDecisionTree<Key>;
32 
33 /* ************************************************************************* */
34 double Potentials::safe_div(const double& a, const double& b) {
35  // cout << boost::format("%g / %g = %g\n") % a % b % ((a == 0) ? 0 : (a / b));
36  // The use for safe_div is when we divide the product factor by the sum
37  // factor. If the product or sum is zero, we accord zero probability to the
38  // event.
39  return (a == 0 || b == 0) ? 0 : (a / b);
40 }
41 
42 /* ********************************************************************************
43  */
44 Potentials::Potentials() : ADT(1.0) {}
45 
46 /* ********************************************************************************
47  */
48 Potentials::Potentials(const DiscreteKeys& keys, const ADT& decisionTree)
49  : ADT(decisionTree), cardinalities_(keys.cardinalities()) {}
50 
51 /* ************************************************************************* */
52 bool Potentials::equals(const Potentials& other, double tol) const {
53  return ADT::equals(other, tol);
54 }
55 
56 /* ************************************************************************* */
57 void Potentials::print(const string& s, const KeyFormatter& formatter) const {
58  cout << s << "\n Cardinalities: {";
59  for (const std::pair<const Key,size_t>& key : cardinalities_)
60  cout << formatter(key.first) << ":" << key.second << ", ";
61  cout << "}" << endl;
62  ADT::print(" ");
63 }
64 //
65 // /* ************************************************************************* */
66 // template<class P>
67 // void Potentials::remapIndices(const P& remapping) {
68 // // Permute the _cardinalities (TODO: Inefficient Consider Improving)
69 // DiscreteKeys keys;
70 // map<Key, Key> ordering;
71 //
72 // // Get the original keys from cardinalities_
73 // for(const DiscreteKey& key: cardinalities_)
74 // keys & key;
75 //
76 // // Perform Permutation
77 // for(DiscreteKey& key: keys) {
78 // ordering[key.first] = remapping[key.first];
79 // key.first = ordering[key.first];
80 // }
81 //
82 // // Change *this
83 // AlgebraicDecisionTree<Key> permuted((*this), ordering);
84 // *this = permuted;
85 // cardinalities_ = keys.cardinalities();
86 // }
87 //
88 // /* ************************************************************************* */
89 // void Potentials::permuteWithInverse(const Permutation& inversePermutation) {
90 // remapIndices(inversePermutation);
91 // }
92 //
93 // /* ************************************************************************* */
94 // void Potentials::reduceWithInverse(const internal::Reduction& inverseReduction) {
95 // remapIndices(inverseReduction);
96 // }
97 
98  /* ************************************************************************* */
99 
100 } // namespace gtsam
Scalar * b
Definition: benchVecAdd.cpp:17
bool equals(const DecisionTree &other, double tol=1e-9) const
Definition: Half.h:150
const KeyFormatter & formatter
Array33i a
void print(const std::string &s="DecisionTree") const
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
GTSAM_EXPORT bool equals(const Potentials &other, double tol=1e-9) const
Definition: Potentials.cpp:52
RealScalar s
traits
Definition: chartTesting.h:28
GTSAM_EXPORT void print(const std::string &s="Potentials: ", const KeyFormatter &formatter=DefaultKeyFormatter) const
Definition: Potentials.cpp:57
std::map< Key, size_t > cardinalities_
Cardinality for each key, used in combine.
Definition: Potentials.h:41
const G double tol
Definition: Group.h:83
const KeyVector keys
GTSAM_EXPORT Potentials()
Definition: Potentials.cpp:44
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:37


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:28