AntiFactor.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 
16 #pragma once
17 
18 #include <ostream>
19 
22 
23 namespace gtsam {
24 
31  class AntiFactor: public NonlinearFactor {
32 
33  private:
34 
35  typedef AntiFactor This;
38 
40 
41  public:
42 
43  // shorthand for a smart pointer to a factor
44  typedef std::shared_ptr<AntiFactor> shared_ptr;
45 
48 
51 
52  ~AntiFactor() override {}
53 
56  return std::static_pointer_cast<gtsam::NonlinearFactor>(
58 
62  void print(const std::string& s, const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
63  std::cout << s << "AntiFactor version of:" << std::endl;
64  factor_->print(s, keyFormatter);
65  }
66 
68  bool equals(const NonlinearFactor& expected, double tol=1e-9) const override {
69  const This *e = dynamic_cast<const This*> (&expected);
70  return e != nullptr && Base::equals(*e, tol) && this->factor_->equals(*e->factor_, tol);
71  }
72 
80  double error(const Values& c) const override { return -factor_->error(c); }
81 
83  size_t dim() const override { return factor_->dim(); }
84 
89  bool active(const Values& c) const override { return factor_->active(c); }
90 
97  std::shared_ptr<GaussianFactor> linearize(const Values& c) const override {
98 
99  // Generate the linearized factor from the contained nonlinear factor
100  GaussianFactor::shared_ptr gaussianFactor = factor_->linearize(c);
101 
102  // return the negated version of the factor
103  return gaussianFactor->negate();
104  }
105 
106 
107  private:
108 
109 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
110 
111  friend class boost::serialization::access;
112  template<class ARCHIVE>
113  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
114  ar & boost::serialization::make_nvp("AntiFactor",
115  boost::serialization::base_object<Base>(*this));
116  ar & BOOST_SERIALIZATION_NVP(factor_);
117  }
118 #endif
119  }; // \class AntiFactor
120 
121 }
gtsam::NonlinearFactor::shared_ptr
std::shared_ptr< This > shared_ptr
Definition: NonlinearFactor.h:79
gtsam::AntiFactor::clone
gtsam::NonlinearFactor::shared_ptr clone() const override
Definition: AntiFactor.h:55
gtsam::AntiFactor::AntiFactor
AntiFactor()
Definition: AntiFactor.h:47
gtsam::AntiFactor::AntiFactor
AntiFactor(NonlinearFactor::shared_ptr factor)
Definition: AntiFactor.h:50
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
gtsam::AntiFactor::shared_ptr
std::shared_ptr< AntiFactor > shared_ptr
Definition: AntiFactor.h:44
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::NonlinearFactor::equals
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Definition: NonlinearFactor.cpp:47
gtsam::AntiFactor::active
bool active(const Values &c) const override
Definition: AntiFactor.h:89
gtsam::Factor
Definition: Factor.h:70
gtsam::AntiFactor::Base
NonlinearFactor Base
Definition: AntiFactor.h:36
gtsam::AntiFactor::~AntiFactor
~AntiFactor() override
Definition: AntiFactor.h:52
gtsam::AntiFactor::dim
size_t dim() const override
Definition: AntiFactor.h:83
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
pruning_fixture::factor
DecisionTreeFactor factor(D &C &B &A, "0.0 0.0 0.0 0.60658897 0.61241912 0.61241969 0.61247685 0.61247742 0.0 " "0.0 0.0 0.99995287 1.0 1.0 1.0 1.0")
gtsam::AntiFactor::print
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Definition: AntiFactor.h:62
gtsam::AntiFactor::error
double error(const Values &c) const override
Definition: AntiFactor.h:80
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::GaussianFactor::shared_ptr
std::shared_ptr< This > shared_ptr
shared_ptr to this class
Definition: GaussianFactor.h:42
gtsam::AntiFactor::factor_
sharedFactor factor_
Definition: AntiFactor.h:39
gtsam::AntiFactor::linearize
std::shared_ptr< GaussianFactor > linearize(const Values &c) const override
Definition: AntiFactor.h:97
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::AntiFactor::equals
bool equals(const NonlinearFactor &expected, double tol=1e-9) const override
Definition: AntiFactor.h:68
gtsam::AntiFactor::sharedFactor
NonlinearFactor::shared_ptr sharedFactor
Definition: AntiFactor.h:37
NonlinearFactor.h
Non-linear factor base classes.
gtsam
traits
Definition: SFMdata.h:40
gtsam::Values
Definition: Values.h:65
gtsam::Factor::keys
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition: Factor.h:143
gtsam::NonlinearFactor
Definition: NonlinearFactor.h:69
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::AntiFactor::This
AntiFactor This
Definition: AntiFactor.h:35
GaussianFactor.h
A factor with a quadratic error function - a Gaussian.
gtsam::AntiFactor
Definition: AntiFactor.h:31


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:06