Implementation of a discrete-conditioned hybrid factor. More...
#include <HybridNonlinearFactor.h>
Classes | |
struct | ConstructorHelper |
Public Types | |
using | Base = HybridFactor |
using | FactorValuePairs = DecisionTree< Key, NonlinearFactorValuePair > |
typedef for DecisionTree which has Keys as node labels and pairs of NoiseModelFactor & an arbitrary scalar as leaf nodes. More... | |
using | shared_ptr = std::shared_ptr< HybridNonlinearFactor > |
using | sharedFactor = std::shared_ptr< NoiseModelFactor > |
using | This = HybridNonlinearFactor |
![]() | |
typedef Factor | Base |
Our base class. More... | |
enum | Category { Category::None, Category::Discrete, Category::Continuous, Category::Hybrid } |
Enum to help with categorizing hybrid factors. More... | |
typedef std::shared_ptr< HybridFactor > | shared_ptr |
shared_ptr to this class More... | |
typedef HybridFactor | This |
This class. More... | |
![]() | |
typedef KeyVector::const_iterator | const_iterator |
Const iterator over keys. More... | |
typedef KeyVector::iterator | iterator |
Iterator over keys. More... | |
Public Member Functions | |
Constructors | |
HybridNonlinearFactor ()=default | |
Default constructor, mainly for serialization. More... | |
HybridNonlinearFactor (const DiscreteKey &discreteKey, const std::vector< NoiseModelFactor::shared_ptr > &factors) | |
Construct a new HybridNonlinearFactor on a single discrete key, providing the factors for each mode m as a vector of factors ϕ_m(x). The value ϕ(x,m) for the factor is simply ϕ_m(x). More... | |
HybridNonlinearFactor (const DiscreteKey &discreteKey, const std::vector< NonlinearFactorValuePair > &pairs) | |
Construct a new HybridNonlinearFactor on a single discrete key, including a scalar error value for each mode m. The factors and scalars are provided as a vector of pairs (ϕ_m(x), E_m). The value ϕ(x,m) for the factor is now ϕ_m(x) + E_m. More... | |
HybridNonlinearFactor (const DiscreteKeys &discreteKeys, const FactorValuePairs &factors) | |
Construct a new HybridNonlinearFactor on a several discrete keys M, including a scalar error value for each assignment m. The factors and scalars are provided as a DecisionTree<Key> of pairs (ϕ_M(x), E_M). The value ϕ(x,M) for the factor is again ϕ_m(x) + E_m. More... | |
AlgebraicDecisionTree< Key > | errorTree (const Values &continuousValues) const |
Compute error of the HybridNonlinearFactor as a tree. More... | |
double | error (const Values &continuousValues, const DiscreteValues &assignment) const |
Compute error of factor given both continuous and discrete values. More... | |
double | error (const HybridValues &values) const override |
Compute error of factor given hybrid values. More... | |
size_t | dim () const |
Get the dimension of the factor (number of rows on linearization). Returns the dimension of the first component factor. More... | |
Testable | |
void | print (const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override |
print to stdout More... | |
bool | equals (const HybridFactor &other, double tol=1e-9) const override |
Check equality. More... | |
Standard API | |
const FactorValuePairs & | factors () const |
Getter for NonlinearFactor decision tree. More... | |
GaussianFactor::shared_ptr | linearize (const Values &continuousValues, const DiscreteValues &assignment) const |
std::shared_ptr< HybridGaussianFactor > | linearize (const Values &continuousValues) const |
Linearize all the continuous factors to get a HybridGaussianFactor. More... | |
HybridNonlinearFactor::shared_ptr | prune (const DecisionTreeFactor &discreteProbs) const |
Prune this factor based on the discrete probabilities. More... | |
std::shared_ptr< Factor > | restrict (const DiscreteValues &assignment) const override |
Restrict the factor to the given discrete values. More... | |
![]() | |
HybridFactor ()=default | |
HybridFactor (const KeyVector &keys) | |
Construct hybrid factor from continuous keys. More... | |
HybridFactor (const DiscreteKeys &discreteKeys) | |
Construct hybrid factor from discrete keys. More... | |
HybridFactor (const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys) | |
Construct a new Hybrid Factor object. More... | |
bool | isDiscrete () const |
True if this is a factor of discrete variables only. More... | |
bool | isContinuous () const |
True if this is a factor of continuous variables only. More... | |
bool | isHybrid () const |
True is this is a Discrete-Continuous factor. More... | |
size_t | nrContinuous () const |
Return the number of continuous variables in this factor. More... | |
const DiscreteKeys & | discreteKeys () const |
Return the discrete keys for this factor. More... | |
const KeyVector & | continuousKeys () const |
Return only the continuous keys for this factor. More... | |
![]() | |
virtual | ~Factor ()=default |
Default destructor. More... | |
bool | empty () const |
Whether the factor is empty (involves zero variables). More... | |
Key | front () const |
First key. More... | |
Key | back () const |
Last key. More... | |
const_iterator | find (Key key) const |
find More... | |
const KeyVector & | keys () const |
Access the factor's involved variable keys. More... | |
const_iterator | begin () const |
const_iterator | end () const |
size_t | size () const |
virtual void | printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const |
print only keys More... | |
bool | equals (const This &other, double tol=1e-9) const |
check equality More... | |
KeyVector & | keys () |
iterator | begin () |
iterator | end () |
Private Member Functions | |
AlgebraicDecisionTree< Key > | errorTree (const VectorValues &continuousValues) const override |
HybridFactor method implementation. Should not be used. More... | |
HybridNonlinearFactor (const ConstructorHelper &helper) | |
Private Attributes | |
FactorValuePairs | factors_ |
Decision tree of nonlinear factors indexed by discrete keys. More... | |
Additional Inherited Members | |
![]() | |
Factor () | |
template<typename CONTAINER > | |
Factor (const CONTAINER &keys) | |
template<typename ITERATOR > | |
Factor (ITERATOR first, ITERATOR last) | |
![]() | |
template<typename CONTAINER > | |
static Factor | FromKeys (const CONTAINER &keys) |
template<typename ITERATOR > | |
static Factor | FromIterators (ITERATOR first, ITERATOR last) |
![]() | |
KeyVector | continuousKeys_ |
Record continuous keys for book-keeping. More... | |
DiscreteKeys | discreteKeys_ |
![]() | |
KeyVector | keys_ |
The keys involved in this factor. More... | |
Implementation of a discrete-conditioned hybrid factor.
Implements a joint discrete-continuous factor where the discrete variable serves to "select" a hybrid component corresponding to a NoiseModelFactor.
This class stores all factors as HybridFactors which can then be typecast to one of (NoiseModelFactor, GaussianFactor) which can then be checked to perform the correct operation.
In factor graphs the error function typically returns 0.5*|h(x)-z|^2, i.e., the negative log-likelihood for a Gaussian noise model. In hybrid factor graphs we allow adding an arbitrary scalar dependent on the discrete assignment. For example, adding a 70/30 mode probability is supported by providing the scalars $-log(.7)$ and $-log(.3)$. Note that adding a common constant will not make any difference in the optimization, so $-log(70)$ and $-log(30)$ work just as well.
Definition at line 58 of file HybridNonlinearFactor.h.
Definition at line 60 of file HybridNonlinearFactor.h.
typedef for DecisionTree which has Keys as node labels and pairs of NoiseModelFactor & an arbitrary scalar as leaf nodes.
Definition at line 69 of file HybridNonlinearFactor.h.
using gtsam::HybridNonlinearFactor::shared_ptr = std::shared_ptr<HybridNonlinearFactor> |
Definition at line 62 of file HybridNonlinearFactor.h.
using gtsam::HybridNonlinearFactor::sharedFactor = std::shared_ptr<NoiseModelFactor> |
Definition at line 63 of file HybridNonlinearFactor.h.
Definition at line 61 of file HybridNonlinearFactor.h.
|
default |
Default constructor, mainly for serialization.
gtsam::HybridNonlinearFactor::HybridNonlinearFactor | ( | const DiscreteKey & | discreteKey, |
const std::vector< NoiseModelFactor::shared_ptr > & | factors | ||
) |
Construct a new HybridNonlinearFactor on a single discrete key, providing the factors for each mode m as a vector of factors ϕ_m(x). The value ϕ(x,m) for the factor is simply ϕ_m(x).
discreteKey | The discrete key for the "mode", indexing components. |
factors | Vector of gaussian factors, one for each mode. |
Definition at line 81 of file HybridNonlinearFactor.cpp.
gtsam::HybridNonlinearFactor::HybridNonlinearFactor | ( | const DiscreteKey & | discreteKey, |
const std::vector< NonlinearFactorValuePair > & | pairs | ||
) |
Construct a new HybridNonlinearFactor on a single discrete key, including a scalar error value for each mode m. The factors and scalars are provided as a vector of pairs (ϕ_m(x), E_m). The value ϕ(x,m) for the factor is now ϕ_m(x) + E_m.
discreteKey | The discrete key for the "mode", indexing components. |
pairs | Vector of gaussian factor-scalar pairs, one per mode. |
Definition at line 86 of file HybridNonlinearFactor.cpp.
gtsam::HybridNonlinearFactor::HybridNonlinearFactor | ( | const DiscreteKeys & | discreteKeys, |
const FactorValuePairs & | factors | ||
) |
Construct a new HybridNonlinearFactor on a several discrete keys M, including a scalar error value for each assignment m. The factors and scalars are provided as a DecisionTree<Key> of pairs (ϕ_M(x), E_M). The value ϕ(x,M) for the factor is again ϕ_m(x) + E_m.
discreteKeys | Discrete variables and their cardinalities. |
factors | The decision tree of nonlinear factor/scalar pairs. |
Definition at line 91 of file HybridNonlinearFactor.cpp.
|
private |
Definition at line 77 of file HybridNonlinearFactor.cpp.
size_t gtsam::HybridNonlinearFactor::dim | ( | ) | const |
Get the dimension of the factor (number of rows on linearization). Returns the dimension of the first component factor.
Definition at line 125 of file HybridNonlinearFactor.cpp.
|
overridevirtual |
Check equality.
Reimplemented from gtsam::HybridFactor.
Definition at line 151 of file HybridNonlinearFactor.cpp.
|
overridevirtual |
Compute error of factor given hybrid values.
values | The continuous Values and the discrete assignment. |
Reimplemented from gtsam::Factor.
Definition at line 120 of file HybridNonlinearFactor.cpp.
double gtsam::HybridNonlinearFactor::error | ( | const Values & | continuousValues, |
const DiscreteValues & | assignment | ||
) | const |
Compute error of factor given both continuous and discrete values.
Definition at line 109 of file HybridNonlinearFactor.cpp.
AlgebraicDecisionTree< Key > gtsam::HybridNonlinearFactor::errorTree | ( | const Values & | continuousValues | ) | const |
Compute error of the HybridNonlinearFactor as a tree.
continuousValues | The continuous values for which to compute the error. |
Definition at line 96 of file HybridNonlinearFactor.cpp.
|
inlineoverrideprivatevirtual |
HybridFactor method implementation. Should not be used.
Implements gtsam::HybridFactor.
Definition at line 76 of file HybridNonlinearFactor.h.
|
inline |
Getter for NonlinearFactor decision tree.
Definition at line 176 of file HybridNonlinearFactor.h.
std::shared_ptr< HybridGaussianFactor > gtsam::HybridNonlinearFactor::linearize | ( | const Values & | continuousValues | ) | const |
Linearize all the continuous factors to get a HybridGaussianFactor.
Definition at line 184 of file HybridNonlinearFactor.cpp.
GaussianFactor::shared_ptr gtsam::HybridNonlinearFactor::linearize | ( | const Values & | continuousValues, |
const DiscreteValues & | assignment | ||
) | const |
Linearize specific nonlinear factors based on the assignment in discreteValues.
Definition at line 176 of file HybridNonlinearFactor.cpp.
|
overridevirtual |
print to stdout
Reimplemented from gtsam::HybridFactor.
Definition at line 132 of file HybridNonlinearFactor.cpp.
HybridNonlinearFactor::shared_ptr gtsam::HybridNonlinearFactor::prune | ( | const DecisionTreeFactor & | discreteProbs | ) | const |
Prune this factor based on the discrete probabilities.
Definition at line 215 of file HybridNonlinearFactor.cpp.
|
overridevirtual |
Restrict the factor to the given discrete values.
Implements gtsam::HybridFactor.
Definition at line 245 of file HybridNonlinearFactor.cpp.
|
private |
Decision tree of nonlinear factors indexed by discrete keys.
Definition at line 73 of file HybridNonlinearFactor.h.