PartialPriorFactor.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 
18 #pragma once
19 
21 #include <gtsam/base/Lie.h>
22 
23 namespace gtsam {
24 
37  template<class VALUE>
38  class PartialPriorFactor: public NoiseModelFactor1<VALUE> {
39 
40  public:
41  typedef VALUE T;
42 
43  protected:
44  // Concept checks on the variable type - currently requires Lie
46 
47  typedef NoiseModelFactor1<VALUE> Base;
48  typedef PartialPriorFactor<VALUE> This;
49 
51  std::vector<size_t> indices_;
52 
55 
61  : Base(model, key) {}
62 
63  public:
64 
65  ~PartialPriorFactor() override {}
66 
68  PartialPriorFactor(Key key, size_t idx, double prior, const SharedNoiseModel& model) :
69  Base(model, key),
70  prior_((Vector(1) << prior).finished()),
71  indices_(1, idx) {
72  assert(model->dim() == 1);
73  }
74 
76  PartialPriorFactor(Key key, const std::vector<size_t>& indices, const Vector& prior,
77  const SharedNoiseModel& model) :
78  Base(model, key),
79  prior_(prior),
80  indices_(indices) {
81  assert((size_t)prior_.size() == indices_.size());
82  assert(model->dim() == (size_t)prior.size());
83  }
84 
87  return boost::static_pointer_cast<gtsam::NonlinearFactor>(
89 
93  void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
94  Base::print(s, keyFormatter);
95  gtsam::print(prior_, "prior");
96  }
97 
99  bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
100  const This *e = dynamic_cast<const This*> (&expected);
101  return e != nullptr && Base::equals(*e, tol) &&
102  gtsam::equal_with_abs_tol(this->prior_, e->prior_, tol) &&
103  this->indices_ == e->indices_;
104  }
105 
109  Vector evaluateError(const T& p, boost::optional<Matrix&> H = boost::none) const override {
111 
112  // If the Rot3 Cayley map is used, Rot3::LocalCoordinates will throw a runtime error
113  // when asked to compute the Jacobian matrix (see Rot3M.cpp).
114  #ifdef GTSAM_ROT3_EXPMAP
115  const Vector full_tangent = T::LocalCoordinates(p, H ? &H_local : nullptr);
116  #else
117  const Vector full_tangent = T::Logmap(p, H ? &H_local : nullptr);
118  #endif
119 
120  if (H) {
121  (*H) = Matrix::Zero(indices_.size(), T::dimension);
122  for (size_t i = 0; i < indices_.size(); ++i) {
123  (*H).row(i) = H_local.row(indices_.at(i));
124  }
125  }
126  // Select relevant parameters from the tangent vector.
127  Vector partial_tangent = Vector::Zero(indices_.size());
128  for (size_t i = 0; i < indices_.size(); ++i) {
129  partial_tangent(i) = full_tangent(indices_.at(i));
130  }
131 
132  return partial_tangent - prior_;
133  }
134 
135  // access
136  const Vector& prior() const { return prior_; }
137  const std::vector<size_t>& indices() const { return indices_; }
138 
139  private:
141  friend class boost::serialization::access;
142  template<class ARCHIVE>
143  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
144  ar & boost::serialization::make_nvp("NoiseModelFactor1",
145  boost::serialization::base_object<Base>(*this));
146  ar & BOOST_SERIALIZATION_NVP(prior_);
147  ar & BOOST_SERIALIZATION_NVP(indices_);
148  // ar & BOOST_SERIALIZATION_NVP(H_);
149  }
150  }; // \class PartialPriorFactor
151 
152 }
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
PartialPriorFactor(Key key, size_t idx, double prior, const SharedNoiseModel &model)
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
noiseModel::Diagonal::shared_ptr model
Matrix expected
Definition: testMatrix.cpp:974
PartialPriorFactor(Key key, const std::vector< size_t > &indices, const Vector &prior, const SharedNoiseModel &model)
void serialize(ARCHIVE &ar, const unsigned int)
Definition: Half.h:150
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
std::vector< size_t > indices_
Indices of the measured tangent space parameters.
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
Vector evaluateError(const T &p, boost::optional< Matrix & > H=boost::none) const override
Eigen::VectorXd Vector
Definition: Vector.h:38
gtsam::NonlinearFactor::shared_ptr clone() const override
boost::shared_ptr< This > shared_ptr
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
PartialPriorFactor< VALUE > This
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
PartialPriorFactor(Key key, const SharedNoiseModel &model)
Base class and basic functions for Lie types.
const Vector & prior() const
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
Definition: base/Matrix.h:84
traits
Definition: chartTesting.h:28
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
#define GTSAM_CONCEPT_LIE_TYPE(T)
Definition: Lie.h:356
Vector prior_
Measurement on tangent space parameters, in compressed form.
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Non-linear factor base classes.
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
float * p
const G double tol
Definition: Group.h:83
The matrix class, also used for vectors and row-vectors.
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
const std::vector< size_t > & indices() const
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:734


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:23