FrobeniusFactor.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010-2019, 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 
19 #pragma once
20 
21 #include <gtsam/geometry/Rot2.h>
22 #include <gtsam/geometry/Rot3.h>
23 #include <gtsam/geometry/SOn.h>
25 
26 namespace gtsam {
27 
42 GTSAM_EXPORT SharedNoiseModel
44  bool defaultToUnit = true);
45 
50 template <class Rot>
51 class GTSAM_EXPORT FrobeniusPrior : public NoiseModelFactor1<Rot> {
52  enum { Dim = Rot::VectorN2::RowsAtCompileTime };
53  using MatrixNN = typename Rot::MatrixNN;
55 
56  public:
59  const SharedNoiseModel& model = nullptr)
61  vecM_ << Eigen::Map<const Matrix>(M.data(), Dim, 1);
62  }
63 
66  boost::optional<Matrix&> H = boost::none) const override {
67  return R.vec(H) - vecM_; // Jacobian is computed only when needed.
68  }
69 };
70 
75 template <class Rot>
76 class GTSAM_EXPORT FrobeniusFactor : public NoiseModelFactor2<Rot, Rot> {
77  enum { Dim = Rot::VectorN2::RowsAtCompileTime };
78 
79  public:
81  FrobeniusFactor(Key j1, Key j2, const SharedNoiseModel& model = nullptr)
83  j2) {}
84 
86  Vector evaluateError(const Rot& R1, const Rot& R2,
87  boost::optional<Matrix&> H1 = boost::none,
88  boost::optional<Matrix&> H2 = boost::none) const override {
89  Vector error = R2.vec(H2) - R1.vec(H1);
90  if (H1) *H1 = -*H1;
91  return error;
92  }
93 };
94 
101 template <class Rot>
102 class GTSAM_EXPORT FrobeniusBetweenFactor : public NoiseModelFactor2<Rot, Rot> {
106  enum { Dim = Rot::VectorN2::RowsAtCompileTime };
107 
108  public:
111 
114  const SharedNoiseModel& model = nullptr)
116  ConvertNoiseModel(model, Dim), j1, j2),
117  R12_(R12),
118  R2hat_H_R1_(R12.inverse().AdjointMap()) {}
119 
123 
125  void
126  print(const std::string &s,
127  const KeyFormatter &keyFormatter = DefaultKeyFormatter) const override {
128  std::cout << s << "FrobeniusBetweenFactor<" << demangle(typeid(Rot).name())
129  << ">(" << keyFormatter(this->key1()) << ","
130  << keyFormatter(this->key2()) << ")\n";
131  traits<Rot>::Print(R12_, " R12: ");
132  this->noiseModel_->print(" noise model: ");
133  }
134 
137  double tol = 1e-9) const override {
138  auto e = dynamic_cast<const FrobeniusBetweenFactor *>(&expected);
139  return e != nullptr && NoiseModelFactor2<Rot, Rot>::equals(*e, tol) &&
140  traits<Rot>::Equals(this->R12_, e->R12_, tol);
141  }
142 
146 
148  Vector evaluateError(const Rot& R1, const Rot& R2,
149  boost::optional<Matrix&> H1 = boost::none,
150  boost::optional<Matrix&> H2 = boost::none) const override {
151  const Rot R2hat = R1.compose(R12_);
153  Vector error = R2.vec(H2) - R2hat.vec(H1 ? &vec_H_R2hat : nullptr);
154  if (H1) *H1 = -vec_H_R2hat * R2hat_H_R1_;
155  return error;
156  }
158 };
159 
160 } // namespace gtsam
FrobeniusPrior(Key j, const MatrixNN &M, const SharedNoiseModel &model=nullptr)
Constructor.
SharedNoiseModel ConvertNoiseModel(const SharedNoiseModel &model, size_t d, bool defaultToUnit)
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:38
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Vector evaluateError(const Rot &R, boost::optional< Matrix & > H=boost::none) const override
Error is just Frobenius norm between Rot element and vectorized matrix M.
Eigen::Matrix< double, Dim, 1 > vecM_
vectorized matrix to approximate
noiseModel::Diagonal::shared_ptr model
Matrix expected
Definition: testMatrix.cpp:974
typename Rot::MatrixNN MatrixNN
int n
typename std::conditional< d==2, Rot2, Rot3 >::type Rot
Rot2 R(Rot2::fromAngle(0.1))
Vector evaluateError(const Rot &R1, const Rot &R2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
Error is just Frobenius norm between rotation matrices.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const Symbol key1('v', 1)
Eigen::VectorXd Vector
Definition: Vector.h:38
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
assert equality up to a tolerance
std::string demangle(const char *name)
Pretty print Value type name.
Definition: types.cpp:37
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
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
Q R1(Eigen::AngleAxisd(1, Q_z_axis))
traits
Definition: chartTesting.h:28
Eigen::Matrix< double, Rot::dimension, Rot::dimension > R2hat_H_R1_
fixed derivative of R2hat wrpt R1
Vector evaluateError(const Rot &R1, const Rot &R2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const override
Error is Frobenius norm between R1*R12 and R2.
Rot R12_
measured rotation between R1 and R2
Non-linear factor base classes.
FrobeniusFactor(Key j1, Key j2, const SharedNoiseModel &model=nullptr)
Constructor.
const Symbol key2('v', 2)
FrobeniusBetweenFactor(Key j1, Key j2, const Rot &R12, const SharedNoiseModel &model=nullptr)
Construct from two keys and measured rotation.
static double error
Definition: testRot3.cpp:39
const G double tol
Definition: Group.h:83
Q R2(Eigen::AngleAxisd(2, Vector3(0, 1, 0)))
EIGEN_DEVICE_FUNC const InverseReturnType inverse() const
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
print with optional string
N*N matrix representation of SO(N). N can be Eigen::Dynamic.
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
void Print(const CONTAINER &keys, const string &s, const KeyFormatter &keyFormatter)
Definition: Key.cpp:59
std::ptrdiff_t j
2D rotation
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734
3D rotation represented as a rotation matrix or quaternion


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:04