DiscreteConditional.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 
19 #pragma once
20 
24 #include <boost/shared_ptr.hpp>
25 #include <boost/make_shared.hpp>
26 
27 #include <string>
28 
29 namespace gtsam {
30 
35 class GTSAM_EXPORT DiscreteConditional: public DecisionTreeFactor,
36  public Conditional<DecisionTreeFactor, DiscreteConditional> {
37 
38 public:
39  // typedefs needed to play nice with gtsam
41  typedef boost::shared_ptr<This> shared_ptr;
44 
48  typedef boost::shared_ptr<Values> sharedValues;
49 
52 
55  }
56 
58  DiscreteConditional(size_t nFrontals, const DecisionTreeFactor& f);
59 
61  DiscreteConditional(const Signature& signature);
62 
65  const DecisionTreeFactor& marginal);
66 
69  const DecisionTreeFactor& marginal, const Ordering& orderedKeys);
70 
78  template<typename ITERATOR>
79  static shared_ptr Combine(ITERATOR firstConditional,
80  ITERATOR lastConditional);
81 
85 
87  void print(const std::string& s = "Discrete Conditional: ",
88  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
89 
91  bool equals(const DiscreteFactor& other, double tol = 1e-9) const override;
92 
96 
99  const std::string& s = "Discrete Conditional: ",
100  const KeyFormatter& formatter = DefaultKeyFormatter) const {
101  static_cast<const BaseConditional*>(this)->print(s, formatter);
102  }
103 
105  double operator()(const Values& values) const override {
106  return Potentials::operator()(values);
107  }
108 
112  }
113 
115  ADT choose(const Assignment<Key>& parentsValues) const;
116 
122  size_t solve(const Values& parentsValues) const;
123 
129  size_t sample(const Values& parentsValues) const;
130 
134 
136  void solveInPlace(Values& parentsValues) const;
137 
139  void sampleInPlace(Values& parentsValues) const;
140 
142 
143 };
144 // DiscreteConditional
145 
146 // traits
147 template<> struct traits<DiscreteConditional> : public Testable<DiscreteConditional> {};
148 
149 /* ************************************************************************* */
150 template<typename ITERATOR>
152  ITERATOR firstConditional, ITERATOR lastConditional) {
153  // TODO: check for being a clique
154 
155  // multiply all the potentials of the given conditionals
156  size_t nrFrontals = 0;
158  for (ITERATOR it = firstConditional; it != lastConditional;
159  ++it, ++nrFrontals) {
161  DecisionTreeFactor::shared_ptr factor = c->toFactor();
162  product = (*factor) * product;
163  }
164  // and then create a new multi-frontal conditional
165  return boost::make_shared<DiscreteConditional>(nrFrontals, product);
166 }
167 
168 } // gtsam
169 
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
Base class for conditional densities.
static shared_ptr Combine(ITERATOR firstConditional, ITERATOR lastConditional)
DecisionTreeFactor::shared_ptr toFactor() const
Conditional< BaseFactor, This > BaseConditional
Typedef to our conditional base class.
DiscreteConditional This
Typedef to this class.
signatures for conditional densities
boost::shared_ptr< Values > sharedValues
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1 & choose(Cond< true >, const T1 &first, const T2 &)
Definition: TensorMeta.h:18
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
leaf::MyValues values
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
double operator()(const Values &values) const override
Evaluate, just look up in AlgebraicDecisonTree.
const KeyFormatter & formatter
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
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
DecisionTreeFactor BaseFactor
Typedef to our factor base class.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
void printSignature(const std::string &s="Discrete Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const
print index signature only
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
traits
Definition: chartTesting.h:28
const double & operator()(const Assignment< Key > &x) const
boost::shared_ptr< DecisionTreeFactor > shared_ptr
const G double tol
Definition: Group.h:83
void product(const MatrixType &m)
Definition: product.h:20


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:59