gtsam 4.2.0
gtsam
Loading...
Searching...
No Matches
gtsam::NonlinearFactor Class Referenceabstract

Detailed Description

Nonlinear factor base class.

This is the base class for all factor types, as well as conditionals, which are implemented as specialized factors.

This class does not store any data other than its keys. Derived classes store data such as matrices and probability tables.

The error method is used to evaluate the factor, and is the only method that is required to be implemented in derived classes, although it has a default implementation that throws an exception.

There are five broad classes of factors that derive from Factor:

  • Nonlinear factors, such as NoiseModelFactor, which represent a nonlinear likelihood function over a set of variables.
  • Gaussian factors, such as
+ Inheritance diagram for gtsam::NonlinearFactor:

Standard Constructors

 NonlinearFactor ()
 Default constructor for I/O only.
 
template<typename CONTAINER >
 NonlinearFactor (const CONTAINER &keys)
 Constructor from a collection of the keys involved in this factor.
 

Testable

void print (const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
 print
 
virtual bool equals (const NonlinearFactor &f, double tol=1e-9) const
 Check if two factors are equal.
 

Standard Interface

virtual ~NonlinearFactor ()
 Destructor.
 
virtual double error (const Values &c) const
 
double error (const HybridValues &c) const override
 All factor types need to implement an error function.
 
virtual size_t dim () const =0
 get the dimension of the factor (number of rows on linearization)
 
virtual bool active (const Values &) const
 Checks whether a factor should be used based on a set of values.
 
virtual boost::shared_ptr< GaussianFactorlinearize (const Values &c) const =0
 linearize to a GaussianFactor
 
virtual shared_ptr clone () const
 Creates a shared_ptr clone of the factor - needs to be specialized to allow for subclasses.
 
virtual shared_ptr rekey (const std::map< Key, Key > &rekey_mapping) const
 Creates a shared_ptr clone of the factor with different keys using a map from old->new keys.
 
virtual shared_ptr rekey (const KeyVector &new_keys) const
 Clones a factor and fully replaces its keys.
 
virtual bool sendable () const
 Should the factor be evaluated in the same thread as the caller This is to enable factors that has shared states (like the Python GIL lock)
 

Public Types

typedef boost::shared_ptr< Thisshared_ptr
 
- Public Types inherited from gtsam::Factor
typedef KeyVector::iterator iterator
 Iterator over keys.
 
typedef KeyVector::const_iterator const_iterator
 Const iterator over keys.
 

Protected Types

typedef Factor Base
 
typedef NonlinearFactor This
 

Additional Inherited Members

- Public Member Functions inherited from gtsam::Factor
virtual ~Factor ()=default
 Default destructor.
 
bool empty () const
 Whether the factor is empty (involves zero variables).
 
Key front () const
 First key.
 
Key back () const
 Last key.
 
const_iterator find (Key key) const
 find
 
const KeyVectorkeys () const
 Access the factor's involved variable keys.
 
const_iterator begin () const
 Iterator at beginning of involved variable keys.
 
const_iterator end () const
 Iterator at end of involved variable keys.
 
size_t size () const
 
virtual void printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
 print only keys
 
bool equals (const This &other, double tol=1e-9) const
 check equality
 
KeyVectorkeys ()
 
iterator begin ()
 Iterator at beginning of involved variable keys.
 
iterator end ()
 Iterator at end of involved variable keys.
 
- Protected Member Functions inherited from gtsam::Factor
 Factor ()
 Default constructor for I/O.
 
template<typename CONTAINER >
 Factor (const CONTAINER &keys)
 Construct factor from container of keys.
 
template<typename ITERATOR >
 Factor (ITERATOR first, ITERATOR last)
 Construct factor from iterator keys.
 
- Static Protected Member Functions inherited from gtsam::Factor
template<typename CONTAINER >
static Factor FromKeys (const CONTAINER &keys)
 Construct factor from container of keys.
 
template<typename ITERATOR >
static Factor FromIterators (ITERATOR first, ITERATOR last)
 Construct factor from iterator keys.
 
- Protected Attributes inherited from gtsam::Factor
KeyVector keys_
 The keys involved in this factor.
 

Member Function Documentation

◆ active()

virtual bool gtsam::NonlinearFactor::active ( const Values ) const
inlinevirtual

Checks whether a factor should be used based on a set of values.

This is primarily used to implement inequality constraints that require a variable active set. For all others, the default implementation returning true solves this problem.

In an inequality/bounding constraint, this active() returns true when the constraint is NOT fulfilled.

Returns
true if the constraint is active

Reimplemented in gtsam::AntiFactor, gtsam::BoundingConstraint1< VALUE >, and gtsam::BoundingConstraint2< VALUE1, VALUE2 >.

◆ clone()

virtual shared_ptr gtsam::NonlinearFactor::clone ( ) const
inlinevirtual

Creates a shared_ptr clone of the factor - needs to be specialized to allow for subclasses.

By default, throws exception if subclass does not implement the function.

Reimplemented in gtsam::AHRSFactor, gtsam::Rot3AttitudeFactor, gtsam::Pose3AttitudeFactor, gtsam::BarometricFactor, gtsam::CombinedImuFactor, gtsam::GPSFactor, gtsam::GPSFactor2, gtsam::ImuFactor, gtsam::ImuFactor2, gtsam::MagFactor, gtsam::MagFactor1, gtsam::MagFactor2, gtsam::MagFactor3, gtsam::MagPoseFactor< POSE >, gtsam::ExpressionFactor< T >, gtsam::ExpressionFactor< BearingRange< A1, A2 > >, gtsam::ExpressionFactor< double >, gtsam::ExpressionFactor< typename Bearing< A1, A2 >::result_type >, gtsam::ExpressionFactor< typename Range< A1, A1 >::result_type >, gtsam::FunctorizedFactor< R, T >, gtsam::FunctorizedFactor< double, BASIS::Parameters >, gtsam::FunctorizedFactor< double, ParameterMatrix< P > >, gtsam::FunctorizedFactor< double, Vector >, gtsam::FunctorizedFactor< T, ParameterMatrix< traits< T >::dimension > >, gtsam::FunctorizedFactor< Vector, ParameterMatrix< M > >, gtsam::FunctorizedFactor2< R, T1, T2 >, gtsam::LinearContainerFactor, gtsam::NonlinearEquality< VALUE >, gtsam::NonlinearEquality1< VALUE >, gtsam::NonlinearEquality2< T >, gtsam::PriorFactor< VALUE >, gtsam::BearingRangeFactor< A1, A2, B, R >, gtsam::RangeFactor< A1, A2, T >, gtsam::RangeFactorWithTransform< A1, A2, T >, gtsam::AntiFactor, gtsam::BetweenFactor< VALUE >, gtsam::EssentialMatrixConstraint, gtsam::EssentialMatrixFactor, gtsam::EssentialMatrixFactor2, gtsam::EssentialMatrixFactor3, gtsam::EssentialMatrixFactor4< CALIBRATION >, gtsam::GeneralSFMFactor< CAMERA, LANDMARK >, gtsam::GeneralSFMFactor2< CALIBRATION >, gtsam::PoseRotationPrior< POSE >, gtsam::PoseTranslationPrior< POSE >, gtsam::GenericProjectionFactor< POSE, LANDMARK, CALIBRATION >, gtsam::ReferenceFrameFactor< POINT, TRANSFORM >, gtsam::RotateFactor, gtsam::RotateDirectionsFactor, gtsam::GenericStereoFactor< POSE, LANDMARK >, and gtsam::TriangulationFactor< CAMERA >.

◆ dim()

virtual size_t gtsam::NonlinearFactor::dim ( ) const
pure virtual

◆ equals()

bool NonlinearFactor::equals ( const NonlinearFactor f,
double  tol = 1e-9 
) const
virtual

Check if two factors are equal.

Reimplemented in gtsam::AHRSFactor, gtsam::Rot3AttitudeFactor, gtsam::Pose3AttitudeFactor, gtsam::BarometricFactor, gtsam::CombinedImuFactor, gtsam::GPSFactor, gtsam::GPSFactor2, gtsam::ImuFactor, gtsam::ImuFactor2, gtsam::MagPoseFactor< POSE >, gtsam::PriorFactor< VALUE >, gtsam::ShonanFactor< d >, gtsam::AntiFactor, gtsam::BetweenFactor< VALUE >, gtsam::EssentialMatrixConstraint, gtsam::FrobeniusBetweenFactor< Rot >, gtsam::OrientedPlane3DirectionPrior, gtsam::PoseRotationPrior< POSE >, gtsam::PoseTranslationPrior< POSE >, gtsam::ExpressionFactor< T >, gtsam::ExpressionFactor< BearingRange< A1, A2 > >, gtsam::ExpressionFactor< double >, gtsam::ExpressionFactor< typename Bearing< A1, A2 >::result_type >, gtsam::ExpressionFactor< typename Range< A1, A1 >::result_type >, gtsam::LinearContainerFactor, gtsam::NonlinearEquality< VALUE >, gtsam::NoiseModelFactor, gtsam::GenericStereoFactor< POSE, LANDMARK >, gtsam::FunctorizedFactor< R, T >, gtsam::FunctorizedFactor< double, BASIS::Parameters >, gtsam::FunctorizedFactor< double, ParameterMatrix< P > >, gtsam::FunctorizedFactor< double, Vector >, gtsam::FunctorizedFactor< T, ParameterMatrix< traits< T >::dimension > >, gtsam::FunctorizedFactor< Vector, ParameterMatrix< M > >, gtsam::FunctorizedFactor2< R, T1, T2 >, gtsam::GeneralSFMFactor< CAMERA, LANDMARK >, gtsam::GeneralSFMFactor2< CALIBRATION >, gtsam::GenericProjectionFactor< POSE, LANDMARK, CALIBRATION >, gtsam::SmartFactorBase< CAMERA >, gtsam::SmartFactorBase< PinholePose< CALIBRATION > >, gtsam::SmartProjectionFactor< CAMERA >, gtsam::SmartProjectionFactor< PinholePose< CALIBRATION > >, gtsam::SmartProjectionPoseFactor< CALIBRATION >, gtsam::SmartProjectionRigFactor< CAMERA >, and gtsam::TriangulationFactor< CAMERA >.

◆ error() [1/2]

double NonlinearFactor::error ( const HybridValues c) const
overridevirtual

All factor types need to implement an error function.

In factor graphs, this is the negative log-likelihood.

Reimplemented from gtsam::Factor.

◆ error() [2/2]

◆ linearize()

◆ print()

◆ rekey() [1/2]

NonlinearFactor::shared_ptr NonlinearFactor::rekey ( const KeyVector new_keys) const
virtual

Clones a factor and fully replaces its keys.

Parameters
new_keysis the full replacement set of keys

Reimplemented in gtsam::LinearContainerFactor.

◆ rekey() [2/2]

NonlinearFactor::shared_ptr NonlinearFactor::rekey ( const std::map< Key, Key > &  rekey_mapping) const
virtual

Creates a shared_ptr clone of the factor with different keys using a map from old->new keys.

Reimplemented in gtsam::LinearContainerFactor.

◆ sendable()

virtual bool gtsam::NonlinearFactor::sendable ( ) const
inlinevirtual

Should the factor be evaluated in the same thread as the caller This is to enable factors that has shared states (like the Python GIL lock)

Reimplemented in gtsam::CustomFactor.


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