#include <BayesTree.h>
Public Types | |
typedef FastVector< sharedFactor >::const_iterator | const_iterator |
typedef FACTOR | FactorType |
factor type More... | |
typedef FastVector< sharedFactor >::iterator | iterator |
typedef std::shared_ptr< FACTOR > | sharedFactor |
Shared pointer to a factor. More... | |
typedef sharedFactor | value_type |
Protected Member Functions | |
bool | isEqual (const FactorGraph &other) const |
Check exact equality of the factor pointers. Useful for derived ==. More... | |
Protected Attributes | |
FastVector< sharedFactor > | factors_ |
Private Types | |
template<typename T > | |
using | HasDerivedElementType = typename std::enable_if< std::is_base_of< FactorType, typename T::value_type::element_type >::value >::type |
Check if T has a pointer type derived from FactorType. More... | |
template<typename T > | |
using | HasDerivedValueType = typename std::enable_if< std::is_base_of< FactorType, typename T::value_type >::value >::type |
Check if T has a value_type derived from FactorType. More... | |
template<typename DERIVEDFACTOR > | |
using | IsDerived = typename std::enable_if< std::is_base_of< FactorType, DERIVEDFACTOR >::value >::type |
Check if a DERIVEDFACTOR is in fact derived from FactorType. More... | |
typedef std::shared_ptr< This > | shared_ptr |
Shared pointer for this class. More... | |
typedef FactorGraph< FACTOR > | This |
Typedef for this class. More... | |
Standard Constructors | |
FactorGraph () | |
template<typename ITERATOR > | |
FactorGraph (ITERATOR firstFactor, ITERATOR lastFactor) | |
template<class CONTAINER > | |
FactorGraph (const CONTAINER &factors) | |
Constructors | |
virtual | ~FactorGraph ()=default |
template<class DERIVEDFACTOR , typename = IsDerived<DERIVEDFACTOR>> | |
FactorGraph (std::initializer_list< std::shared_ptr< DERIVEDFACTOR >> sharedFactors) | |
Adding Single Factors | |
void | reserve (size_t size) |
template<class DERIVEDFACTOR > | |
IsDerived< DERIVEDFACTOR > | push_back (std::shared_ptr< DERIVEDFACTOR > factor) |
Add a factor directly using a shared_ptr. More... | |
template<class DERIVEDFACTOR , class... Args> | |
IsDerived< DERIVEDFACTOR > | emplace_shared (Args &&... args) |
Emplace a shared pointer to factor of given type. More... | |
template<class DERIVEDFACTOR > | |
IsDerived< DERIVEDFACTOR > | push_back (const DERIVEDFACTOR &factor) |
template<class DERIVEDFACTOR > | |
IsDerived< DERIVEDFACTOR > | add (std::shared_ptr< DERIVEDFACTOR > factor) |
add is a synonym for push_back. More... | |
template<class DERIVEDFACTOR > | |
std::enable_if< std::is_base_of< FactorType, DERIVEDFACTOR >::value, This >::type & | operator+= (std::shared_ptr< DERIVEDFACTOR > factor) |
Append factor to factor graph. More... | |
template<class DERIVEDFACTOR > | |
std::enable_if< std::is_base_of< FactorType, DERIVEDFACTOR >::value, This >::type & | operator, (std::shared_ptr< DERIVEDFACTOR > factor) |
Overload comma operator to allow for append chaining. More... | |
Adding via iterators | |
template<typename ITERATOR > | |
HasDerivedElementType< ITERATOR > | push_back (ITERATOR firstFactor, ITERATOR lastFactor) |
template<typename ITERATOR > | |
HasDerivedValueType< ITERATOR > | push_back (ITERATOR firstFactor, ITERATOR lastFactor) |
Push back many factors with an iterator (factors are copied) More... | |
Adding via container | |
template<typename CONTAINER > | |
HasDerivedElementType< CONTAINER > | push_back (const CONTAINER &container) |
template<typename CONTAINER > | |
HasDerivedValueType< CONTAINER > | push_back (const CONTAINER &container) |
Push back non-pointer objects in a container (factors are copied). More... | |
template<class FACTOR_OR_CONTAINER > | |
void | add (const FACTOR_OR_CONTAINER &factorOrContainer) |
template<class FACTOR_OR_CONTAINER > | |
This & | operator+= (const FACTOR_OR_CONTAINER &factorOrContainer) |
Specialized versions | |
template<class CLIQUE > | |
std::enable_if< std::is_base_of< This, typename CLIQUE::FactorGraphType >::value >::type | push_back (const BayesTree< CLIQUE > &bayesTree) |
template<typename CONTAINER , typename = HasDerivedElementType<CONTAINER>> | |
FactorIndices | add_factors (const CONTAINER &factors, bool useEmptySlots=false) |
Testable | |
virtual void | print (const std::string &s="FactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const |
Print out graph to std::cout, with optional key formatter. More... | |
bool | equals (const This &fg, double tol=1e-9) const |
Check equality up to tolerance. More... | |
Standard Interface | |
size_t | size () const |
bool | empty () const |
const sharedFactor | at (size_t i) const |
sharedFactor & | at (size_t i) |
template<typename F > | |
std::shared_ptr< F > | at (size_t i) |
template<typename F > | |
const std::shared_ptr< F > | at (size_t i) const |
Const version of templated at method. More... | |
const sharedFactor | operator[] (size_t i) const |
sharedFactor & | operator[] (size_t i) |
const_iterator | begin () const |
const_iterator | end () const |
sharedFactor | front () const |
sharedFactor | back () const |
double | error (const HybridValues &values) const |
Modifying Factor Graphs (imperative, discouraged) | |
iterator | begin () |
iterator | end () |
virtual void | resize (size_t size) |
void | remove (size_t i) |
void | replace (size_t index, sharedFactor factor) |
iterator | erase (iterator item) |
iterator | erase (iterator first, iterator last) |
Graph Display | |
void | dot (std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DotWriter &writer=DotWriter()) const |
Output to graphviz format, stream version. More... | |
std::string | dot (const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DotWriter &writer=DotWriter()) const |
Output to graphviz format string. More... | |
void | saveGraph (const std::string &filename, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DotWriter &writer=DotWriter()) const |
output to file with graphviz format. More... | |
Advanced Interface | |
size_t | nrFactors () const |
KeySet | keys () const |
KeyVector | keyVector () const |
bool | exists (size_t idx) const |
A factor graph is a bipartite graph with factor nodes connected to variable nodes. In this class, however, only factor nodes are kept around.
Definition at line 34 of file BayesTree.h.
typedef FastVector<sharedFactor>::const_iterator gtsam::FactorGraph< FACTOR >::const_iterator |
Definition at line 65 of file FactorGraph.h.
typedef FACTOR gtsam::FactorGraph< FACTOR >::FactorType |
factor type
Definition at line 60 of file FactorGraph.h.
|
private |
Check if T has a pointer type derived from FactorType.
Definition at line 85 of file FactorGraph.h.
|
private |
Check if T has a value_type derived from FactorType.
Definition at line 80 of file FactorGraph.h.
|
private |
Check if a DERIVEDFACTOR is in fact derived from FactorType.
Definition at line 75 of file FactorGraph.h.
typedef FastVector<sharedFactor>::iterator gtsam::FactorGraph< FACTOR >::iterator |
Definition at line 64 of file FactorGraph.h.
|
private |
Shared pointer for this class.
Definition at line 70 of file FactorGraph.h.
typedef std::shared_ptr<FACTOR> gtsam::FactorGraph< FACTOR >::sharedFactor |
Shared pointer to a factor.
Definition at line 62 of file FactorGraph.h.
|
private |
Typedef for this class.
Definition at line 68 of file FactorGraph.h.
typedef sharedFactor gtsam::FactorGraph< FACTOR >::value_type |
Definition at line 63 of file FactorGraph.h.
|
inlineprotected |
Default constructor
Definition at line 103 of file FactorGraph.h.
|
inlineprotected |
Constructor from iterator over factors (shared_ptr or plain objects)
Definition at line 107 of file FactorGraph.h.
|
inlineexplicitprotected |
Construct from container of factors (shared_ptr or plain objects)
Definition at line 113 of file FactorGraph.h.
|
virtualdefault |
Default destructor Public and virtual so boost serialization can call it.
|
inline |
Constructor that takes an initializer list of shared pointers. FactorGraph fg = {make_shared<MyFactor>(), ...};
Definition at line 132 of file FactorGraph.h.
|
inline |
Add a factor or container of factors, including STL collections, BayesTrees, etc.
Definition at line 241 of file FactorGraph.h.
|
inline |
add
is a synonym for push_back.
Definition at line 171 of file FactorGraph.h.
FactorIndices gtsam::FactorGraph< FACTOR >::add_factors | ( | const CONTAINER & | factors, |
bool | useEmptySlots = false |
||
) |
Add new factors to a factor graph and returns a list of new factor indices, optionally finding and reusing empty factor slots.
Definition at line 109 of file FactorGraph-inst.h.
|
inline |
Get a specific factor by index (this checks array bounds and may throw an exception, as opposed to operator[] which does not).
Definition at line 311 of file FactorGraph.h.
|
inline |
Get a specific factor by index and typecast to factor type F (this checks array bounds and may throw an exception, as opposed to operator[] which does not).
Definition at line 318 of file FactorGraph.h.
|
inline |
Get a specific factor by index (this checks array bounds and may throw an exception, as opposed to operator[] which does not).
Definition at line 306 of file FactorGraph.h.
|
inline |
Const version of templated at
method.
Definition at line 324 of file FactorGraph.h.
|
inline |
Get the last factor
Definition at line 348 of file FactorGraph.h.
|
inline |
non-const STL-style begin()
Definition at line 358 of file FactorGraph.h.
|
inline |
Iterator to beginning of factors.
Definition at line 339 of file FactorGraph.h.
std::string gtsam::FactorGraph< FACTOR >::dot | ( | const KeyFormatter & | keyFormatter = DefaultKeyFormatter , |
const DotWriter & | writer = DotWriter() |
||
) | const |
Output to graphviz format string.
Definition at line 168 of file FactorGraph-inst.h.
void gtsam::FactorGraph< FACTOR >::dot | ( | std::ostream & | os, |
const KeyFormatter & | keyFormatter = DefaultKeyFormatter , |
||
const DotWriter & | writer = DotWriter() |
||
) | const |
Output to graphviz format, stream version.
Definition at line 141 of file FactorGraph-inst.h.
|
inline |
Emplace a shared pointer to factor of given type.
Definition at line 153 of file FactorGraph.h.
|
inline |
Check if the graph is empty (null factors set by remove() will cause this to return false).
Definition at line 301 of file FactorGraph.h.
|
inline |
non-const STL-style end()
Definition at line 361 of file FactorGraph.h.
|
inline |
Iterator to end of factors.
Definition at line 342 of file FactorGraph.h.
bool gtsam::FactorGraph< FACTOR >::equals | ( | const This & | fg, |
double | tol = 1e-9 |
||
) | const |
Check equality up to tolerance.
Definition at line 50 of file FactorGraph-inst.h.
|
inline |
Erase factors and rearrange other factors to take up the empty space
Definition at line 380 of file FactorGraph.h.
|
inline |
Erase factor and rearrange other factors to take up the empty space
Definition at line 377 of file FactorGraph.h.
double gtsam::FactorGraph< FACTOR >::error | ( | const HybridValues & | values | ) | const |
Add error for all factors.
Definition at line 66 of file FactorGraph-inst.h.
|
inline |
MATLAB interface utility: Checks whether a factor index idx exists in the graph and is a live pointer
Definition at line 420 of file FactorGraph.h.
|
inline |
Get the first factor
Definition at line 345 of file FactorGraph.h.
|
inlineprotected |
Check exact equality of the factor pointers. Useful for derived ==.
Definition at line 95 of file FactorGraph.h.
KeySet gtsam::FactorGraph< FACTOR >::keys |
Potentially slow function to return all keys involved, sorted, as a set
Definition at line 85 of file FactorGraph-inst.h.
KeyVector gtsam::FactorGraph< FACTOR >::keyVector |
Potentially slow function to return all keys involved, sorted, as a vector
Definition at line 95 of file FactorGraph-inst.h.
size_t gtsam::FactorGraph< FACTOR >::nrFactors |
return the number of non-null factors
Definition at line 76 of file FactorGraph-inst.h.
|
inline |
Add a factor or container of factors, including STL collections, BayesTrees, etc.
Definition at line 250 of file FactorGraph.h.
|
inline |
Append factor to factor graph.
Definition at line 179 of file FactorGraph.h.
|
inline |
Overload comma operator to allow for append chaining.
E.g. fg += factor1, factor2, ...
Definition at line 190 of file FactorGraph.h.
|
inline |
Get a specific factor by index (this does not check array bounds, as opposed to at() which does).
Definition at line 336 of file FactorGraph.h.
|
inline |
Get a specific factor by index (this does not check array bounds, as opposed to at() which does).
Definition at line 331 of file FactorGraph.h.
|
virtual |
Print out graph to std::cout, with optional key formatter.
Reimplemented in gtsam::NonlinearFactorGraph, gtsam::InequalityFactorGraph, gtsam::SymbolicFactorGraph, gtsam::SymbolicBayesNet, gtsam::Scheduler, gtsam::HybridNonlinearFactorGraph, gtsam::HybridGaussianFactorGraph, gtsam::DiscreteFactorGraph, gtsam::BayesNet< CONDITIONAL >, gtsam::BayesNet< SymbolicConditional >, gtsam::BayesNet< GaussianConditional >, gtsam::BayesNet< DiscreteConditional >, gtsam::BayesNet< HybridConditional >, gtsam::BayesNet< DiscreteLookupTable >, gtsam::GaussianBayesNet, and gtsam::HybridBayesNet.
Definition at line 37 of file FactorGraph-inst.h.
|
inline |
Push back a BayesTree as a collection of factors. NOTE: This should be hidden in derived classes in favor of a type-specialized version that calls this templated function.
Definition at line 267 of file FactorGraph.h.
|
inline |
Push back many factors as shared_ptr's in a container (factors are not copied)
Definition at line 226 of file FactorGraph.h.
|
inline |
Push back non-pointer objects in a container (factors are copied).
Definition at line 232 of file FactorGraph.h.
|
inline |
Add a factor by value, will be copy-constructed (use push_back with a shared_ptr to avoid the copy).
Definition at line 164 of file FactorGraph.h.
|
inline |
Push back many factors with an iterator over shared_ptr (factors are not copied)
Definition at line 205 of file FactorGraph.h.
|
inline |
Push back many factors with an iterator (factors are copied)
Definition at line 212 of file FactorGraph.h.
|
inline |
Add a factor directly using a shared_ptr.
Definition at line 147 of file FactorGraph.h.
|
inline |
delete factor without re-arranging indexes by inserting a nullptr pointer
Definition at line 371 of file FactorGraph.h.
|
inline |
replace a factor by index
Definition at line 374 of file FactorGraph.h.
|
inline |
Reserve space for the specified number of factors if you know in advance how many there will be (works like FastVector::reserve).
Definition at line 143 of file FactorGraph.h.
|
inlinevirtual |
Directly resize the number of factors in the graph. If the new size is less than the original, factors at the end will be removed. If the new size is larger than the original, null factors will be appended.
Definition at line 367 of file FactorGraph.h.
void gtsam::FactorGraph< FACTOR >::saveGraph | ( | const std::string & | filename, |
const KeyFormatter & | keyFormatter = DefaultKeyFormatter , |
||
const DotWriter & | writer = DotWriter() |
||
) | const |
output to file with graphviz format.
Definition at line 177 of file FactorGraph-inst.h.
|
inline |
return the number of factors (including any null factors set by remove() ).
Definition at line 297 of file FactorGraph.h.
|
protected |
concept check, makes sure FACTOR defines print and equals Collection of factors
Definition at line 92 of file FactorGraph.h.