GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
DiscreteMarginals.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 
21 #pragma once
22 
25 #include <gtsam/base/Vector.h>
26 
27 namespace gtsam {
28 
34 
35  protected:
36 
37  DiscreteBayesTree::shared_ptr bayesTree_;
38 
39  public:
40 
42 
47  bayesTree_ = graph.eliminateMultifrontal();
48  }
49 
52  // Compute marginal
53  DiscreteFactor::shared_ptr marginalFactor;
54  marginalFactor = bayesTree_->marginalFactor(variable, &EliminateDiscrete);
55  return marginalFactor;
56  }
57 
62  Vector marginalProbabilities(const DiscreteKey& key) const {
63  // Compute marginal
64  DiscreteFactor::shared_ptr marginalFactor;
65  marginalFactor = bayesTree_->marginalFactor(key.first, &EliminateDiscrete);
66 
67  //Create result
68  Vector vResult(key.second);
69  for (size_t state = 0; state < key.second ; ++ state) {
70  DiscreteValues values;
71  values[key.first] = state;
72  vResult(state) = (*marginalFactor)(values);
73  }
74  return vResult;
75  }
76 
77  };
78 
79 } /* namespace gtsam */
DiscreteFactor::shared_ptr operator()(Key variable) const
Definition: DiscreteMarginals.h:51
DiscreteMarginals(const DiscreteFactorGraph &graph)
Definition: DiscreteMarginals.h:46
Vector marginalProbabilities(const DiscreteKey &key) const
Definition: DiscreteMarginals.h:62
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
Definition: DiscreteValues.h:34
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:44
Definition: DiscreteMarginals.h:33
Definition: chartTesting.h:28
typedef and functions to augment Eigen&#39;s VectorXd
Definition: DiscreteFactorGraph.h:83
GTSAM_EXPORT std::pair< std::shared_ptr< DiscreteConditional >, DecisionTreeFactor::shared_ptr > EliminateDiscrete(const DiscreteFactorGraph &factors, const Ordering &keys)
Main elimination function for DiscreteFactorGraph.
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
std::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
Definition: EliminateableFactorGraph-inst.h:88
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102