gtsam  4.1.0
gtsam
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 
33 
34  protected:
35 
36  DiscreteBayesTree::shared_ptr bayesTree_;
37 
38  public:
39 
44  bayesTree_ = graph.eliminateMultifrontal();
45  }
46 
49  // Compute marginal
50  DiscreteFactor::shared_ptr marginalFactor;
51  marginalFactor = bayesTree_->marginalFactor(variable, &EliminateDiscrete);
52  return marginalFactor;
53  }
54 
59  Vector marginalProbabilities(const DiscreteKey& key) const {
60  // Compute marginal
61  DiscreteFactor::shared_ptr marginalFactor;
62  marginalFactor = bayesTree_->marginalFactor(key.first, &EliminateDiscrete);
63 
64  //Create result
65  Vector vResult(key.second);
66  for (size_t state = 0; state < key.second ; ++ state) {
68  values[key.first] = state;
69  vResult(state) = (*marginalFactor)(values);
70  }
71  return vResult;
72  }
73 
74  };
75 
76 } /* namespace gtsam */
gtsam::EliminateDiscrete
std::pair< DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr > EliminateDiscrete(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Main elimination function for DiscreteFactorGraph.
Definition: DiscreteFactorGraph.cpp:105
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Key type for discrete conditionals Includes name and cardinality.
Definition: DiscreteKey.h:34
gtsam::Assignment
An assignment from labels to value index (size_t).
Definition: Assignment.h:34
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
gtsam
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
gtsam::DiscreteMarginals
A class for computing marginals of variables in a DiscreteFactorGraph.
Definition: DiscreteMarginals.h:32
gtsam::DiscreteMarginals::operator()
DiscreteFactor::shared_ptr operator()(Key variable) const
Compute the marginal of a single variable.
Definition: DiscreteMarginals.h:48
Vector.h
typedef and functions to augment Eigen's VectorXd
DiscreteBayesTree.h
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
gtsam::DiscreteMarginals::marginalProbabilities
Vector marginalProbabilities(const DiscreteKey &key) const
Compute the marginal of a single variable.
Definition: DiscreteMarginals.h:59
gtsam::DiscreteFactorGraph
A Discrete Factor Graph is a factor graph where all factors are Discrete, i.e.
Definition: DiscreteFactorGraph.h:66
DiscreteFactorGraph.h
gtsam::DiscreteMarginals::DiscreteMarginals
DiscreteMarginals(const DiscreteFactorGraph &graph)
Construct a marginals class.
Definition: DiscreteMarginals.h:43
gtsam::DiscreteFactor::shared_ptr
boost::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:40