From 2f8238a9566a4ce31dba4f004e4ec3f95cde0281 Mon Sep 17 00:00:00 2001 From: Alice Anderson Date: Wed, 28 Aug 2019 17:28:10 -0700 Subject: [PATCH 1/3] Fixed spelling for Welsch and added to gtsam.h --- gtsam/linear/NoiseModel.cpp | 16 ++++++++-------- gtsam/linear/NoiseModel.h | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gtsam/linear/NoiseModel.cpp b/gtsam/linear/NoiseModel.cpp index 4d9c7883b9..fac9f9ecd1 100644 --- a/gtsam/linear/NoiseModel.cpp +++ b/gtsam/linear/NoiseModel.cpp @@ -808,22 +808,22 @@ Tukey::shared_ptr Tukey::Create(double c, const ReweightScheme reweight) { } /* ************************************************************************* */ -// Welsh +// Welsch /* ************************************************************************* */ -Welsh::Welsh(double c, const ReweightScheme reweight) : Base(reweight), c_(c), csquared_(c * c) {} +Welsch::Welsch(double c, const ReweightScheme reweight) : Base(reweight), c_(c), csquared_(c * c) {} -void Welsh::print(const std::string &s="") const { - std::cout << s << ": Welsh (" << c_ << ")" << std::endl; +void Welsch::print(const std::string &s="") const { + std::cout << s << ": Welsch (" << c_ << ")" << std::endl; } -bool Welsh::equals(const Base &expected, double tol) const { - const Welsh* p = dynamic_cast(&expected); +bool Welsch::equals(const Base &expected, double tol) const { + const Welsch* p = dynamic_cast(&expected); if (p == NULL) return false; return std::abs(c_ - p->c_) < tol; } -Welsh::shared_ptr Welsh::Create(double c, const ReweightScheme reweight) { - return shared_ptr(new Welsh(c, reweight)); +Welsch::shared_ptr Welsch::Create(double c, const ReweightScheme reweight) { + return shared_ptr(new Welsch(c, reweight)); } /* ************************************************************************* */ diff --git a/gtsam/linear/NoiseModel.h b/gtsam/linear/NoiseModel.h index e495921c2d..3476869055 100644 --- a/gtsam/linear/NoiseModel.h +++ b/gtsam/linear/NoiseModel.h @@ -852,15 +852,15 @@ namespace gtsam { } }; - /// Welsh implements the "Welsh" robust error model (Zhang97ivc) - class GTSAM_EXPORT Welsh : public Base { + /// Welsch implements the "Welsch" robust error model (Zhang97ivc) + class GTSAM_EXPORT Welsch : public Base { protected: double c_, csquared_; public: - typedef boost::shared_ptr shared_ptr; + typedef boost::shared_ptr shared_ptr; - Welsh(double c = 2.9846, const ReweightScheme reweight = Block); + Welsch(double c = 2.9846, const ReweightScheme reweight = Block); double weight(double error) const { double xc2 = (error*error)/csquared_; return std::exp(-xc2); From 87c336fce363fc7f7c87db5985ae6d8aa3800db2 Mon Sep 17 00:00:00 2001 From: Alice Anderson Date: Thu, 29 Aug 2019 08:15:00 -0700 Subject: [PATCH 2/3] Added Welsch model to gtsam.h --- gtsam.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gtsam.h b/gtsam.h index 0ac2d4ad12..bf35755809 100644 --- a/gtsam.h +++ b/gtsam.h @@ -252,9 +252,9 @@ class FactorIndices { bool isDebugVersion(); #include -class IndexPair { - IndexPair(); - IndexPair(size_t i, size_t j); +class IndexPair { + IndexPair(); + IndexPair(size_t i, size_t j); size_t i() const; size_t j() const; }; @@ -1388,6 +1388,15 @@ virtual class Tukey: gtsam::noiseModel::mEstimator::Base { void serializable() const; }; +virtual class Welsch: gtsam::noiseModel::mEstimator::Base { + Welsch(double k); + static gtsam::noiseModel::mEstimator::Welsch* Create(double k); + + // enabling serialization functionality + void serializable() const; +}; + + }///\namespace mEstimator virtual class Robust : gtsam::noiseModel::Base { From f72322c4a4a1c9689726bb160f5557640e5fb22b Mon Sep 17 00:00:00 2001 From: Alice Anderson Date: Mon, 2 Sep 2019 14:11:56 -0700 Subject: [PATCH 3/3] Added old code back wrapped in deprecated flag --- gtsam/linear/NoiseModel.cpp | 18 ++++++++++++++++++ gtsam/linear/NoiseModel.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/gtsam/linear/NoiseModel.cpp b/gtsam/linear/NoiseModel.cpp index fac9f9ecd1..0adb9910ad 100644 --- a/gtsam/linear/NoiseModel.cpp +++ b/gtsam/linear/NoiseModel.cpp @@ -826,6 +826,24 @@ Welsch::shared_ptr Welsch::Create(double c, const ReweightScheme reweight) { return shared_ptr(new Welsch(c, reweight)); } +#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4 +Welsh::Welsh(double c, const ReweightScheme reweight) : Base(reweight), c_(c), csquared_(c * c) {} + +void Welsh::print(const std::string &s="") const { + std::cout << s << ": Welsh (" << c_ << ")" << std::endl; +} + +bool Welsh::equals(const Base &expected, double tol) const { + const Welsh* p = dynamic_cast(&expected); + if (p == NULL) return false; + return std::abs(c_ - p->c_) < tol; +} + +Welsh::shared_ptr Welsh::Create(double c, const ReweightScheme reweight) { + return shared_ptr(new Welsh(c, reweight)); +} +#endif + /* ************************************************************************* */ // GemanMcClure /* ************************************************************************* */ diff --git a/gtsam/linear/NoiseModel.h b/gtsam/linear/NoiseModel.h index 3476869055..aa89be9825 100644 --- a/gtsam/linear/NoiseModel.h +++ b/gtsam/linear/NoiseModel.h @@ -878,6 +878,38 @@ namespace gtsam { ar & BOOST_SERIALIZATION_NVP(c_); } }; +#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4 + /// @name Deprecated + /// @{ + // Welsh implements the "Welsch" robust error model (Zhang97ivc) + // This was misspelled in previous versions of gtsam and should be + // removed in the future. + class GTSAM_EXPORT Welsh : public Base { + protected: + double c_, csquared_; + + public: + typedef boost::shared_ptr shared_ptr; + + Welsh(double c = 2.9846, const ReweightScheme reweight = Block); + double weight(double error) const { + double xc2 = (error*error)/csquared_; + return std::exp(-xc2); + } + void print(const std::string &s) const; + bool equals(const Base& expected, double tol=1e-8) const; + static shared_ptr Create(double k, const ReweightScheme reweight = Block) ; + + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(ARCHIVE & ar, const unsigned int /*version*/) { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); + ar & BOOST_SERIALIZATION_NVP(c_); + } + }; +#endif /// GemanMcClure implements the "Geman-McClure" robust error model /// (Zhang97ivc).