Loading...
Searching...
No Matches
DiscreteMarginals.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/discrete/DiscreteFactorGraph.h>
#include <gtsam/discrete/DiscreteBayesTree.h>
#include <gtsam/base/Vector.h>
namespace gtsam {
class DiscreteMarginals {
protected:
DiscreteBayesTree::shared_ptr bayesTree_;
public:
DiscreteMarginals() {}
DiscreteMarginals(const DiscreteFactorGraph& graph) {
bayesTree_ = graph.eliminateMultifrontal();
}
DiscreteFactor::shared_ptr operator()(Key variable) const {
// Compute marginal
DiscreteFactor::shared_ptr marginalFactor;
marginalFactor = bayesTree_->marginalFactor(variable, &EliminateDiscrete);
return marginalFactor;
}
Vector marginalProbabilities(const DiscreteKey& key) const {
// Compute marginal
DiscreteFactor::shared_ptr marginalFactor;
marginalFactor = bayesTree_->marginalFactor(key.first, &EliminateDiscrete);
//Create result
Vector vResult(key.second);
for (size_t state = 0; state < key.second ; ++ state) {
DiscreteValues values;
values[key.first] = state;
vResult(state) = (*marginalFactor)(values);
}
return vResult;
}
};
} /* namespace gtsam */
Vector.h
typedef and functions to augment Eigen's VectorXd
DiscreteBayesTree.h
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
DiscreteFactorGraph.h
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:36
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:200
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
gtsam::DiscreteFactor::shared_ptr
boost::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition DiscreteFactor.h:44
gtsam::DiscreteFactorGraph
A Discrete Factor Graph is a factor graph where all factors are Discrete, i.e.
Definition DiscreteFactorGraph.h:101
gtsam::DiscreteMarginals::marginalProbabilities
Vector marginalProbabilities(const DiscreteKey &key) const
Compute the marginal of a single variable.
Definition DiscreteMarginals.h:62
gtsam::DiscreteMarginals::DiscreteMarginals
DiscreteMarginals(const DiscreteFactorGraph &graph)
Construct a marginals class.
Definition DiscreteMarginals.h:46
gtsam::DiscreteMarginals::operator()
DiscreteFactor::shared_ptr operator()(Key variable) const
Compute the marginal of a single variable.
Definition DiscreteMarginals.h:51
gtsam::DiscreteValues
A map from keys to values.
Definition DiscreteValues.h:34
gtsam::EliminateableFactorGraph::eliminateMultifrontal
boost::shared_ptr< BayesTreeType > eliminateMultifrontal(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Do multifrontal elimination of all variables to produce a Bayes tree.
Definition EliminateableFactorGraph-inst.h:91