formatting; removed virtual from derived classes; added default values for L2WithDeadZone constructor to allow serialization

release/4.3a0
Varun Agrawal 2019-10-09 15:33:40 -04:00
parent 7501d8a4b0
commit 1240339dc2
3 changed files with 18 additions and 32 deletions

View File

@ -1422,8 +1422,8 @@ virtual class Welsch: gtsam::noiseModel::mEstimator::Base {
}; };
virtual class GemanMcClure: gtsam::noiseModel::mEstimator::Base { virtual class GemanMcClure: gtsam::noiseModel::mEstimator::Base {
GemanMcClure(double k); GemanMcClure(double c);
static gtsam::noiseModel::mEstimator::GemanMcClure* Create(double k); static gtsam::noiseModel::mEstimator::GemanMcClure* Create(double c);
// enabling serialization functionality // enabling serialization functionality
void serializable() const; void serializable() const;

View File

@ -731,6 +731,7 @@ Fair::Fair(double c, const ReweightScheme reweight) : Base(reweight), c_(c) {
double Fair::weight(double error) const { double Fair::weight(double error) const {
return 1.0 / (1.0 + std::abs(error) / c_); return 1.0 / (1.0 + std::abs(error) / c_);
} }
double Fair::residual(double error) const { double Fair::residual(double error) const {
const double absError = std::abs(error); const double absError = std::abs(error);
const double normalizedError = absError / c_; const double normalizedError = absError / c_;
@ -839,6 +840,7 @@ double Tukey::weight(double error) const {
} }
return 0.0; return 0.0;
} }
double Tukey::residual(double error) const { double Tukey::residual(double error) const {
double absError = std::abs(error); double absError = std::abs(error);
if (absError <= c_) { if (absError <= c_) {
@ -894,24 +896,6 @@ Welsch::shared_ptr Welsch::Create(double c, const ReweightScheme reweight) {
return shared_ptr(new Welsch(c, 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<const Welsh*>(&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 // GemanMcClure
/* ************************************************************************* */ /* ************************************************************************* */
@ -992,16 +976,13 @@ DCS::shared_ptr DCS::Create(double c, const ReweightScheme reweight) {
// L2WithDeadZone // L2WithDeadZone
/* ************************************************************************* */ /* ************************************************************************* */
L2WithDeadZone::L2WithDeadZone(double k, const ReweightScheme reweight) : Base(reweight), k_(k) { L2WithDeadZone::L2WithDeadZone(double k, const ReweightScheme reweight)
: Base(reweight), k_(k) {
if (k_ <= 0) { if (k_ <= 0) {
throw runtime_error("mEstimator L2WithDeadZone takes only positive double in constructor."); throw runtime_error("mEstimator L2WithDeadZone takes only positive double in constructor.");
} }
} }
double L2WithDeadZone::residual(double error) const {
const double abs_error = std::abs(error);
return (abs_error < k_) ? 0.0 : 0.5*(k_-abs_error)*(k_-abs_error);
}
double L2WithDeadZone::weight(double error) const { double L2WithDeadZone::weight(double error) const {
// note that this code is slightly uglier than residual, because there are three distinct // note that this code is slightly uglier than residual, because there are three distinct
// cases to handle (left of deadzone, deadzone, right of deadzone) instead of the two // cases to handle (left of deadzone, deadzone, right of deadzone) instead of the two
@ -1011,6 +992,11 @@ double L2WithDeadZone::weight(double error) const {
else return (k_+error)/error; else return (k_+error)/error;
} }
double L2WithDeadZone::residual(double error) const {
const double abs_error = std::abs(error);
return (abs_error < k_) ? 0.0 : 0.5*(k_-abs_error)*(k_-abs_error);
}
void L2WithDeadZone::print(const std::string &s="") const { void L2WithDeadZone::print(const std::string &s="") const {
std::cout << s << ": L2WithDeadZone (" << k_ << ")" << std::endl; std::cout << s << ": L2WithDeadZone (" << k_ << ")" << std::endl;
} }

View File

@ -725,11 +725,11 @@ namespace gtsam {
typedef boost::shared_ptr<Null> shared_ptr; typedef boost::shared_ptr<Null> shared_ptr;
Null(const ReweightScheme reweight = Block) : Base(reweight) {} Null(const ReweightScheme reweight = Block) : Base(reweight) {}
virtual ~Null() {} ~Null() {}
virtual double weight(double /*error*/) const { return 1.0; } double weight(double /*error*/) const { return 1.0; }
virtual double residual(double error) const { return error; } double residual(double error) const { return error; }
virtual void print(const std::string &s) const; void print(const std::string &s) const;
virtual bool equals(const Base& /*expected*/, double /*tol*/) const { return true; } bool equals(const Base& /*expected*/, double /*tol*/) const { return true; }
static shared_ptr Create() ; static shared_ptr Create() ;
private: private:
@ -951,9 +951,9 @@ namespace gtsam {
public: public:
typedef boost::shared_ptr<L2WithDeadZone> shared_ptr; typedef boost::shared_ptr<L2WithDeadZone> shared_ptr;
L2WithDeadZone(double k, const ReweightScheme reweight = Block); L2WithDeadZone(double k = 1.0, const ReweightScheme reweight = Block);
double residual(double error) const override;
double weight(double error) const override; double weight(double error) const override;
double residual(double error) const override;
void print(const std::string &s) const; void print(const std::string &s) const;
bool equals(const Base& expected, double tol=1e-8) const; bool equals(const Base& expected, double tol=1e-8) const;
static shared_ptr Create(double k, const ReweightScheme reweight = Block); static shared_ptr Create(double k, const ReweightScheme reweight = Block);