Public Types | Protected Member Functions | Protected Attributes | Private Types | List of all members
gtsam::FactorGraph< FACTOR > Class Template Reference

#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< sharedFactorfactors_
 

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< Thisshared_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 >::typeoperator+= (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 >::typeoperator, (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 >
Thisoperator+= (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
 
sharedFactorat (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
 
sharedFactoroperator[] (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
 

Detailed Description

template<class FACTOR>
class gtsam::FactorGraph< FACTOR >

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.

Member Typedef Documentation

◆ const_iterator

template<class FACTOR >
typedef FastVector<sharedFactor>::const_iterator gtsam::FactorGraph< FACTOR >::const_iterator

Definition at line 65 of file FactorGraph.h.

◆ FactorType

template<class FACTOR >
typedef FACTOR gtsam::FactorGraph< FACTOR >::FactorType

factor type

Definition at line 60 of file FactorGraph.h.

◆ HasDerivedElementType

template<class FACTOR >
template<typename T >
using gtsam::FactorGraph< FACTOR >::HasDerivedElementType = typename std::enable_if<std::is_base_of< FactorType, typename T::value_type::element_type>::value>::type
private

Check if T has a pointer type derived from FactorType.

Definition at line 85 of file FactorGraph.h.

◆ HasDerivedValueType

template<class FACTOR >
template<typename T >
using gtsam::FactorGraph< FACTOR >::HasDerivedValueType = typename std::enable_if< std::is_base_of<FactorType, typename T::value_type>::value>::type
private

Check if T has a value_type derived from FactorType.

Definition at line 80 of file FactorGraph.h.

◆ IsDerived

template<class FACTOR >
template<typename DERIVEDFACTOR >
using gtsam::FactorGraph< FACTOR >::IsDerived = typename std::enable_if< std::is_base_of<FactorType, DERIVEDFACTOR>::value>::type
private

Check if a DERIVEDFACTOR is in fact derived from FactorType.

Definition at line 75 of file FactorGraph.h.

◆ iterator

template<class FACTOR >
typedef FastVector<sharedFactor>::iterator gtsam::FactorGraph< FACTOR >::iterator

Definition at line 64 of file FactorGraph.h.

◆ shared_ptr

template<class FACTOR >
typedef std::shared_ptr<This> gtsam::FactorGraph< FACTOR >::shared_ptr
private

Shared pointer for this class.

Definition at line 70 of file FactorGraph.h.

◆ sharedFactor

template<class FACTOR >
typedef std::shared_ptr<FACTOR> gtsam::FactorGraph< FACTOR >::sharedFactor

Shared pointer to a factor.

Definition at line 62 of file FactorGraph.h.

◆ This

template<class FACTOR >
typedef FactorGraph<FACTOR> gtsam::FactorGraph< FACTOR >::This
private

Typedef for this class.

Definition at line 68 of file FactorGraph.h.

◆ value_type

template<class FACTOR >
typedef sharedFactor gtsam::FactorGraph< FACTOR >::value_type

Definition at line 63 of file FactorGraph.h.

Constructor & Destructor Documentation

◆ FactorGraph() [1/4]

template<class FACTOR >
gtsam::FactorGraph< FACTOR >::FactorGraph ( )
inlineprotected

Default constructor

Definition at line 103 of file FactorGraph.h.

◆ FactorGraph() [2/4]

template<class FACTOR >
template<typename ITERATOR >
gtsam::FactorGraph< FACTOR >::FactorGraph ( ITERATOR  firstFactor,
ITERATOR  lastFactor 
)
inlineprotected

Constructor from iterator over factors (shared_ptr or plain objects)

Definition at line 107 of file FactorGraph.h.

◆ FactorGraph() [3/4]

template<class FACTOR >
template<class CONTAINER >
gtsam::FactorGraph< FACTOR >::FactorGraph ( const CONTAINER &  factors)
inlineexplicitprotected

Construct from container of factors (shared_ptr or plain objects)

Definition at line 113 of file FactorGraph.h.

◆ ~FactorGraph()

template<class FACTOR >
virtual gtsam::FactorGraph< FACTOR >::~FactorGraph ( )
virtualdefault

Default destructor Public and virtual so boost serialization can call it.

◆ FactorGraph() [4/4]

template<class FACTOR >
template<class DERIVEDFACTOR , typename = IsDerived<DERIVEDFACTOR>>
gtsam::FactorGraph< FACTOR >::FactorGraph ( std::initializer_list< std::shared_ptr< DERIVEDFACTOR >>  sharedFactors)
inline

Constructor that takes an initializer list of shared pointers. FactorGraph fg = {make_shared<MyFactor>(), ...};

Definition at line 132 of file FactorGraph.h.

Member Function Documentation

◆ add() [1/2]

template<class FACTOR >
template<class FACTOR_OR_CONTAINER >
void gtsam::FactorGraph< FACTOR >::add ( const FACTOR_OR_CONTAINER &  factorOrContainer)
inline

Add a factor or container of factors, including STL collections, BayesTrees, etc.

Definition at line 241 of file FactorGraph.h.

◆ add() [2/2]

template<class FACTOR >
template<class DERIVEDFACTOR >
IsDerived<DERIVEDFACTOR> gtsam::FactorGraph< FACTOR >::add ( std::shared_ptr< DERIVEDFACTOR >  factor)
inline

add is a synonym for push_back.

Definition at line 171 of file FactorGraph.h.

◆ add_factors()

template<class FACTOR >
template<typename CONTAINER , typename >
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.

◆ at() [1/4]

template<class FACTOR >
sharedFactor& gtsam::FactorGraph< FACTOR >::at ( size_t  i)
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.

◆ at() [2/4]

template<class FACTOR >
template<typename F >
std::shared_ptr<F> gtsam::FactorGraph< FACTOR >::at ( size_t  i)
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.

◆ at() [3/4]

template<class FACTOR >
const sharedFactor gtsam::FactorGraph< FACTOR >::at ( size_t  i) const
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.

◆ at() [4/4]

template<class FACTOR >
template<typename F >
const std::shared_ptr<F> gtsam::FactorGraph< FACTOR >::at ( size_t  i) const
inline

Const version of templated at method.

Definition at line 324 of file FactorGraph.h.

◆ back()

template<class FACTOR >
sharedFactor gtsam::FactorGraph< FACTOR >::back ( ) const
inline

Get the last factor

Definition at line 348 of file FactorGraph.h.

◆ begin() [1/2]

template<class FACTOR >
iterator gtsam::FactorGraph< FACTOR >::begin ( )
inline

non-const STL-style begin()

Definition at line 358 of file FactorGraph.h.

◆ begin() [2/2]

template<class FACTOR >
const_iterator gtsam::FactorGraph< FACTOR >::begin ( ) const
inline

Iterator to beginning of factors.

Definition at line 339 of file FactorGraph.h.

◆ dot() [1/2]

template<class FACTOR >
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.

◆ dot() [2/2]

template<class FACTOR >
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.

◆ emplace_shared()

template<class FACTOR >
template<class DERIVEDFACTOR , class... Args>
IsDerived<DERIVEDFACTOR> gtsam::FactorGraph< FACTOR >::emplace_shared ( Args &&...  args)
inline

Emplace a shared pointer to factor of given type.

Definition at line 153 of file FactorGraph.h.

◆ empty()

template<class FACTOR >
bool gtsam::FactorGraph< FACTOR >::empty ( ) const
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.

◆ end() [1/2]

template<class FACTOR >
iterator gtsam::FactorGraph< FACTOR >::end ( )
inline

non-const STL-style end()

Definition at line 361 of file FactorGraph.h.

◆ end() [2/2]

template<class FACTOR >
const_iterator gtsam::FactorGraph< FACTOR >::end ( ) const
inline

Iterator to end of factors.

Definition at line 342 of file FactorGraph.h.

◆ equals()

template<class FACTOR >
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.

◆ erase() [1/2]

template<class FACTOR >
iterator gtsam::FactorGraph< FACTOR >::erase ( iterator  first,
iterator  last 
)
inline

Erase factors and rearrange other factors to take up the empty space

Definition at line 380 of file FactorGraph.h.

◆ erase() [2/2]

template<class FACTOR >
iterator gtsam::FactorGraph< FACTOR >::erase ( iterator  item)
inline

Erase factor and rearrange other factors to take up the empty space

Definition at line 377 of file FactorGraph.h.

◆ error()

template<class FACTOR >
double gtsam::FactorGraph< FACTOR >::error ( const HybridValues values) const

Add error for all factors.

Definition at line 66 of file FactorGraph-inst.h.

◆ exists()

template<class FACTOR >
bool gtsam::FactorGraph< FACTOR >::exists ( size_t  idx) const
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.

◆ front()

template<class FACTOR >
sharedFactor gtsam::FactorGraph< FACTOR >::front ( ) const
inline

Get the first factor

Definition at line 345 of file FactorGraph.h.

◆ isEqual()

template<class FACTOR >
bool gtsam::FactorGraph< FACTOR >::isEqual ( const FactorGraph< FACTOR > &  other) const
inlineprotected

Check exact equality of the factor pointers. Useful for derived ==.

Definition at line 95 of file FactorGraph.h.

◆ keys()

template<class FACTOR >
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()

template<class FACTOR >
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.

◆ nrFactors()

template<class FACTOR >
size_t gtsam::FactorGraph< FACTOR >::nrFactors

return the number of non-null factors

Definition at line 76 of file FactorGraph-inst.h.

◆ operator+=() [1/2]

template<class FACTOR >
template<class FACTOR_OR_CONTAINER >
This& gtsam::FactorGraph< FACTOR >::operator+= ( const FACTOR_OR_CONTAINER &  factorOrContainer)
inline

Add a factor or container of factors, including STL collections, BayesTrees, etc.

Definition at line 250 of file FactorGraph.h.

◆ operator+=() [2/2]

template<class FACTOR >
template<class DERIVEDFACTOR >
std::enable_if<std::is_base_of<FactorType, DERIVEDFACTOR>::value, This>::type& gtsam::FactorGraph< FACTOR >::operator+= ( std::shared_ptr< DERIVEDFACTOR >  factor)
inline

Append factor to factor graph.

Definition at line 179 of file FactorGraph.h.

◆ operator,()

template<class FACTOR >
template<class DERIVEDFACTOR >
std::enable_if<std::is_base_of<FactorType, DERIVEDFACTOR>::value, This>::type& gtsam::FactorGraph< FACTOR >::operator, ( std::shared_ptr< DERIVEDFACTOR >  factor)
inline

Overload comma operator to allow for append chaining.

E.g. fg += factor1, factor2, ...

Definition at line 190 of file FactorGraph.h.

◆ operator[]() [1/2]

template<class FACTOR >
sharedFactor& gtsam::FactorGraph< FACTOR >::operator[] ( size_t  i)
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.

◆ operator[]() [2/2]

template<class FACTOR >
const sharedFactor gtsam::FactorGraph< FACTOR >::operator[] ( size_t  i) const
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.

◆ print()

template<class FACTOR >
void gtsam::FactorGraph< FACTOR >::print ( const std::string &  s = "FactorGraph< FACTOR >",
const KeyFormatter formatter = DefaultKeyFormatter 
) const
virtual

◆ push_back() [1/7]

template<class FACTOR >
template<class CLIQUE >
std::enable_if< std::is_base_of<This, typename CLIQUE::FactorGraphType>::value>::type gtsam::FactorGraph< FACTOR >::push_back ( const BayesTree< CLIQUE > &  bayesTree)
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.

◆ push_back() [2/7]

template<class FACTOR >
template<typename CONTAINER >
HasDerivedElementType<CONTAINER> gtsam::FactorGraph< FACTOR >::push_back ( const CONTAINER &  container)
inline

Push back many factors as shared_ptr's in a container (factors are not copied)

Definition at line 226 of file FactorGraph.h.

◆ push_back() [3/7]

template<class FACTOR >
template<typename CONTAINER >
HasDerivedValueType<CONTAINER> gtsam::FactorGraph< FACTOR >::push_back ( const CONTAINER &  container)
inline

Push back non-pointer objects in a container (factors are copied).

Definition at line 232 of file FactorGraph.h.

◆ push_back() [4/7]

template<class FACTOR >
template<class DERIVEDFACTOR >
IsDerived<DERIVEDFACTOR> gtsam::FactorGraph< FACTOR >::push_back ( const DERIVEDFACTOR &  factor)
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.

◆ push_back() [5/7]

template<class FACTOR >
template<typename ITERATOR >
HasDerivedElementType<ITERATOR> gtsam::FactorGraph< FACTOR >::push_back ( ITERATOR  firstFactor,
ITERATOR  lastFactor 
)
inline

Push back many factors with an iterator over shared_ptr (factors are not copied)

Definition at line 205 of file FactorGraph.h.

◆ push_back() [6/7]

template<class FACTOR >
template<typename ITERATOR >
HasDerivedValueType<ITERATOR> gtsam::FactorGraph< FACTOR >::push_back ( ITERATOR  firstFactor,
ITERATOR  lastFactor 
)
inline

Push back many factors with an iterator (factors are copied)

Definition at line 212 of file FactorGraph.h.

◆ push_back() [7/7]

template<class FACTOR >
template<class DERIVEDFACTOR >
IsDerived<DERIVEDFACTOR> gtsam::FactorGraph< FACTOR >::push_back ( std::shared_ptr< DERIVEDFACTOR >  factor)
inline

Add a factor directly using a shared_ptr.

Definition at line 147 of file FactorGraph.h.

◆ remove()

template<class FACTOR >
void gtsam::FactorGraph< FACTOR >::remove ( size_t  i)
inline

delete factor without re-arranging indexes by inserting a nullptr pointer

Definition at line 371 of file FactorGraph.h.

◆ replace()

template<class FACTOR >
void gtsam::FactorGraph< FACTOR >::replace ( size_t  index,
sharedFactor  factor 
)
inline

replace a factor by index

Definition at line 374 of file FactorGraph.h.

◆ reserve()

template<class FACTOR >
void gtsam::FactorGraph< FACTOR >::reserve ( size_t  size)
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.

◆ resize()

template<class FACTOR >
virtual void gtsam::FactorGraph< FACTOR >::resize ( size_t  size)
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.

◆ saveGraph()

template<class FACTOR >
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.

◆ size()

template<class FACTOR >
size_t gtsam::FactorGraph< FACTOR >::size ( ) const
inline

return the number of factors (including any null factors set by remove() ).

Definition at line 297 of file FactorGraph.h.

Member Data Documentation

◆ factors_

template<class FACTOR >
FastVector<sharedFactor> gtsam::FactorGraph< FACTOR >::factors_
protected

concept check, makes sure FACTOR defines print and equals Collection of factors

Definition at line 92 of file FactorGraph.h.


The documentation for this class was generated from the following files:


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:51:18