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 #include <cassert>
24 
25 namespace gtsam {
26 
39  template<class VALUE>
40  class PartialPriorFactor: public NoiseModelFactorN<VALUE> {
41 
42  public:
43  typedef VALUE T;
44 
45  protected:
46  // Concept checks on the variable type - currently requires Lie
48 
51 
53  std::vector<size_t> indices_;
54 
60  : Base(model, key) {}
61 
62  public:
63 
64  // Provide access to the Matrix& version of evaluateError:
65  using Base::evaluateError;
66 
69 
71  PartialPriorFactor(Key key, size_t idx, double prior, const SharedNoiseModel& model) :
72  Base(model, key),
73  prior_((Vector(1) << prior).finished()),
74  indices_(1, idx) {
75  assert(model->dim() == 1);
76  }
77 
79  PartialPriorFactor(Key key, const std::vector<size_t>& indices, const Vector& prior,
80  const SharedNoiseModel& model) :
81  Base(model, key),
82  prior_(prior),
83  indices_(indices) {
84  assert((size_t)prior_.size() == indices_.size());
85  assert(model->dim() == (size_t)prior.size());
86  }
87 
88  ~PartialPriorFactor() override {}
89 
92  return std::static_pointer_cast<gtsam::NonlinearFactor>(
94 
98  void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
99  Base::print(s, keyFormatter);
100  gtsam::print(prior_, "prior");
101  }
102 
104  bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
105  const This *e = dynamic_cast<const This*> (&expected);
106  return e != nullptr && Base::equals(*e, tol) &&
107  gtsam::equal_with_abs_tol(this->prior_, e->prior_, tol) &&
108  this->indices_ == e->indices_;
109  }
110 
114  Vector evaluateError(const T& p, OptionalMatrixType H) const override {
116 
117  // If the Rot3 Cayley map is used, Rot3::LocalCoordinates will throw a runtime error
118  // when asked to compute the Jacobian matrix (see Rot3M.cpp).
119  #ifdef GTSAM_ROT3_EXPMAP
120  const Vector full_tangent = T::LocalCoordinates(p, H ? &H_local : nullptr);
121  #else
122  const Vector full_tangent = T::Logmap(p, H ? &H_local : nullptr);
123  #endif
124 
125  if (H) {
126  (*H) = Matrix::Zero(indices_.size(), T::dimension);
127  for (size_t i = 0; i < indices_.size(); ++i) {
128  (*H).row(i) = H_local.row(indices_.at(i));
129  }
130  }
131  // Select relevant parameters from the tangent vector.
132  Vector partial_tangent = Vector::Zero(indices_.size());
133  for (size_t i = 0; i < indices_.size(); ++i) {
134  partial_tangent(i) = full_tangent(indices_.at(i));
135  }
136 
137  return partial_tangent - prior_;
138  }
139 
140  // access
141  const Vector& prior() const { return prior_; }
142  const std::vector<size_t>& indices() const { return indices_; }
143 
144  private:
145 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
146 
147  friend class boost::serialization::access;
148  template<class ARCHIVE>
149  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
150  // NoiseModelFactor1 instead of NoiseModelFactorN for backward compatibility
151  ar & boost::serialization::make_nvp("NoiseModelFactor1",
152  boost::serialization::base_object<Base>(*this));
153  ar & BOOST_SERIALIZATION_NVP(prior_);
154  ar & BOOST_SERIALIZATION_NVP(indices_);
155  // ar & BOOST_SERIALIZATION_NVP(H_);
156  }
157 #endif
158  }; // \class PartialPriorFactor
159 
160 }
H
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
Definition: gnuplot_common_settings.hh:74
gtsam::NonlinearFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: NonlinearFactor.h:79
gtsam::PartialPriorFactor::indices_
std::vector< size_t > indices_
Indices of the measured tangent space parameters.
Definition: PartialPriorFactor.h:53
gtsam::PartialPriorFactor::~PartialPriorFactor
~PartialPriorFactor() override
Definition: PartialPriorFactor.h:88
gtsam::PartialPriorFactor::equals
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Definition: PartialPriorFactor.h:104
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::PartialPriorFactor::PartialPriorFactor
PartialPriorFactor(Key key, size_t idx, double prior, const SharedNoiseModel &model)
Definition: PartialPriorFactor.h:71
gtsam::PartialPriorFactor::print
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: PartialPriorFactor.h:98
gtsam::NoiseModelFactorN< VALUE >::evaluateError
virtual Vector evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const=0
gtsam::equal_with_abs_tol
bool equal_with_abs_tol(const Eigen::DenseBase< MATRIX > &A, const Eigen::DenseBase< MATRIX > &B, double tol=1e-9)
Definition: base/Matrix.h:80
gtsam::Factor
Definition: Factor.h:70
gtsam::Vector
Eigen::VectorXd Vector
Definition: Vector.h:39
gtsam::PartialPriorFactor::This
PartialPriorFactor< VALUE > This
Definition: PartialPriorFactor.h:50
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
GTSAM_CONCEPT_LIE_TYPE
#define GTSAM_CONCEPT_LIE_TYPE(T)
Definition: Lie.h:373
Eigen::internal::VALUE
@ VALUE
Definition: SpecialFunctionsImpl.h:729
gtsam::PartialPriorFactor::prior_
Vector prior_
Measurement on tangent space parameters, in compressed form.
Definition: PartialPriorFactor.h:52
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:156
gtsam::KeyFormatter
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
gtsam::NoiseModelFactorN
Definition: NonlinearFactor.h:432
gtsam::NoiseModelFactor::print
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: NonlinearFactor.cpp:74
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::NoiseModelFactor::equals
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
Definition: NonlinearFactor.cpp:82
gtsam::SharedNoiseModel
noiseModel::Base::shared_ptr SharedNoiseModel
Definition: NoiseModel.h:762
gtsam::PartialPriorFactor::PartialPriorFactor
PartialPriorFactor()
Definition: PartialPriorFactor.h:68
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
gtsam::PartialPriorFactor::PartialPriorFactor
PartialPriorFactor(Key key, const std::vector< size_t > &indices, const Vector &prior, const SharedNoiseModel &model)
Definition: PartialPriorFactor.h:79
gtsam::PoseRTV
Definition: PoseRTV.h:23
NonlinearFactor.h
Non-linear factor base classes.
gtsam::PartialPriorFactor::prior
const Vector & prior() const
Definition: PartialPriorFactor.h:141
Lie.h
Base class and basic functions for Lie types.
gtsam
traits
Definition: SFMdata.h:40
gtsam::PartialPriorFactor::T
VALUE T
Definition: PartialPriorFactor.h:43
gtsam::PartialPriorFactor::evaluateError
Vector evaluateError(const T &p, OptionalMatrixType H) const override
Definition: PartialPriorFactor.h:114
std
Definition: BFloat16.h:88
gtsam::NonlinearFactor
Definition: NonlinearFactor.h:69
p
float * p
Definition: Tutorial_Map_using.cpp:9
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::OptionalMatrixType
Matrix * OptionalMatrixType
Definition: NonlinearFactor.h:56
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
gtsam::NoiseModelFactorN< VALUE >::key
Key key() const
Definition: NonlinearFactor.h:583
gtsam::PartialPriorFactor::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: PartialPriorFactor.h:91
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
gtsam::PartialPriorFactor
Definition: PartialPriorFactor.h:40
gtsam::PartialPriorFactor::indices
const std::vector< size_t > & indices() const
Definition: PartialPriorFactor.h:142


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:12:40