24#include <gtsam/dllexport.h>
26#include <boost/serialization/extended_type_info.hpp>
27#include <boost/serialization/nvp.hpp>
28#include <boost/serialization/version.hpp>
29#include <boost/serialization/optional.hpp>
30#include <boost/serialization/shared_ptr.hpp>
31#include <boost/serialization/singleton.hpp>
61 enum ReweightScheme { Scalar, Block };
62 typedef boost::shared_ptr<Base> shared_ptr;
70 Base(
const ReweightScheme reweight = Block) : reweight_(reweight) {}
84 virtual double loss(
double distance)
const {
return 0; };
94 virtual double weight(
double distance)
const = 0;
96 virtual void print(
const std::string &s)
const = 0;
97 virtual bool equals(
const Base &expected,
double tol = 1e-8)
const = 0;
99 double sqrtWeight(
double distance)
const {
return std::sqrt(weight(distance)); }
103 Vector weight(
const Vector &error)
const;
107 return weight(error).cwiseSqrt();
112 void reweight(Vector &error)
const;
113 void reweight(std::vector<Matrix> &A, Vector &error)
const;
114 void reweight(Matrix &A, Vector &error)
const;
115 void reweight(Matrix &A1, Matrix &A2, Vector &error)
const;
116 void reweight(Matrix &A1, Matrix &A2, Matrix &A3, Vector &error)
const;
120 friend class boost::serialization::access;
121 template <
class ARCHIVE>
122 void serialize(ARCHIVE &ar,
const unsigned int ) {
123 ar &BOOST_SERIALIZATION_NVP(reweight_);
130 typedef boost::shared_ptr<Null> shared_ptr;
132 Null(
const ReweightScheme reweight = Block) :
Base(reweight) {}
134 double weight(
double )
const override {
return 1.0; }
135 double loss(
double distance)
const override {
return 0.5 * distance * distance; }
136 void print(
const std::string &s)
const override;
137 bool equals(
const Base & ,
double )
const override {
return true; }
138 static shared_ptr Create();
142 friend class boost::serialization::access;
143 template <
class ARCHIVE>
144 void serialize(ARCHIVE &ar,
const unsigned int ) {
145 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
155 typedef boost::shared_ptr<Fair> shared_ptr;
157 Fair(
double c = 1.3998,
const ReweightScheme reweight = Block);
158 double weight(
double distance)
const override;
159 double loss(
double distance)
const override;
160 void print(
const std::string &s)
const override;
161 bool equals(
const Base &expected,
double tol = 1e-8)
const override;
162 static shared_ptr Create(
double c,
const ReweightScheme reweight = Block);
166 friend class boost::serialization::access;
167 template <
class ARCHIVE>
168 void serialize(ARCHIVE &ar,
const unsigned int ) {
169 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
170 ar &BOOST_SERIALIZATION_NVP(c_);
180 typedef boost::shared_ptr<Huber> shared_ptr;
182 Huber(
double k = 1.345,
const ReweightScheme reweight = Block);
183 double weight(
double distance)
const override;
184 double loss(
double distance)
const override;
185 void print(
const std::string &s)
const override;
186 bool equals(
const Base &expected,
double tol = 1e-8)
const override;
187 static shared_ptr Create(
double k,
const ReweightScheme reweight = Block);
191 friend class boost::serialization::access;
192 template <
class ARCHIVE>
193 void serialize(ARCHIVE &ar,
const unsigned int ) {
194 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
195 ar &BOOST_SERIALIZATION_NVP(k_);
207 double k_, ksquared_;
210 typedef boost::shared_ptr<Cauchy> shared_ptr;
212 Cauchy(
double k = 0.1,
const ReweightScheme reweight = Block);
213 double weight(
double distance)
const override;
214 double loss(
double distance)
const override;
215 void print(
const std::string &s)
const override;
216 bool equals(
const Base &expected,
double tol = 1e-8)
const override;
217 static shared_ptr Create(
double k,
const ReweightScheme reweight = Block);
221 friend class boost::serialization::access;
222 template <
class ARCHIVE>
223 void serialize(ARCHIVE &ar,
const unsigned int ) {
224 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
225 ar &BOOST_SERIALIZATION_NVP(k_);
232 double c_, csquared_;
235 typedef boost::shared_ptr<Tukey> shared_ptr;
237 Tukey(
double c = 4.6851,
const ReweightScheme reweight = Block);
238 double weight(
double distance)
const override;
239 double loss(
double distance)
const override;
240 void print(
const std::string &s)
const override;
241 bool equals(
const Base &expected,
double tol = 1e-8)
const override;
242 static shared_ptr Create(
double k,
const ReweightScheme reweight = Block);
246 friend class boost::serialization::access;
247 template <
class ARCHIVE>
248 void serialize(ARCHIVE &ar,
const unsigned int ) {
249 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
250 ar &BOOST_SERIALIZATION_NVP(c_);
257 double c_, csquared_;
260 typedef boost::shared_ptr<Welsch> shared_ptr;
262 Welsch(
double c = 2.9846,
const ReweightScheme reweight = Block);
263 double weight(
double distance)
const override;
264 double loss(
double distance)
const override;
265 void print(
const std::string &s)
const override;
266 bool equals(
const Base &expected,
double tol = 1e-8)
const override;
267 static shared_ptr Create(
double k,
const ReweightScheme reweight = Block);
271 friend class boost::serialization::access;
272 template <
class ARCHIVE>
273 void serialize(ARCHIVE &ar,
const unsigned int ) {
274 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
275 ar &BOOST_SERIALIZATION_NVP(c_);
287 typedef boost::shared_ptr<GemanMcClure> shared_ptr;
289 GemanMcClure(
double c = 1.0,
const ReweightScheme reweight = Block);
291 double weight(
double distance)
const override;
292 double loss(
double distance)
const override;
293 void print(
const std::string &s)
const override;
294 bool equals(
const Base &expected,
double tol = 1e-8)
const override;
295 static shared_ptr Create(
double k,
const ReweightScheme reweight = Block);
302 friend class boost::serialization::access;
303 template <
class ARCHIVE>
304 void serialize(ARCHIVE &ar,
const unsigned int ) {
305 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
306 ar &BOOST_SERIALIZATION_NVP(c_);
317 typedef boost::shared_ptr<DCS> shared_ptr;
319 DCS(
double c = 1.0,
const ReweightScheme reweight = Block);
321 double weight(
double distance)
const override;
322 double loss(
double distance)
const override;
323 void print(
const std::string &s)
const override;
324 bool equals(
const Base &expected,
double tol = 1e-8)
const override;
325 static shared_ptr Create(
double k,
const ReweightScheme reweight = Block);
332 friend class boost::serialization::access;
333 template <
class ARCHIVE>
334 void serialize(ARCHIVE &ar,
const unsigned int ) {
335 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
336 ar &BOOST_SERIALIZATION_NVP(c_);
351 typedef boost::shared_ptr<L2WithDeadZone> shared_ptr;
353 L2WithDeadZone(
double k = 1.0,
const ReweightScheme reweight = Block);
354 double weight(
double distance)
const override;
355 double loss(
double distance)
const override;
356 void print(
const std::string &s)
const override;
357 bool equals(
const Base &expected,
double tol = 1e-8)
const override;
358 static shared_ptr Create(
double k,
const ReweightScheme reweight = Block);
362 friend class boost::serialization::access;
363 template <
class ARCHIVE>
364 void serialize(ARCHIVE &ar,
const unsigned int ) {
365 ar &BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Base);
366 ar &BOOST_SERIALIZATION_NVP(k_);
typedef and functions to augment Eigen's MatrixXd
Concept check for values that can be used in unit tests.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:112
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
Template to create a binary predicate.
Definition: Testable.h:111
Definition: LossFunctions.h:59
ReweightScheme reweight_
the rows can be weighted independently according to the error or uniformly with the norm of the right...
Definition: LossFunctions.h:67
Vector sqrtWeight(const Vector &error) const
square root version of the weight function
Definition: LossFunctions.h:106
Null class should behave as Gaussian.
Definition: LossFunctions.h:128
Fair implements the "Fair" robust error model (Zhang97ivc)
Definition: LossFunctions.h:150
Huber implements the "Huber" robust error model (Zhang97ivc)
Definition: LossFunctions.h:175
Cauchy implements the "Cauchy" robust error model (Lee2013IROS).
Definition: LossFunctions.h:205
Tukey implements the "Tukey" robust error model (Zhang97ivc)
Definition: LossFunctions.h:230
Welsch implements the "Welsch" robust error model (Zhang97ivc)
Definition: LossFunctions.h:255
GemanMcClure implements the "Geman-McClure" robust error model (Zhang97ivc).
Definition: LossFunctions.h:285
DCS implements the Dynamic Covariance Scaling robust error model from the paper Robust Map Optimizati...
Definition: LossFunctions.h:315
L2WithDeadZone implements a standard L2 penalty, but with a dead zone of width 2*k,...
Definition: LossFunctions.h:346