gtsam
Loading...
Searching...
No Matches
GaussMarkov1stOrderFactor.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
17#pragma once
18
23#include <gtsam/base/Testable.h>
24#include <gtsam/base/Lie.h>
25
26#include <ostream>
27
28namespace gtsam {
29
30/*
31 * - The 1st order GaussMarkov factor relates two keys of the same type. This relation is given via
32 * key_2 = exp(-1/tau*delta_t) * key1 + w_d
33 * where tau is the time constant and delta_t is the time difference between the two keys.
34 * w_d is the equivalent discrete noise, whose covariance is calculated from the continuous noise model and delta_t.
35 * - w_d is approximated as a Gaussian noise.
36 * - In the multi-dimensional case, tau is a vector, and the above equation is applied on each element
37 * in the state (represented by keys), using the appropriate time constant in the vector tau.
38 */
39
40/*
41 * A class for a measurement predicted by "GaussMarkov1stOrderFactor(config[key1],config[key2])"
42 * KEY1::Value is the Lie Group type
43 * T is the measurement type, by default the same
44 */
45template<class VALUE>
47 : public NoiseModelFactorT<typename traits<VALUE>::TangentVector, VALUE,
48 VALUE> {
49
50private:
51
54 Base;
55 using ErrorVector = typename traits<VALUE>::TangentVector;
56
57 double dt_;
58 Vector tau_;
59
60public:
61
62 // Provide access to the Matrix& version of evaluateError:
64
65 // shorthand for a smart pointer to a factor
66 typedef typename std::shared_ptr<GaussMarkov1stOrderFactor> shared_ptr;
67
70
72 GaussMarkov1stOrderFactor(const Key& key1, const Key& key2, double delta_t, Vector tau,
73 const SharedGaussian& model) :
74 Base(calcDiscreteNoiseModel(model, delta_t), key1, key2), dt_(delta_t), tau_(tau) {
75 }
76
77 ~GaussMarkov1stOrderFactor() override {}
78
80
82 void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
83 std::cout << s << "GaussMarkov1stOrderFactor("
84 << keyFormatter(this->key1()) << ","
85 << keyFormatter(this->key2()) << ")\n";
86 this->noiseModel_->print(" noise model");
87 }
88
90 bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
91 const This *e = dynamic_cast<const This*> (&expected);
92 return e != nullptr && Base::equals(*e, tol);
93 }
94
96
98 ErrorVector evaluateError(const VALUE& p1, const VALUE& p2,
100 OptionalMatrixType H2) const override {
101
102 Vector v1( traits<VALUE>::Logmap(p1) );
103 Vector v2( traits<VALUE>::Logmap(p2) );
104
105 Vector alpha(tau_.size());
106 Vector alpha_v1(tau_.size());
107 for(int i=0; i<tau_.size(); i++){
108 alpha(i) = exp(- 1/tau_(i)*dt_ );
109 alpha_v1(i) = alpha(i) * v1(i);
110 }
111
112 Vector hx(v2 - alpha_v1);
113
114 if(H1) *H1 = -1 * alpha.asDiagonal();
115 if(H2) *H2 = Matrix::Identity(v2.size(),v2.size());
116
117 return hx;
118 }
119
120private:
121
122#if GTSAM_ENABLE_BOOST_SERIALIZATION
124 friend class boost::serialization::access;
125 template<class ARCHIVE>
126 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
127 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
128 ar & BOOST_SERIALIZATION_NVP(dt_);
129 ar & BOOST_SERIALIZATION_NVP(tau_);
130 }
131#endif
132
133 SharedGaussian calcDiscreteNoiseModel(const SharedGaussian& model, double delta_t){
134 /* Q_d (approx)= Q * delta_t */
135 /* In practice, square root of the information matrix is represented, so that:
136 * R_d (approx)= R / sqrt(delta_t)
137 * */
138 noiseModel::Gaussian::shared_ptr gaussian_model = std::dynamic_pointer_cast<noiseModel::Gaussian>(model);
139 SharedGaussian model_d(noiseModel::Gaussian::SqrtInformation(gaussian_model->R()/sqrt(delta_t)));
140 return model_d;
141 }
142
143}; // \class GaussMarkov1stOrderFactor
144
146template<class VALUE> struct traits<GaussMarkov1stOrderFactor<VALUE> > :
147 public Testable<GaussMarkov1stOrderFactor<VALUE> > {
148};
149
150}
Concept check for values that can be used in unit tests.
Base class and basic functions for Lie types.
A factor with a quadratic error function - a Gaussian.
Base class for noise model factors with N variables.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
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
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
bool equals(const This &other, double tol=1e-9) const
check equality
Definition Factor.cpp:42
static shared_ptr SqrtInformation(const Matrix &R, bool smart=true)
A Gaussian noise model created by specifying a square root information matrix.
Definition NoiseModel.cpp:85
virtual OutputVec evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const =0
Override evaluateError to finish implementing an n-way factor.
Nonlinear factor base class.
Definition NonlinearFactor.h:70
Definition GaussMarkov1stOrderFactor.h:48
GaussMarkov1stOrderFactor()
default constructor - only use for serialization
Definition GaussMarkov1stOrderFactor.h:69
GaussMarkov1stOrderFactor(const Key &key1, const Key &key2, double delta_t, Vector tau, const SharedGaussian &model)
Constructor.
Definition GaussMarkov1stOrderFactor.h:72
ErrorVector evaluateError(const VALUE &p1, const VALUE &p2, OptionalMatrixType H1, OptionalMatrixType H2) const override
implement functions needed to derive from Factor
Definition GaussMarkov1stOrderFactor.h:98
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
implement functions needed for Testable
Definition GaussMarkov1stOrderFactor.h:82
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
equals
Definition GaussMarkov1stOrderFactor.h:90