betweenFactorMaxMix.h
Go to the documentation of this file.
1 /*
2  * betweenFactorMaxMix.h
3  *
4  * Created on: 14.08.2012
5  * Author: niko
6  */
7 
8 #ifndef BETWEENFACTORMAXMIX_H_
9 #define BETWEENFACTORMAXMIX_H_
10 
12 #include <Eigen/Eigen>
13 #include <gtsam/config.h>
14 
15 #if GTSAM_VERSION_NUMERIC >= 40100
16 namespace gtsam {
17 gtsam::Matrix inverse(const gtsam::Matrix & matrix)
18 {
19  return matrix.inverse();
20 }
21 }
22 #endif
23 
24 namespace vertigo {
25 
26  template<class VALUE>
27  class BetweenFactorMaxMix : public gtsam::NoiseModelFactor2<VALUE, VALUE>
28  {
29  public:
31  BetweenFactorMaxMix(gtsam::Key key1, gtsam::Key key2, const VALUE& measured, const gtsam::SharedNoiseModel& model, const gtsam::SharedNoiseModel& model2, double w)
34 
35  gtsam::Vector evaluateError(const VALUE& p1, const VALUE& p2,
36  boost::optional<gtsam::Matrix&> H1 = boost::none,
37  boost::optional<gtsam::Matrix&> H2 = boost::none) const
38  {
39 
40  // calculate error
42 
43 
44 
45  // which hypothesis is more likely
46  double m1 = this->noiseModel_->distance(error);
47  gtsam::noiseModel::Gaussian::shared_ptr g1 = this->noiseModel_;
48  gtsam::Matrix info1(g1->R().transpose()*g1->R());
49  double nu1 = 1.0/sqrt(gtsam::inverse(info1).determinant());
50  double l1 = nu1 * exp(-0.5*m1);
51 
52 #if GTSAM_VERSION_NUMERIC >= 40100
53  double m2 = nullHypothesisModel->squaredMahalanobisDistance(error);
54 #else
55  double m2 = nullHypothesisModel->distance(error);
56 #endif
58  gtsam::Matrix info2(g2->R().transpose()*g2->R());
59  double nu2 = 1.0/sqrt(gtsam::inverse(info2).determinant());
60  double l2 = nu2 * exp(-0.5*m2);
61 
62  // if the null hypothesis is more likely, than proceed by applying the weight ...
63  if (l2>l1) {
64  if (H1) *H1 = *H1 * weight;
65  if (H2) *H2 = *H2 * weight;
66  error *= sqrt(weight);
67  }
68 
69  return error;
70  };
71 
72  private:
75  double weight;
76 
77  };
78 }
79 
80 
81 #endif /* BETWEENFACTORMAXMIX_H_ */
key1
const Symbol key1( 'v', 1)
w
RowVector3d w
l2
gtsam::Key l2
g1
Pose3 g1(Rot3(), Point3(100.0, 0.0, 300.0))
model2
noiseModel::Unit::shared_ptr model2
m1
Matrix3d m1
gtsam::Matrix
Eigen::MatrixXd Matrix
vertigo::BetweenFactorMaxMix::BetweenFactorMaxMix
BetweenFactorMaxMix()
Definition: betweenFactorMaxMix.h:30
vertigo::BetweenFactorMaxMix::nullHypothesisModel
gtsam::SharedNoiseModel nullHypothesisModel
Definition: betweenFactorMaxMix.h:74
gtsam::noiseModel::Gaussian::shared_ptr
std::shared_ptr< Gaussian > shared_ptr
gtsam::Vector
Eigen::VectorXd Vector
determinant
void determinant(const MatrixType &m)
VALUE
VALUE
m2
MatrixType m2(n_dims)
key2
const Symbol key2( 'v', 2)
glm::sqrt
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
g2
Pose3 g2(g1.expmap(h *V1_g1))
p2
p2
error
void error(const char *str)
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
p1
Vector3f p1
vertigo::BetweenFactorMaxMix::weight
double weight
Definition: betweenFactorMaxMix.h:75
gtsam
vertigo
Definition: betweenFactorMaxMix.h:24
gtsam::BetweenFactor::evaluateError
Vector evaluateError(const T &p1, const T &p2, OptionalMatrixType H1, OptionalMatrixType H2) const override
l1
gtsam::Key l1
NoiseModel.h
measured
measured
vertigo::BetweenFactorMaxMix::BetweenFactorMaxMix
BetweenFactorMaxMix(gtsam::Key key1, gtsam::Key key2, const VALUE &measured, const gtsam::SharedNoiseModel &model, const gtsam::SharedNoiseModel &model2, double w)
Definition: betweenFactorMaxMix.h:31
vertigo::BetweenFactorMaxMix
Definition: betweenFactorMaxMix.h:27
NoiseModelFactor2
#define NoiseModelFactor2
matrix
Map< const Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(const T *data, int rows, int cols, int stride)
vertigo::BetweenFactorMaxMix::evaluateError
gtsam::Vector evaluateError(const VALUE &p1, const VALUE &p2, boost::optional< gtsam::Matrix & > H1=boost::none, boost::optional< gtsam::Matrix & > H2=boost::none) const
Definition: betweenFactorMaxMix.h:35
gtsam::Key
std::uint64_t Key
vertigo::BetweenFactorMaxMix::betweenFactor
gtsam::BetweenFactor< VALUE > betweenFactor
Definition: betweenFactorMaxMix.h:70
glm::exp
GLM_FUNC_DECL genType exp(genType const &x)
trace.model
model
Definition: trace.py:4
glm::inverse
GLM_FUNC_DECL matType< T, P > inverse(matType< T, P > const &m)
gtsam::BetweenFactor< VALUE >


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