Loading...
Searching...
No Matches
DiscreteFactorGraph.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/DecisionTreeFactor.h>
#include <gtsam/discrete/DiscreteLookupDAG.h>
#include <gtsam/inference/EliminateableFactorGraph.h>
#include <gtsam/inference/FactorGraph.h>
#include <gtsam/inference/Ordering.h>
#include <gtsam/base/FastSet.h>
#include <boost/make_shared.hpp>
#include <string>
#include <utility>
#include <vector>
namespace gtsam {
// Forward declarations
class DiscreteFactorGraph;
class DiscreteConditional;
class DiscreteBayesNet;
class DiscreteEliminationTree;
class DiscreteBayesTree;
class DiscreteJunctionTree;
GTSAM_EXPORT
std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr>
EliminateDiscrete(const DiscreteFactorGraph& factors,
const Ordering& frontalKeys);
GTSAM_EXPORT
std::pair<DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr>
EliminateForMPE(const DiscreteFactorGraph& factors,
const Ordering& frontalKeys);
template<> struct EliminationTraits<DiscreteFactorGraph>
{
typedef DiscreteFactor FactorType;
typedef DiscreteFactorGraph FactorGraphType;
typedef DiscreteConditional ConditionalType;
typedef DiscreteBayesNet BayesNetType;
typedef DiscreteEliminationTree EliminationTreeType;
typedef DiscreteBayesTree BayesTreeType;
typedef DiscreteJunctionTree JunctionTreeType;
static std::pair<boost::shared_ptr<ConditionalType>,
boost::shared_ptr<FactorType> >
DefaultEliminate(const FactorGraphType& factors, const Ordering& keys) {
return EliminateDiscrete(factors, keys);
}
static Ordering DefaultOrderingFunc(
const FactorGraphType& graph,
boost::optional<const VariableIndex&> variableIndex) {
return Ordering::Colamd(*variableIndex);
}
};
class GTSAM_EXPORT DiscreteFactorGraph
: public FactorGraph<DiscreteFactor>,
public EliminateableFactorGraph<DiscreteFactorGraph> {
public:
using This = DiscreteFactorGraph;
using Base = FactorGraph<DiscreteFactor>;
using BaseEliminateable =
EliminateableFactorGraph<This>;
using shared_ptr = boost::shared_ptr<This>;
using Values = DiscreteValues;
using Indices = KeyVector;
DiscreteFactorGraph() {}
template <typename ITERATOR>
DiscreteFactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
: Base(firstFactor, lastFactor) {}
template <class CONTAINER>
explicit DiscreteFactorGraph(const CONTAINER& factors) : Base(factors) {}
template <class DERIVED_FACTOR>
DiscreteFactorGraph(const FactorGraph<DERIVED_FACTOR>& graph) : Base(graph) {}
virtual ~DiscreteFactorGraph() {}
bool equals(const This& fg, double tol = 1e-9) const;
template <typename... Args>
void add(Args&&... args) {
emplace_shared<DecisionTreeFactor>(std::forward<Args>(args)...);
}
KeySet keys() const;
DiscreteKeys discreteKeys() const;
DecisionTreeFactor product() const;
double operator()(const DiscreteValues& values) const;
void print(
const std::string& s = "DiscreteFactorGraph",
const KeyFormatter& formatter = DefaultKeyFormatter) const override;
DiscreteBayesNet sumProduct(
OptionalOrderingType orderingType = boost::none) const;
DiscreteBayesNet sumProduct(const Ordering& ordering) const;
DiscreteLookupDAG maxProduct(
OptionalOrderingType orderingType = boost::none) const;
DiscreteLookupDAG maxProduct(const Ordering& ordering) const;
DiscreteValues optimize(
OptionalOrderingType orderingType = boost::none) const;
DiscreteValues optimize(const Ordering& ordering) const;
std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DiscreteFactor::Names& names = {}) const;
std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DiscreteFactor::Names& names = {}) const;
using Base::error; // Expose error(const HybridValues&) method..
}; // \ DiscreteFactorGraph
template <>
struct traits<DiscreteFactorGraph> : public Testable<DiscreteFactorGraph> {};
} // namespace gtsam
FastSet.h
A thin wrapper around std::set that uses boost's fast_pool_allocator.
DiscreteLookupDAG.h
DecisionTreeFactor.h
Ordering.h
Variable ordering for the elimination algorithm.
FactorGraph.h
Factor Graph Base Class.
EliminateableFactorGraph.h
Variable elimination algorithms for factor graphs.
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::EliminateForMPE
std::pair< DiscreteConditional::shared_ptr, DecisionTreeFactor::shared_ptr > EliminateForMPE(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Alternate elimination function for that creates non-normalized lookup tables.
Definition DiscreteFactorGraph.cpp:116
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::markdown
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition DiscreteValues.cpp:129
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
gtsam::optimize
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition triangulation.cpp:155
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
gtsam::KeyFormatter
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
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
gtsam::equals
Template to create a binary predicate.
Definition Testable.h:111
gtsam::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::DecisionTreeFactor
A discrete probabilistic factor.
Definition DecisionTreeFactor.h:45
gtsam::DiscreteBayesNet
A Bayes net made from discrete conditional distributions.
Definition DiscreteBayesNet.h:38
gtsam::DiscreteBayesTree
A Bayes tree representing a Discrete density.
Definition DiscreteBayesTree.h:75
gtsam::DiscreteConditional
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition DiscreteConditional.h:40
gtsam::DiscreteEliminationTree
Elimination tree for discrete factors.
Definition DiscreteEliminationTree.h:33
gtsam::DiscreteFactor
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition DiscreteFactor.h:38
gtsam::DiscreteFactor::Names
DiscreteValues::Names Names
Translation table from values to strings.
Definition DiscreteFactor.h:106
gtsam::EliminationTraits< DiscreteFactorGraph >::FactorGraphType
DiscreteFactorGraph FactorGraphType
Type of the factor graph (e.g. DiscreteFactorGraph).
Definition DiscreteFactorGraph.h:72
gtsam::EliminationTraits< DiscreteFactorGraph >::JunctionTreeType
DiscreteJunctionTree JunctionTreeType
Type of Junction tree.
Definition DiscreteFactorGraph.h:77
gtsam::EliminationTraits< DiscreteFactorGraph >::FactorType
DiscreteFactor FactorType
Type of factors in factor graph.
Definition DiscreteFactorGraph.h:71
gtsam::EliminationTraits< DiscreteFactorGraph >::DefaultEliminate
static std::pair< boost::shared_ptr< ConditionalType >, boost::shared_ptr< FactorType > > DefaultEliminate(const FactorGraphType &factors, const Ordering &keys)
The default dense elimination function.
Definition DiscreteFactorGraph.h:82
gtsam::EliminationTraits< DiscreteFactorGraph >::BayesTreeType
DiscreteBayesTree BayesTreeType
Type of Bayes tree.
Definition DiscreteFactorGraph.h:76
gtsam::EliminationTraits< DiscreteFactorGraph >::BayesNetType
DiscreteBayesNet BayesNetType
Type of Bayes net from sequential elimination.
Definition DiscreteFactorGraph.h:74
gtsam::EliminationTraits< DiscreteFactorGraph >::ConditionalType
DiscreteConditional ConditionalType
Type of conditionals from elimination.
Definition DiscreteFactorGraph.h:73
gtsam::EliminationTraits< DiscreteFactorGraph >::DefaultOrderingFunc
static Ordering DefaultOrderingFunc(const FactorGraphType &graph, boost::optional< const VariableIndex & > variableIndex)
The default ordering generation function.
Definition DiscreteFactorGraph.h:87
gtsam::EliminationTraits< DiscreteFactorGraph >::EliminationTreeType
DiscreteEliminationTree EliminationTreeType
Type of elimination tree.
Definition DiscreteFactorGraph.h:75
gtsam::DiscreteFactorGraph
A Discrete Factor Graph is a factor graph where all factors are Discrete, i.e.
Definition DiscreteFactorGraph.h:101
gtsam::DiscreteFactorGraph::DiscreteFactorGraph
DiscreteFactorGraph(const CONTAINER &factors)
Construct from container of factors (shared_ptr or plain objects).
Definition DiscreteFactorGraph.h:123
gtsam::DiscreteFactorGraph::shared_ptr
boost::shared_ptr< This > shared_ptr
shared_ptr to This
Definition DiscreteFactorGraph.h:107
gtsam::DiscreteFactorGraph::Values
DiscreteValues Values
backwards compatibility
Definition DiscreteFactorGraph.h:109
gtsam::DiscreteFactorGraph::Base
FactorGraph< DiscreteFactor > Base
base factor graph type
Definition DiscreteFactorGraph.h:104
gtsam::DiscreteFactorGraph::DiscreteFactorGraph
DiscreteFactorGraph()
Default constructor.
Definition DiscreteFactorGraph.h:114
gtsam::DiscreteFactorGraph::DiscreteFactorGraph
DiscreteFactorGraph(const FactorGraph< DERIVED_FACTOR > &graph)
Implicit copy/downcast constructor to override explicit template container constructor.
Definition DiscreteFactorGraph.h:128
gtsam::DiscreteFactorGraph::DiscreteFactorGraph
DiscreteFactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
Construct from iterator over factors.
Definition DiscreteFactorGraph.h:118
gtsam::DiscreteFactorGraph::~DiscreteFactorGraph
virtual ~DiscreteFactorGraph()
Destructor.
Definition DiscreteFactorGraph.h:131
gtsam::DiscreteFactorGraph::This
DiscreteFactorGraph This
this class
Definition DiscreteFactorGraph.h:103
gtsam::DiscreteFactorGraph::add
void add(Args &&... args)
Add a decision-tree factor.
Definition DiscreteFactorGraph.h:142
gtsam::DiscreteFactorGraph::BaseEliminateable
EliminateableFactorGraph< This > BaseEliminateable
for elimination
Definition DiscreteFactorGraph.h:105
gtsam::DiscreteJunctionTree
An EliminatableClusterTree, i.e., a set of variable clusters with factors, arranged in a tree,...
Definition DiscreteJunctionTree.h:52
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:39
gtsam::DiscreteLookupDAG
A DAG made from lookup tables, as defined above.
Definition DiscreteLookupDAG.h:77
gtsam::DiscreteValues
A map from keys to values.
Definition DiscreteValues.h:34
gtsam::FactorGraph< DiscreteFactor >::FactorGraph
FactorGraph()
Definition FactorGraph.h:142
gtsam::FactorGraph< DiscreteFactor >::emplace_shared
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Definition FactorGraph.h:192
gtsam::EliminationTraits
Traits class for eliminateable factor graphs, specifies the types that result from elimination,...
Definition EliminateableFactorGraph.h:36
gtsam::EliminateableFactorGraph
EliminateableFactorGraph is a base class for factor graphs that contains elimination algorithms.
Definition EliminateableFactorGraph.h:57
gtsam::Ordering
Definition Ordering.h:34
gtsam::Ordering::Colamd
static Ordering Colamd(const FACTOR_GRAPH &graph)
Compute a fill-reducing ordering using COLAMD from a factor graph (see details for note on performanc...
Definition Ordering.h:95