gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NoiseModel.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 
19 #pragma once
20 
21 #include <boost/serialization/nvp.hpp>
22 #include <boost/serialization/extended_type_info.hpp>
23 #include <boost/serialization/singleton.hpp>
24 #include <boost/serialization/shared_ptr.hpp>
25 #include <boost/serialization/optional.hpp>
26 #include <gtsam/base/Matrix.h>
27 #include <cmath>
28 
29 namespace gtsam {
30 
32  namespace noiseModel {
33 
34  // Forward declaration
35  class Gaussian;
36  class Diagonal;
37  class Constrained;
38  class Isotropic;
39  class Unit;
40 
41  //---------------------------------------------------------------------------------------
42 
49  class GTSAM_EXPORT Base {
50 
51  public:
52  typedef boost::shared_ptr<Base> shared_ptr;
53 
54  protected:
55 
56  size_t dim_;
57 
58  public:
59 
61  Base(size_t dim = 1):dim_(dim) {}
62  virtual ~Base() {}
63 
65  inline size_t dim() const { return dim_;}
66 
67  virtual void print(const std::string& name = "") const = 0;
68 
69  virtual bool equals(const Base& expected, double tol=1e-9) const = 0;
70 
74  virtual Vector whiten(const Vector& v) const = 0;
75 
79  virtual Vector unwhiten(const Vector& v) const = 0;
80 
81  virtual double distance(const Vector& v) const = 0;
82 
83  virtual void WhitenSystem(std::vector<Matrix>& A, Vector& b) const = 0;
84  virtual void WhitenSystem(Matrix& A, Vector& b) const = 0;
85  virtual void WhitenSystem(Matrix& A1, Matrix& A2, Vector& b) const = 0;
86  virtual void WhitenSystem(Matrix& A1, Matrix& A2, Matrix& A3, Vector& b) const = 0;
87 
89  virtual void whitenInPlace(Vector& v) const {
90  v = whiten(v);
91  }
92 
94  virtual void unwhitenInPlace(Vector& v) const {
95  v = unwhiten(v);
96  }
97 
99  virtual void whitenInPlace(Eigen::Block<Vector>& v) const {
100  v = whiten(v);
101  }
102 
104  virtual void unwhitenInPlace(Eigen::Block<Vector>& v) const {
105  v = unwhiten(v);
106  }
107 
108  private:
110  friend class boost::serialization::access;
111  template<class ARCHIVE>
112  void serialize(ARCHIVE & ar, const unsigned int version) {
113  ar & BOOST_SERIALIZATION_NVP(dim_);
114  }
115  };
116 
117  //---------------------------------------------------------------------------------------
118 
131  class GTSAM_EXPORT Gaussian: public Base {
132 
133  protected:
134 
136  boost::optional<Matrix> sqrt_information_;
137 
138  private:
139 
143  const Matrix& thisR() const {
144  // should never happen
145  if (!sqrt_information_) throw std::runtime_error("Gaussian: has no R matrix");
146  return *sqrt_information_;
147  }
148 
149  protected:
150 
152  Gaussian(size_t dim = 1, const boost::optional<Matrix>& sqrt_information = boost::none) :
153  Base(dim), sqrt_information_(sqrt_information) {
154  }
155 
156  public:
157 
158  typedef boost::shared_ptr<Gaussian> shared_ptr;
159 
160  virtual ~Gaussian() {}
161 
167  static shared_ptr SqrtInformation(const Matrix& R, bool smart = true);
168 
174  static shared_ptr Information(const Matrix& M, bool smart = true);
175 
181  static shared_ptr Covariance(const Matrix& covariance, bool smart = true);
182 
183  virtual void print(const std::string& name) const;
184  virtual bool equals(const Base& expected, double tol=1e-9) const;
185  virtual Vector whiten(const Vector& v) const;
186  virtual Vector unwhiten(const Vector& v) const;
187 
191  virtual double Mahalanobis(const Vector& v) const;
192 
193  inline virtual double distance(const Vector& v) const {
194  return Mahalanobis(v);
195  }
196 
201  virtual Matrix Whiten(const Matrix& H) const;
202 
206  virtual void WhitenInPlace(Matrix& H) const;
207 
211  virtual void WhitenInPlace(Eigen::Block<Matrix> H) const;
212 
216  virtual void WhitenSystem(std::vector<Matrix>& A, Vector& b) const ;
217  virtual void WhitenSystem(Matrix& A, Vector& b) const ;
218  virtual void WhitenSystem(Matrix& A1, Matrix& A2, Vector& b) const ;
219  virtual void WhitenSystem(Matrix& A1, Matrix& A2, Matrix& A3, Vector& b) const;
220 
228  virtual boost::shared_ptr<Diagonal> QR(Matrix& Ab) const;
229 
233  virtual Matrix R() const { return thisR();}
234 
239  virtual bool isConstrained() const {return false;}
240 
241  private:
243  friend class boost::serialization::access;
244  template<class ARCHIVE>
245  void serialize(ARCHIVE & ar, const unsigned int version) {
246  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
247  ar & BOOST_SERIALIZATION_NVP(sqrt_information_);
248  }
249 
250  }; // Gaussian
251 
252  //---------------------------------------------------------------------------------------
253 
259  class GTSAM_EXPORT Diagonal : public Gaussian {
260  protected:
261 
267  Vector sigmas_, invsigmas_, precisions_;
268 
269  protected:
271  Diagonal();
272 
274  Diagonal(const Vector& sigmas);
275 
276  public:
277 
278  typedef boost::shared_ptr<Diagonal> shared_ptr;
279 
280  virtual ~Diagonal() {}
281 
286  static shared_ptr Sigmas(const Vector& sigmas, bool smart = true);
287 
294  static shared_ptr Variances(const Vector& variances, bool smart = true);
295 
300  static shared_ptr Precisions(const Vector& precisions, bool smart = true) {
301  return Variances(reciprocal(precisions), smart);
302  }
303 
304  virtual void print(const std::string& name) const;
305  virtual Vector whiten(const Vector& v) const;
306  virtual Vector unwhiten(const Vector& v) const;
307  virtual Matrix Whiten(const Matrix& H) const;
308  virtual void WhitenInPlace(Matrix& H) const;
309  virtual void WhitenInPlace(Eigen::Block<Matrix> H) const;
310 
314  inline const Vector& sigmas() const { return sigmas_; }
315  inline double sigma(size_t i) const { return sigmas_(i); }
316 
320  inline const Vector& invsigmas() const { return invsigmas_; }
321  inline double invsigma(size_t i) const {return invsigmas_(i);}
322 
326  inline const Vector& precisions() const { return precisions_; }
327  inline double precision(size_t i) const {return precisions_(i);}
328 
332  virtual Matrix R() const {
333  return diag(invsigmas());
334  }
335 
336  private:
338  friend class boost::serialization::access;
339  template<class ARCHIVE>
340  void serialize(ARCHIVE & ar, const unsigned int version) {
341  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Gaussian);
342  ar & BOOST_SERIALIZATION_NVP(sigmas_);
343  ar & BOOST_SERIALIZATION_NVP(invsigmas_);
344  }
345  }; // Diagonal
346 
347  //---------------------------------------------------------------------------------------
348 
361  class GTSAM_EXPORT Constrained : public Diagonal {
362  protected:
363 
364  // Sigmas are contained in the base class
365  Vector mu_;
366 
373  Constrained(const Vector& sigmas = zero(1));
374 
380  Constrained(const Vector& mu, const Vector& sigmas);
381 
382  public:
383 
384  typedef boost::shared_ptr<Constrained> shared_ptr;
385 
386  virtual ~Constrained() {}
387 
389  const Vector& mu() const { return mu_; }
390 
395  static shared_ptr MixedSigmas(const Vector& mu, const Vector& sigmas,
396  bool smart = true);
397 
402  static shared_ptr MixedSigmas(const Vector& sigmas, bool smart = true) {
403  return MixedSigmas(repeat(sigmas.size(), 1000.0), sigmas, smart);
404  }
405 
410  static shared_ptr MixedSigmas(double m, const Vector& sigmas,
411  bool smart = true) {
412  return MixedSigmas(repeat(sigmas.size(), m), sigmas, smart);
413  }
414 
419  static shared_ptr MixedVariances(const Vector& mu, const Vector& variances) {
420  return shared_ptr(new Constrained(mu, esqrt(variances)));
421  }
422  static shared_ptr MixedVariances(const Vector& variances) {
423  return shared_ptr(new Constrained(esqrt(variances)));
424  }
425 
430  static shared_ptr MixedPrecisions(const Vector& mu, const Vector& precisions) {
431  return MixedVariances(mu, reciprocal(precisions));
432  }
433  static shared_ptr MixedPrecisions(const Vector& precisions) {
434  return MixedVariances(reciprocal(precisions));
435  }
436 
442  virtual double distance(const Vector& v) const;
443 
445  static shared_ptr All(size_t dim) {
446  return shared_ptr(new Constrained(repeat(dim, 1000.0), repeat(dim,0)));
447  }
448 
450  static shared_ptr All(size_t dim, const Vector& mu) {
451  return shared_ptr(new Constrained(mu, repeat(dim,0)));
452  }
453 
455  static shared_ptr All(size_t dim, double mu) {
456  return shared_ptr(new Constrained(repeat(dim, mu), repeat(dim,0)));
457  }
458 
459  virtual void print(const std::string& name) const;
460 
462  virtual Vector whiten(const Vector& v) const;
463 
466  virtual Matrix Whiten(const Matrix& H) const;
467  virtual void WhitenInPlace(Matrix& H) const;
468  virtual void WhitenInPlace(Eigen::Block<Matrix> H) const;
469 
473  virtual Diagonal::shared_ptr QR(Matrix& Ab) const;
474 
479  virtual bool isConstrained() const { return true; }
480 
485  shared_ptr unit() const;
486 
487  private:
489  friend class boost::serialization::access;
490  template<class ARCHIVE>
491  void serialize(ARCHIVE & ar, const unsigned int version) {
492  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Diagonal);
493  ar & BOOST_SERIALIZATION_NVP(mu_);
494  }
495 
496  }; // Constrained
497 
498  //---------------------------------------------------------------------------------------
499 
504  class GTSAM_EXPORT Isotropic : public Diagonal {
505  protected:
506  double sigma_, invsigma_;
507 
509  Isotropic(size_t dim, double sigma) :
510  Diagonal(repeat(dim, sigma)),sigma_(sigma),invsigma_(1.0/sigma) {}
511 
512  /* dummy constructor to allow for serialization */
513  Isotropic() : Diagonal(repeat(1, 1.0)),sigma_(1.0),invsigma_(1.0) {}
514 
515  public:
516 
517  virtual ~Isotropic() {}
518 
519  typedef boost::shared_ptr<Isotropic> shared_ptr;
520 
524  static shared_ptr Sigma(size_t dim, double sigma, bool smart = true);
525 
532  static shared_ptr Variance(size_t dim, double variance, bool smart = true);
533 
537  static shared_ptr Precision(size_t dim, double precision, bool smart = true) {
538  return Variance(dim, 1.0/precision, smart);
539  }
540 
541  virtual void print(const std::string& name) const;
542  virtual double Mahalanobis(const Vector& v) const;
543  virtual Vector whiten(const Vector& v) const;
544  virtual Vector unwhiten(const Vector& v) const;
545  virtual Matrix Whiten(const Matrix& H) const;
546  virtual void WhitenInPlace(Matrix& H) const;
547  virtual void WhitenInPlace(Eigen::Block<Matrix> H) const;
548 
552  inline double sigma() const { return sigma_; }
553 
554  private:
556  friend class boost::serialization::access;
557  template<class ARCHIVE>
558  void serialize(ARCHIVE & ar, const unsigned int version) {
559  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Diagonal);
560  ar & BOOST_SERIALIZATION_NVP(sigma_);
561  ar & BOOST_SERIALIZATION_NVP(invsigma_);
562  }
563 
564  };
565 
566  //---------------------------------------------------------------------------------------
567 
571  class GTSAM_EXPORT Unit : public Isotropic {
572  protected:
573 
574  Unit(size_t dim=1): Isotropic(dim,1.0) {}
575 
576  public:
577 
578  typedef boost::shared_ptr<Unit> shared_ptr;
579 
580  virtual ~Unit() {}
581 
585  static shared_ptr Create(size_t dim) {
586  return shared_ptr(new Unit(dim));
587  }
588 
589  virtual void print(const std::string& name) const;
590  virtual double Mahalanobis(const Vector& v) const {return v.dot(v); }
591  virtual Vector whiten(const Vector& v) const { return v; }
592  virtual Vector unwhiten(const Vector& v) const { return v; }
593  virtual Matrix Whiten(const Matrix& H) const { return H; }
594  virtual void WhitenInPlace(Matrix& H) const {}
595  virtual void WhitenInPlace(Eigen::Block<Matrix> H) const {}
596  virtual void whitenInPlace(Vector& v) const {}
597  virtual void unwhitenInPlace(Vector& v) const {}
598  virtual void whitenInPlace(Eigen::Block<Vector>& v) const {}
599  virtual void unwhitenInPlace(Eigen::Block<Vector>& v) const {}
600 
601  private:
603  friend class boost::serialization::access;
604  template<class ARCHIVE>
605  void serialize(ARCHIVE & ar, const unsigned int version) {
606  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Isotropic);
607  }
608  };
609 
610  // TODO: should not really exist
612  namespace mEstimator {
613 
614  //---------------------------------------------------------------------------------------
615 
616  class GTSAM_EXPORT Base {
617  public:
618  enum ReweightScheme { Scalar, Block };
619  typedef boost::shared_ptr<Base> shared_ptr;
620 
621  protected:
624  ReweightScheme reweight_;
625 
626  public:
627  Base(const ReweightScheme reweight = Block):reweight_(reweight) {}
628  virtual ~Base() {}
629 
631  virtual double weight(const double &error) const = 0;
632 
633  virtual void print(const std::string &s) const = 0;
634  virtual bool equals(const Base& expected, const double tol=1e-8) const = 0;
635 
636  inline double sqrtWeight(const double &error) const
637  { return std::sqrt(weight(error)); }
638 
641  Vector weight(const Vector &error) const;
642 
644  Vector sqrtWeight(const Vector &error) const;
645 
647  void reweight(Vector &error) const;
648  void reweight(std::vector<Matrix> &A, Vector &error) const;
649  void reweight(Matrix &A, Vector &error) const;
650  void reweight(Matrix &A1, Matrix &A2, Vector &error) const;
651  void reweight(Matrix &A1, Matrix &A2, Matrix &A3, Vector &error) const;
652 
653  private:
655  friend class boost::serialization::access;
656  template<class ARCHIVE>
657  void serialize(ARCHIVE & ar, const unsigned int version) {
658  ar & BOOST_SERIALIZATION_NVP(reweight_);
659  }
660  };
661 
663  class GTSAM_EXPORT Null : public Base {
664  public:
665  typedef boost::shared_ptr<Null> shared_ptr;
666 
667  Null(const ReweightScheme reweight = Block) : Base(reweight) {}
668  virtual ~Null() {}
669  virtual double weight(const double &error) const { return 1.0; }
670  virtual void print(const std::string &s) const;
671  virtual bool equals(const Base& expected, const double tol=1e-8) const { return true; }
672  static shared_ptr Create() ;
673 
674  private:
676  friend class boost::serialization::access;
677  template<class ARCHIVE>
678  void serialize(ARCHIVE & ar, const unsigned int version) {
679  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
680  }
681  };
682 
684  class GTSAM_EXPORT Fair : public Base {
685  public:
686  typedef boost::shared_ptr<Fair> shared_ptr;
687 
688  Fair(const double c = 1.3998, const ReweightScheme reweight = Block);
689  virtual ~Fair() {}
690  virtual double weight(const double &error) const ;
691  virtual void print(const std::string &s) const ;
692  virtual bool equals(const Base& expected, const double tol=1e-8) const ;
693  static shared_ptr Create(const double c, const ReweightScheme reweight = Block) ;
694 
695  protected:
696  double c_;
697 
698  private:
700  friend class boost::serialization::access;
701  template<class ARCHIVE>
702  void serialize(ARCHIVE & ar, const unsigned int version) {
703  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
704  ar & BOOST_SERIALIZATION_NVP(c_);
705  }
706  };
707 
709  class GTSAM_EXPORT Huber : public Base {
710  public:
711  typedef boost::shared_ptr<Huber> shared_ptr;
712 
713  virtual ~Huber() {}
714  Huber(const double k = 1.345, const ReweightScheme reweight = Block);
715  virtual double weight(const double &error) const ;
716  virtual void print(const std::string &s) const ;
717  virtual bool equals(const Base& expected, const double tol=1e-8) const ;
718  static shared_ptr Create(const double k, const ReweightScheme reweight = Block) ;
719 
720  protected:
721  double k_;
722 
723  private:
725  friend class boost::serialization::access;
726  template<class ARCHIVE>
727  void serialize(ARCHIVE & ar, const unsigned int version) {
728  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
729  ar & BOOST_SERIALIZATION_NVP(k_);
730  }
731  };
732 
738  class GTSAM_EXPORT Cauchy : public Base {
739  public:
740  typedef boost::shared_ptr<Cauchy> shared_ptr;
741 
742  virtual ~Cauchy() {}
743  Cauchy(const double k = 0.1, const ReweightScheme reweight = Block);
744  virtual double weight(const double &error) const ;
745  virtual void print(const std::string &s) const ;
746  virtual bool equals(const Base& expected, const double tol=1e-8) const ;
747  static shared_ptr Create(const double k, const ReweightScheme reweight = Block) ;
748 
749  protected:
750  double k_;
751 
752  private:
754  friend class boost::serialization::access;
755  template<class ARCHIVE>
756  void serialize(ARCHIVE & ar, const unsigned int version) {
757  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
758  ar & BOOST_SERIALIZATION_NVP(k_);
759  }
760  };
761 
763  class GTSAM_EXPORT Tukey : public Base {
764  public:
765  typedef boost::shared_ptr<Tukey> shared_ptr;
766 
767  Tukey(const double c = 4.6851, const ReweightScheme reweight = Block);
768  virtual ~Tukey() {}
769  virtual double weight(const double &error) const ;
770  virtual void print(const std::string &s) const ;
771  virtual bool equals(const Base& expected, const double tol=1e-8) const ;
772  static shared_ptr Create(const double k, const ReweightScheme reweight = Block) ;
773 
774  protected:
775  double c_;
776 
777  private:
779  friend class boost::serialization::access;
780  template<class ARCHIVE>
781  void serialize(ARCHIVE & ar, const unsigned int version) {
782  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
783  ar & BOOST_SERIALIZATION_NVP(c_);
784  }
785  };
786 
788  class GTSAM_EXPORT Welsh : public Base {
789  public:
790  typedef boost::shared_ptr<Welsh> shared_ptr;
791 
792  Welsh(const double c = 2.9846, const ReweightScheme reweight = Block);
793  virtual ~Welsh() {}
794  virtual double weight(const double &error) const ;
795  virtual void print(const std::string &s) const ;
796  virtual bool equals(const Base& expected, const double tol=1e-8) const ;
797  static shared_ptr Create(const double k, const ReweightScheme reweight = Block) ;
798 
799  protected:
800  double c_;
801 
802  private:
804  friend class boost::serialization::access;
805  template<class ARCHIVE>
806  void serialize(ARCHIVE & ar, const unsigned int version) {
807  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
808  ar & BOOST_SERIALIZATION_NVP(c_);
809  }
810  };
811 
812  }
813 
815  class GTSAM_EXPORT Robust : public Base {
816  public:
817  typedef boost::shared_ptr<Robust> shared_ptr;
818 
819  protected:
822 
823  const RobustModel::shared_ptr robust_;
824  const NoiseModel::shared_ptr noise_;
825 
826  public:
827 
829  Robust() {};
830 
832  Robust(const RobustModel::shared_ptr robust, const NoiseModel::shared_ptr noise)
833  : Base(noise->dim()), robust_(robust), noise_(noise) {}
834 
836  virtual ~Robust() {}
837 
838  virtual void print(const std::string& name) const;
839  virtual bool equals(const Base& expected, double tol=1e-9) const;
840 
842  const RobustModel::shared_ptr& robust() const { return robust_; }
843 
845  const NoiseModel::shared_ptr& noise() const { return noise_; }
846 
847  // TODO: functions below are dummy but necessary for the noiseModel::Base
848  inline virtual Vector whiten(const Vector& v) const
849  { Vector r = v; this->WhitenSystem(r); return r; }
850  inline virtual Vector unwhiten(const Vector& v) const
851  { throw std::invalid_argument("unwhiten is not currently supported for robust noise models."); }
852  inline virtual double distance(const Vector& v) const
853  { return this->whiten(v).squaredNorm(); }
854 
855  // TODO: these are really robust iterated re-weighting support functions
856  virtual void WhitenSystem(Vector& b) const;
857  virtual void WhitenSystem(std::vector<Matrix>& A, Vector& b) const;
858  virtual void WhitenSystem(Matrix& A, Vector& b) const;
859  virtual void WhitenSystem(Matrix& A1, Matrix& A2, Vector& b) const;
860  virtual void WhitenSystem(Matrix& A1, Matrix& A2, Matrix& A3, Vector& b) const;
861 
862  static shared_ptr Create(
863  const RobustModel::shared_ptr &robust, const NoiseModel::shared_ptr noise);
864 
865  private:
867  friend class boost::serialization::access;
868  template<class ARCHIVE>
869  void serialize(ARCHIVE & ar, const unsigned int version) {
870  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
871  ar & boost::serialization::make_nvp("robust_", const_cast<RobustModel::shared_ptr&>(robust_));
872  ar & boost::serialization::make_nvp("noise_", const_cast<NoiseModel::shared_ptr&>(noise_));
873  }
874  };
875 
876  // Helper function
877  GTSAM_EXPORT boost::optional<Vector> checkIfDiagonal(const Matrix M);
878 
879  } // namespace noiseModel
880 
884  typedef noiseModel::Base::shared_ptr SharedNoiseModel;
885  typedef noiseModel::Gaussian::shared_ptr SharedGaussian;
886  typedef noiseModel::Diagonal::shared_ptr SharedDiagonal;
887  typedef noiseModel::Constrained::shared_ptr SharedConstrained;
888 
889 } // namespace gtsam
890 
891 
static shared_ptr MixedSigmas(const Vector &sigmas, bool smart=true)
A diagonal noise model created by specifying a Vector of standard devations, some of which might be z...
Definition: NoiseModel.h:402
virtual Vector whiten(const Vector &v) const
Whiten an error vector.
Definition: NoiseModel.h:848
Huber implements the "Huber" robust error model (Zhang97ivc)
Definition: NoiseModel.h:709
const Vector & invsigmas() const
Return sqrt precisions.
Definition: NoiseModel.h:320
static shared_ptr Precisions(const Vector &precisions, bool smart=true)
A diagonal noise model created by specifying a Vector of precisions, i.e.
Definition: NoiseModel.h:300
static shared_ptr MixedVariances(const Vector &mu, const Vector &variances)
A diagonal noise model created by specifying a Vector of standard devations, some of which might be z...
Definition: NoiseModel.h:419
virtual Matrix R() const
Return R itself, but note that Whiten(H) is cheaper than R*H.
Definition: NoiseModel.h:233
static shared_ptr Create(size_t dim)
Create a unit covariance noise model.
Definition: NoiseModel.h:585
Tukey implements the "Tukey" robust error model (Zhang97ivc)
Definition: NoiseModel.h:763
Base class for robust error models.
Definition: NoiseModel.h:815
virtual Vector whiten(const Vector &v) const
Whiten an error vector.
Definition: NoiseModel.h:591
Vector reciprocal(const Vector &a)
Elementwise reciprocal of vector elements.
Definition: Vector.cpp:219
Robust(const RobustModel::shared_ptr robust, const NoiseModel::shared_ptr noise)
Constructor.
Definition: NoiseModel.h:832
virtual Vector unwhiten(const Vector &v) const
Unwhiten an error vector.
Definition: NoiseModel.h:850
Cauchy implements the "Cauchy" robust error model (Lee2013IROS).
Definition: NoiseModel.h:738
static shared_ptr MixedPrecisions(const Vector &mu, const Vector &precisions)
A diagonal noise model created by specifying a Vector of precisions, some of which might be inf...
Definition: NoiseModel.h:430
Vector sigmas_
Standard deviations (sigmas), their inverse and inverse square (weights/precisions) These are all com...
Definition: NoiseModel.h:267
static shared_ptr MixedSigmas(double m, const Vector &sigmas, bool smart=true)
A diagonal noise model created by specifying a Vector of standard devations, some of which might be z...
Definition: NoiseModel.h:410
const Vector & sigmas() const
Return standard deviations (sqrt of diagonal)
Definition: NoiseModel.h:314
virtual double Mahalanobis(const Vector &v) const
Mahalanobis distance v'*R'*R*v = <R*v,R*v>
Definition: NoiseModel.h:590
boost::optional< Matrix > sqrt_information_
Matrix square root of information matrix (R)
Definition: NoiseModel.h:136
virtual void whitenInPlace(Vector &v) const
in-place whiten, override if can be done more efficiently
Definition: NoiseModel.h:89
Base(size_t dim=1)
primary constructor
Definition: NoiseModel.h:61
virtual void unwhitenInPlace(Eigen::Block< Vector > &v) const
in-place unwhiten, override if can be done more efficiently
Definition: NoiseModel.h:104
Robust()
Default Constructor for serialization.
Definition: NoiseModel.h:829
static shared_ptr All(size_t dim)
Fully constrained variations.
Definition: NoiseModel.h:445
virtual void unwhitenInPlace(Vector &v) const
in-place unwhiten, override if can be done more efficiently
Definition: NoiseModel.h:597
Vector esqrt(const Vector &v)
Elementwise sqrt of vector elements.
Definition: Vector.cpp:228
size_t dim(const Vector &v)
dimensionality == size
Definition: Vector.h:90
const RobustModel::shared_ptr & robust() const
Return the contained robust error function.
Definition: NoiseModel.h:842
ReweightScheme reweight_
the rows can be weighted independently according to the error or uniformly with the norm of the right...
Definition: NoiseModel.h:624
const Vector & precisions() const
Return precisions.
Definition: NoiseModel.h:326
bool zero(const Vector &v)
check if all zero
Definition: Vector.cpp:39
Isotropic(size_t dim, double sigma)
protected constructor takes sigma
Definition: NoiseModel.h:509
virtual double weight(const double &error) const
robust error function to implement
Definition: NoiseModel.h:669
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
Gaussian(size_t dim=1, const boost::optional< Matrix > &sqrt_information=boost::none)
protected constructor takes square root information matrix
Definition: NoiseModel.h:152
virtual void whitenInPlace(Vector &v) const
in-place whiten, override if can be done more efficiently
Definition: NoiseModel.h:596
Gaussian implements the mathematical model |R*x|^2 = |y|^2 with R'*R=inv(Sigma) where y = whiten(x) =...
Definition: NoiseModel.h:131
double sigma() const
Return standard deviation.
Definition: NoiseModel.h:552
virtual void whitenInPlace(Eigen::Block< Vector > &v) const
in-place whiten, override if can be done more efficiently
Definition: NoiseModel.h:598
A Constrained constrained model is a specialization of Diagonal which allows some or all of the sigma...
Definition: NoiseModel.h:361
static shared_ptr All(size_t dim, const Vector &mu)
Fully constrained variations.
Definition: NoiseModel.h:450
virtual Matrix R() const
Return R itself, but note that Whiten(H) is cheaper than R*H.
Definition: NoiseModel.h:332
Template to create a binary predicate.
Definition: Testable.h:102
const NoiseModel::shared_ptr & noise() const
Return the contained noise model.
Definition: NoiseModel.h:845
static shared_ptr Precision(size_t dim, double precision, bool smart=true)
An isotropic noise model created by specifying a precision.
Definition: NoiseModel.h:537
An isotropic noise model corresponds to a scaled diagonal covariance To construct, use one of the static methods.
Definition: NoiseModel.h:504
typedef and functions to augment Eigen's MatrixXd
virtual Matrix Whiten(const Matrix &H) const
Multiply a derivative with R (derivative of whiten) Equivalent to whitening each column of the input ...
Definition: NoiseModel.h:593
virtual Vector unwhiten(const Vector &v) const
Unwhiten an error vector.
Definition: NoiseModel.h:592
virtual bool isConstrained() const
Simple check for constrained-ness FIXME Find a better way of handling this.
Definition: NoiseModel.h:239
size_t dim() const
Dimensionality.
Definition: NoiseModel.h:65
Null class is not robust so is a Gaussian ?
Definition: NoiseModel.h:663
const RobustModel::shared_ptr robust_
robust error function used
Definition: NoiseModel.h:823
Unit: i.i.d.
Definition: NoiseModel.h:571
Definition: NoiseModel.h:616
const Vector & mu() const
Access mu as a vector.
Definition: NoiseModel.h:389
virtual bool isConstrained() const
Check constrained is always true FIXME Find a better way of handling this.
Definition: NoiseModel.h:479
Fair implements the "Fair" robust error model (Zhang97ivc)
Definition: NoiseModel.h:684
virtual void WhitenInPlace(Eigen::Block< Matrix > H) const
In-place version.
Definition: NoiseModel.h:595
virtual void WhitenInPlace(Matrix &H) const
In-place version.
Definition: NoiseModel.h:594
A diagonal noise model implements a diagonal covariance matrix, with the elements of the diagonal spe...
Definition: NoiseModel.h:259
virtual ~Robust()
Destructor.
Definition: NoiseModel.h:836
virtual void unwhitenInPlace(Vector &v) const
in-place unwhiten, override if can be done more efficiently
Definition: NoiseModel.h:94
virtual void whitenInPlace(Eigen::Block< Vector > &v) const
in-place whiten, override if can be done more efficiently
Definition: NoiseModel.h:99
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:884
virtual void unwhitenInPlace(Eigen::Block< Vector > &v) const
in-place unwhiten, override if can be done more efficiently
Definition: NoiseModel.h:599
Vector mu_
Penalty function weight - needs to be large enough to dominate soft constraints.
Definition: NoiseModel.h:365
Vector repeat(size_t n, double value)
Create vector initialized to a constant value.
Definition: Vector.cpp:48
static shared_ptr All(size_t dim, double mu)
Fully constrained variations with a mu parameter.
Definition: NoiseModel.h:455
const NoiseModel::shared_ptr noise_
noise model used
Definition: NoiseModel.h:824
noiseModel::Base is the abstract base class for all noise models.
Definition: NoiseModel.h:49
Welsh implements the "Welsh" robust error model (Zhang97ivc)
Definition: NoiseModel.h:788