betweenFactorSwitchable.h
Go to the documentation of this file.
1 /*
2  * betweenFactorSwitchable.h
3  *
4  * Created on: 02.08.2012
5  * Author: niko
6  */
7 
8 #ifndef BETWEENFACTORSWITCHABLE_H_
9 #define BETWEENFACTORSWITCHABLE_H_
10 
12 
13 #include <iostream>
14 using std::cout;
15 using std::endl;
16 
17 #include "switchVariableLinear.h"
18 #include "switchVariableSigmoid.h"
19 
20 
21 namespace vertigo {
22 
23  template<class VALUE>
24  class BetweenFactorSwitchableLinear : public gtsam::NoiseModelFactor3<VALUE, VALUE, SwitchVariableLinear>
25  {
26  public:
31 
32  gtsam::Vector evaluateError(const VALUE& p1, const VALUE& p2, const SwitchVariableLinear& s,
33 #if GTSAM_VERSION_NUMERIC >= 40300
34  OptionalMatrixType H1 = OptionalNone,
35  OptionalMatrixType H2 = OptionalNone,
36  OptionalMatrixType H3 = OptionalNone) const
37 #else
38  boost::optional<gtsam::Matrix&> H1 = boost::none,
39  boost::optional<gtsam::Matrix&> H2 = boost::none,
40  boost::optional<gtsam::Matrix&> H3 = boost::none) const
41 #endif
42  {
43 
44  // calculate error
46  error *= s.value();
47 
48  // handle derivatives
49  if (H1) *H1 = *H1 * s.value();
50  if (H2) *H2 = *H2 * s.value();
51  if (H3) *H3 = error;
52 
53  return error;
54  };
55 
56  private:
58 
59  };
60 
61 
62 
63  template<class VALUE>
64  class BetweenFactorSwitchableSigmoid : public gtsam::NoiseModelFactor3<VALUE, VALUE, SwitchVariableSigmoid>
65  {
66  public:
71 
72  gtsam::Vector evaluateError(const VALUE& p1, const VALUE& p2, const SwitchVariableSigmoid& s,
73 #if GTSAM_VERSION_NUMERIC >= 40300
74  OptionalMatrixType H1 = OptionalNone,
75  OptionalMatrixType H2 = OptionalNone,
76  OptionalMatrixType H3 = OptionalNone) const
77 #else
78  boost::optional<gtsam::Matrix&> H1 = boost::none,
79  boost::optional<gtsam::Matrix&> H2 = boost::none,
80  boost::optional<gtsam::Matrix&> H3 = boost::none) const
81 #endif
82  {
83 
84  // calculate error
86 
87 
88  double w = sigmoid(s.value());
89  error *= w;
90 
91  // handle derivatives
92  if (H1) *H1 = *H1 * w;
93  if (H2) *H2 = *H2 * w;
94  if (H3) *H3 = error /* (w*(1.0-w))*/; // sig(x)*(1-sig(x)) is the derivative of sig(x) wrt. x
95 
96  return error;
97  };
98 
99  private:
101 
102  double sigmoid(double x) const {
103  return 1.0/(1.0+exp(-x));
104  }
105  };
106 
107 }
108 
109 #endif /* BETWEENFACTORSWITCHABLE_H_ */
key1
const Symbol key1( 'v', 1)
w
RowVector3d w
s
RealScalar s
vertigo::BetweenFactorSwitchableSigmoid::evaluateError
gtsam::Vector evaluateError(const VALUE &p1, const VALUE &p2, const SwitchVariableSigmoid &s, boost::optional< gtsam::Matrix & > H1=boost::none, boost::optional< gtsam::Matrix & > H2=boost::none, boost::optional< gtsam::Matrix & > H3=boost::none) const
Definition: betweenFactorSwitchable.h:72
switchVariableLinear.h
gtsam::Vector
Eigen::VectorXd Vector
VALUE
VALUE
vertigo::BetweenFactorSwitchableLinear::evaluateError
gtsam::Vector evaluateError(const VALUE &p1, const VALUE &p2, const SwitchVariableLinear &s, boost::optional< gtsam::Matrix & > H1=boost::none, boost::optional< gtsam::Matrix & > H2=boost::none, boost::optional< gtsam::Matrix & > H3=boost::none) const
Definition: betweenFactorSwitchable.h:32
key2
const Symbol key2( 'v', 2)
vertigo::BetweenFactorSwitchableLinear
Definition: betweenFactorSwitchable.h:24
vertigo::BetweenFactorSwitchableSigmoid::sigmoid
double sigmoid(double x) const
Definition: betweenFactorSwitchable.h:102
NonlinearFactor.h
vertigo::BetweenFactorSwitchableSigmoid::BetweenFactorSwitchableSigmoid
BetweenFactorSwitchableSigmoid()
Definition: betweenFactorSwitchable.h:67
vertigo::SwitchVariableSigmoid
Definition: switchVariableSigmoid.h:22
p2
p2
key3
const Symbol key3( 'v', 3)
vertigo::BetweenFactorSwitchableLinear::betweenFactor
gtsam::BetweenFactor< VALUE > betweenFactor
Definition: betweenFactorSwitchable.h:54
vertigo::BetweenFactorSwitchableSigmoid::BetweenFactorSwitchableSigmoid
BetweenFactorSwitchableSigmoid(gtsam::Key key1, gtsam::Key key2, gtsam::Key key3, const VALUE &measured, const gtsam::SharedNoiseModel &model)
Definition: betweenFactorSwitchable.h:68
vertigo::BetweenFactorSwitchableLinear::BetweenFactorSwitchableLinear
BetweenFactorSwitchableLinear(gtsam::Key key1, gtsam::Key key2, gtsam::Key key3, const VALUE &measured, const gtsam::SharedNoiseModel &model)
Definition: betweenFactorSwitchable.h:28
x
x
error
void error(const char *str)
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
p1
Vector3f p1
vertigo::BetweenFactorSwitchableSigmoid::betweenFactor
gtsam::BetweenFactor< VALUE > betweenFactor
Definition: betweenFactorSwitchable.h:97
gtsam
vertigo::BetweenFactorSwitchableSigmoid
Definition: betweenFactorSwitchable.h:64
vertigo
Definition: betweenFactorMaxMix.h:24
gtsam::BetweenFactor::evaluateError
Vector evaluateError(const T &p1, const T &p2, OptionalMatrixType H1, OptionalMatrixType H2) const override
NoiseModelFactor3
#define NoiseModelFactor3
vertigo::SwitchVariableLinear
Definition: switchVariableLinear.h:22
switchVariableSigmoid.h
measured
measured
vertigo::BetweenFactorSwitchableLinear::BetweenFactorSwitchableLinear
BetweenFactorSwitchableLinear()
Definition: betweenFactorSwitchable.h:27
Eigen.Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor >
gtsam::Key
std::uint64_t Key
glm::exp
GLM_FUNC_DECL genType exp(genType const &x)
trace.model
model
Definition: trace.py:4
gtsam::BetweenFactor< VALUE >


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:06