29 #include <boost/serialization/base_object.hpp> 30 #include <boost/assign/list_of.hpp> 32 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4 33 #define ADD_CLONE_NONLINEAR_FACTOR(Derived) \ 34 virtual gtsam::NonlinearFactor::shared_ptr clone() const { \ 35 return boost::static_pointer_cast<gtsam::NonlinearFactor>( \ 36 gtsam::NonlinearFactor::shared_ptr(new Derived(*this))); } 41 using boost::assign::cref_list_of;
60 typedef boost::shared_ptr<This> shared_ptr;
71 template<
typename CONTAINER>
80 virtual void print(
const std::string& s =
"",
81 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
98 virtual double error(
const Values& c)
const = 0;
101 virtual size_t dim()
const = 0;
116 virtual boost::shared_ptr<GaussianFactor>
117 linearize(
const Values& c)
const = 0;
127 throw std::runtime_error(
"NonlinearFactor::clone(): Attempting to clone factor with no clone() implemented!");
136 shared_ptr rekey(
const std::map<Key,Key>& rekey_mapping)
const;
142 shared_ptr rekey(
const KeyVector& new_keys)
const;
184 template<
typename CONTAINER>
186 Base(keys), noiseModel_(noiseModel) {}
198 virtual void print(
const std::string& s =
"",
199 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const;
205 virtual size_t dim()
const {
206 return noiseModel_->dim();
220 virtual Vector unwhitenedError(
const Values& x,
221 boost::optional<std::vector<Matrix>&> H = boost::none)
const = 0;
227 Vector whitenedError(
const Values& c)
const;
235 virtual double error(
const Values& c)
const;
242 boost::shared_ptr<GaussianFactor> linearize(
const Values& x)
const;
244 #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4 254 friend class boost::serialization::access;
255 template<
class ARCHIVE>
256 void serialize(ARCHIVE & ar,
const unsigned int ) {
257 ar & boost::serialization::make_nvp(
"NonlinearFactor",
258 boost::serialization::base_object<Base>(*
this));
259 ar & BOOST_SERIALIZATION_NVP(noiseModel_);
275 template<
class VALUE>
295 inline Key key()
const {
return keys_[0]; }
317 return Vector::Zero(this->
dim());
326 virtual Vector
evaluateError(
const X& x, boost::optional<Matrix&> H =
327 boost::none)
const = 0;
332 friend class boost::serialization::access;
333 template<
class ARCHIVE>
334 void serialize(ARCHIVE & ar,
const unsigned int ) {
335 ar & boost::serialization::make_nvp(
"NoiseModelFactor",
336 boost::serialization::base_object<Base>(*
this));
344 template<
class VALUE1,
class VALUE2>
378 inline Key key2()
const {
return keys_[1]; }
385 const X2& x2 = x.
at<X2>(
keys_[1]);
392 return Vector::Zero(this->
dim());
402 evaluateError(
const X1&,
const X2&, boost::optional<Matrix&> H1 =
403 boost::none, boost::optional<Matrix&> H2 = boost::none)
const = 0;
408 friend class boost::serialization::access;
409 template<
class ARCHIVE>
410 void serialize(ARCHIVE & ar,
const unsigned int ) {
411 ar & boost::serialization::make_nvp(
"NoiseModelFactor",
412 boost::serialization::base_object<Base>(*
this));
419 template<
class VALUE1,
class VALUE2,
class VALUE3>
455 inline Key key2()
const {
return keys_[1]; }
456 inline Key key3()
const {
return keys_[2]; }
467 return Vector::Zero(this->
dim());
478 boost::optional<Matrix&> H1 = boost::none,
479 boost::optional<Matrix&> H2 = boost::none,
480 boost::optional<Matrix&> H3 = boost::none)
const = 0;
485 friend class boost::serialization::access;
486 template<
class ARCHIVE>
487 void serialize(ARCHIVE & ar,
const unsigned int ) {
488 ar & boost::serialization::make_nvp(
"NoiseModelFactor",
489 boost::serialization::base_object<Base>(*
this));
496 template<
class VALUE1,
class VALUE2,
class VALUE3,
class VALUE4>
534 inline Key key2()
const {
return keys_[1]; }
535 inline Key key3()
const {
return keys_[2]; }
536 inline Key key4()
const {
return keys_[3]; }
547 return Vector::Zero(this->
dim());
558 boost::optional<Matrix&> H1 = boost::none,
559 boost::optional<Matrix&> H2 = boost::none,
560 boost::optional<Matrix&> H3 = boost::none,
561 boost::optional<Matrix&> H4 = boost::none)
const = 0;
566 friend class boost::serialization::access;
567 template<
class ARCHIVE>
568 void serialize(ARCHIVE & ar,
const unsigned int ) {
569 ar & boost::serialization::make_nvp(
"NoiseModelFactor",
570 boost::serialization::base_object<Base>(*
this));
577 template<
class VALUE1,
class VALUE2,
class VALUE3,
class VALUE4,
class VALUE5>
617 inline Key key2()
const {
return keys_[1]; }
618 inline Key key3()
const {
return keys_[2]; }
619 inline Key key4()
const {
return keys_[3]; }
620 inline Key key5()
const {
return keys_[4]; }
631 return Vector::Zero(this->
dim());
641 evaluateError(
const X1&,
const X2&,
const X3&,
const X4&,
const X5&,
642 boost::optional<Matrix&> H1 = boost::none,
643 boost::optional<Matrix&> H2 = boost::none,
644 boost::optional<Matrix&> H3 = boost::none,
645 boost::optional<Matrix&> H4 = boost::none,
646 boost::optional<Matrix&> H5 = boost::none)
const = 0;
651 friend class boost::serialization::access;
652 template<
class ARCHIVE>
653 void serialize(ARCHIVE & ar,
const unsigned int ) {
654 ar & boost::serialization::make_nvp(
"NoiseModelFactor",
655 boost::serialization::base_object<Base>(*
this));
662 template<
class VALUE1,
class VALUE2,
class VALUE3,
class VALUE4,
class VALUE5,
class VALUE6>
704 inline Key key2()
const {
return keys_[1]; }
705 inline Key key3()
const {
return keys_[2]; }
706 inline Key key4()
const {
return keys_[3]; }
707 inline Key key5()
const {
return keys_[4]; }
708 inline Key key6()
const {
return keys_[5]; }
715 return evaluateError(x.
at<
X1>(
keys_[0]), x.
at<X2>(
keys_[1]), x.
at<
X3>(
keys_[2]), x.
at<X4>(
keys_[3]), x.
at<
X5>(
keys_[4]), x.
at<
X6>(
keys_[5]), (*H)[0], (*H)[1], (*H)[2], (*H)[3], (*H)[4], (*H)[5]);
719 return Vector::Zero(this->
dim());
729 evaluateError(
const X1&,
const X2&,
const X3&,
const X4&,
const X5&,
const X6&,
730 boost::optional<Matrix&> H1 = boost::none,
731 boost::optional<Matrix&> H2 = boost::none,
732 boost::optional<Matrix&> H3 = boost::none,
733 boost::optional<Matrix&> H4 = boost::none,
734 boost::optional<Matrix&> H5 = boost::none,
735 boost::optional<Matrix&> H6 = boost::none)
const = 0;
740 friend class boost::serialization::access;
741 template<
class ARCHIVE>
742 void serialize(ARCHIVE & ar,
const unsigned int ) {
743 ar & boost::serialization::make_nvp(
"NoiseModelFactor",
744 boost::serialization::base_object<Base>(*
this));
virtual shared_ptr clone() const
Creates a shared_ptr clone of the factor - needs to be specialized to allow for subclasses.
Definition: NonlinearFactor.h:125
NoiseModelFactor3(const SharedNoiseModel &noiseModel, Key j1, Key j2, Key j3)
Constructor.
Definition: NonlinearFactor.h:448
This is the base class for all factor types.
Definition: Factor.h:54
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
A convenient base class for creating your own NoiseModelFactor with 2 variables.
Definition: NonlinearFactor.h:345
virtual Vector evaluateError(const X1 &, const X2 &, const X3 &, const X4 &, const X5 &, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none, boost::optional< Matrix & > H4=boost::none, boost::optional< Matrix & > H5=boost::none) const =0
Override this method to finish implementing a 5-way factor.
NoiseModelFactor3()
Default Constructor for I/O.
Definition: NonlinearFactor.h:439
virtual Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const
Calls the 2-key specific version of evaluateError, which is pure virtual so must be implemented in th...
Definition: NonlinearFactor.h:382
ValueType at(Key j) const
Retrieve a variable by key j.
Definition: Values-inl.h:342
virtual Vector evaluateError(const X1 &, const X2 &, const X3 &, const X4 &, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none, boost::optional< Matrix & > H4=boost::none) const =0
Override this method to finish implementing a 4-way factor.
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
Represents an infinite plane in 3D, which is composed of a planar normal and its perpendicular distan...
Definition: OrientedPlane3.h:35
NoiseModelFactor1(const SharedNoiseModel &noiseModel, Key key1)
Constructor.
Definition: NonlinearFactor.h:302
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
boost::shared_ptr< This > shared_ptr
Noise model.
Definition: NonlinearFactor.h:173
Template to create a binary predicate.
Definition: Testable.h:110
NoiseModelFactor4(const SharedNoiseModel &noiseModel, Key j1, Key j2, Key j3, Key j4)
Constructor.
Definition: NonlinearFactor.h:527
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
virtual ~NoiseModelFactor()
Destructor.
Definition: NonlinearFactor.h:179
NoiseModelFactor2()
Default Constructor for I/O.
Definition: NonlinearFactor.h:363
NonlinearFactor()
Default constructor for I/O only.
Definition: NonlinearFactor.h:66
virtual Vector evaluateError(const X1 &, const X2 &, const X3 &, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none) const =0
Override this method to finish implementing a trinary factor.
virtual Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const
Calls the 3-key specific version of evaluateError, which is pure virtual so must be implemented in th...
Definition: NonlinearFactor.h:460
A convenient base class for creating your own NoiseModelFactor with 4 variables.
Definition: NonlinearFactor.h:497
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
A convenient base class for creating your own NoiseModelFactor with 1 variable.
Definition: NonlinearFactor.h:276
virtual Vector evaluateError(const X &x, boost::optional< Matrix & > H=boost::none) const =0
Override this method to finish implementing a unary factor.
Nonlinear factor base class.
Definition: NonlinearFactor.h:50
const SharedNoiseModel & noiseModel() const
access to the noise model
Definition: NonlinearFactor.h:210
Key key1() const
methods to retrieve both keys
Definition: NonlinearFactor.h:377
A convenient base class for creating your own NoiseModelFactor with 6 variables.
Definition: NonlinearFactor.h:663
virtual Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const
Calls the 6-key specific version of evaluateError, which is pure virtual so must be implemented in th...
Definition: NonlinearFactor.h:712
A convenient base class for creating your own NoiseModelFactor with 3 variables.
Definition: NonlinearFactor.h:420
virtual Vector evaluateError(const X1 &, const X2 &, const X3 &, const X4 &, const X5 &, const X6 &, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none, boost::optional< Matrix & > H3=boost::none, boost::optional< Matrix & > H4=boost::none, boost::optional< Matrix & > H5=boost::none, boost::optional< Matrix & > H6=boost::none) const =0
Override this method to finish implementing a 6-way factor.
virtual Vector evaluateError(const X1 &, const X2 &, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const =0
Override this method to finish implementing a binary factor.
A nonlinear sum-of-squares factor with a zero-mean noise model implementing the density Templated on...
Definition: NonlinearFactor.h:161
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:56
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
virtual Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const
Calls the 5-key specific version of evaluateError, which is pure virtual so must be implemented in th...
Definition: NonlinearFactor.h:624
A non-templated config holding any types of Manifold-group elements.
NoiseModelFactor6(const SharedNoiseModel &noiseModel, Key j1, Key j2, Key j3, Key j4, Key j5, Key j6)
Constructor.
Definition: NonlinearFactor.h:697
NonlinearFactor(const CONTAINER &keys)
Constructor from a collection of the keys involved in this factor.
Definition: NonlinearFactor.h:72
A convenient base class for creating your own NoiseModelFactor with 5 variables.
Definition: NonlinearFactor.h:578
NoiseModelFactor6()
Default Constructor for I/O.
Definition: NonlinearFactor.h:685
NoiseModelFactor5(const SharedNoiseModel &noiseModel, Key j1, Key j2, Key j3, Key j4, Key j5)
Constructor.
Definition: NonlinearFactor.h:610
NoiseModelFactor(const SharedNoiseModel &noiseModel)
Constructor - only for subclasses, as this does not set keys.
Definition: NonlinearFactor.h:193
virtual bool active(const Values &) const
Checks whether a factor should be used based on a set of values.
Definition: NonlinearFactor.h:113
Key key1() const
methods to retrieve keys
Definition: NonlinearFactor.h:616
The base class for all factors.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Key key1() const
methods to retrieve keys
Definition: NonlinearFactor.h:454
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:1072
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:72
Key key1() const
methods to retrieve keys
Definition: NonlinearFactor.h:703
virtual Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const
Calls the 1-key specific version of evaluateError, which is pure virtual so must be implemented in th...
Definition: NonlinearFactor.h:308
NoiseModelFactor(const SharedNoiseModel &noiseModel, const CONTAINER &keys)
Constructor.
Definition: NonlinearFactor.h:185
virtual Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const
Calls the 4-key specific version of evaluateError, which is pure virtual so must be implemented in th...
Definition: NonlinearFactor.h:540
NoiseModelFactor5()
Default Constructor for I/O.
Definition: NonlinearFactor.h:599
NoiseModelFactor1()
Default constructor for I/O only.
Definition: NonlinearFactor.h:291
NoiseModelFactor2(const SharedNoiseModel &noiseModel, Key j1, Key j2)
Constructor.
Definition: NonlinearFactor.h:371
Special class for optional Jacobian arguments.
virtual size_t dim() const
get the dimension of the factor (number of rows on linearization)
Definition: NonlinearFactor.h:205
Key key1() const
methods to retrieve keys
Definition: NonlinearFactor.h:533
NoiseModelFactor()
Default constructor for I/O only.
Definition: NonlinearFactor.h:176
virtual ~NonlinearFactor()
Destructor.
Definition: NonlinearFactor.h:90
NoiseModelFactor4()
Default Constructor for I/O.
Definition: NonlinearFactor.h:517