gtsam 4.2.0
gtsam
Loading...
Searching...
No Matches
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
27namespace 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 */
typedef and functions to augment Eigen's VectorXd
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
std::pair< DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr > EliminateDiscrete(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Main elimination function for DiscreteFactorGraph.
Definition DiscreteFactorGraph.cpp:200
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:36
Global functions in a separate testing namespace.
Definition chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
boost::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition DiscreteFactor.h:44
A Discrete Factor Graph is a factor graph where all factors are Discrete, i.e.
Definition DiscreteFactorGraph.h:86
A class for computing marginals of variables in a DiscreteFactorGraph.
Definition DiscreteMarginals.h:33
Vector marginalProbabilities(const DiscreteKey &key) const
Compute the marginal of a single variable.
Definition DiscreteMarginals.h:62
DiscreteMarginals(const DiscreteFactorGraph &graph)
Construct a marginals class.
Definition DiscreteMarginals.h:46
DiscreteFactor::shared_ptr operator()(Key variable) const
Compute the marginal of a single variable.
Definition DiscreteMarginals.h:51
A map from keys to values.
Definition DiscreteValues.h:34