MRPT  1.9.9
CPosePDFGaussianInf.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #ifndef CPosePDFGaussianInf_H
10 #define CPosePDFGaussianInf_H
11 
12 #include <mrpt/poses/CPosePDF.h>
14 
15 namespace mrpt::poses
16 {
17 class CPose3DPDF;
18 
19 // This must be added to any CSerializable derived class:
20 
21 /** A Probability Density function (PDF) of a 2D pose \f$ p(\mathbf{x}) = [x ~
22  * y ~ \phi ]^t \f$ as a Gaussian with a mean and the inverse of the covariance.
23  *
24  * This class implements a PDF as a mono-modal Gaussian distribution in its
25  * <b>information form</b>, that is,
26  * keeping the inverse of the covariance matrix instead of the covariance
27  * matrix itself.
28  *
29  * This class is the dual of CPosePDFGaussian.
30  *
31  * \sa CPose2D, CPosePDF, CPosePDFParticles
32  * \ingroup poses_pdf_grp
33  */
35 {
36  // This must be added to any CSerializable derived class:
39 
40  protected:
41  /** Assures the symmetry of the covariance matrix (eventually certain
42  * operations in the math-coprocessor lead to non-symmetric matrixes!)
43  */
44  void assureSymmetry();
45 
46  public:
47  /** @name Data fields
48  @{ */
49 
50  /** The mean value */
52  /** The inverse of the 3x3 covariance matrix (the "information" matrix) */
54 
55  /** @} */
56 
57  inline const CPose2D& getPoseMean() const { return mean; }
58  inline CPose2D& getPoseMean() { return mean; }
59  /** Default constructor (mean=all zeros, inverse covariance=all zeros -> so
60  * be careful!) */
62 
63  /** Constructor with a mean value (inverse covariance=all zeros -> so be
64  * careful!) */
65  explicit CPosePDFGaussianInf(const CPose2D& init_Mean);
66 
67  /** Constructor */
69  const CPose2D& init_Mean,
70  const mrpt::math::CMatrixDouble33& init_CovInv);
71 
72  /** Copy constructor, including transformations between other PDFs */
73  explicit CPosePDFGaussianInf(const CPosePDF& o) { copyFrom(o); }
74  /** Copy constructor, including transformations between other PDFs */
75  explicit CPosePDFGaussianInf(const CPose3DPDF& o) { copyFrom(o); }
76  /** Returns an estimate of the pose, (the mean, or mathematical expectation
77  * of the PDF).
78  * \sa getCovariance */
79  void getMean(CPose2D& mean_pose) const override { mean_pose = mean; }
80  bool isInfType() const override { return true; }
81  /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and
82  * the mean, both at once.
83  * \sa getMean */
85  mrpt::math::CMatrixDouble33& cov, CPose2D& mean_point) const override
86  {
87  mean_point = mean;
88  this->cov_inv.inv(cov);
89  }
90 
91  /** Returns the information (inverse covariance) matrix (a STATE_LEN x
92  * STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
93  virtual void getInformationMatrix(
94  mrpt::math::CMatrixDouble33& inf) const override
95  {
96  inf = cov_inv;
97  }
98 
99  /** Copy operator, translating if necesary (for example, between particles
100  * and gaussian representations) */
101  void copyFrom(const CPosePDF& o) override;
102 
103  /** Copy operator, translating if necesary (for example, between particles
104  * and gaussian representations) */
105  void copyFrom(const CPose3DPDF& o);
106 
107  /** Save PDF's particles to a text file, containing the 2D pose in the first
108  * line, then the covariance matrix in next 3 lines. */
109  bool saveToTextFile(const std::string& file) const override;
110 
111  /** this = p (+) this. This can be used to convert a PDF from local
112  * coordinates to global, providing the point (newReferenceBase) from which
113  * "to project" the current pdf. Result PDF substituted the currently stored
114  * one in the object */
115  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
116 
117  /** this = p (+) this. This can be used to convert a PDF from local
118  * coordinates to global, providing the point (newReferenceBase) from which
119  * "to project" the current pdf. Result PDF substituted the currently stored
120  * one in the object. */
121  void changeCoordinatesReference(const CPose2D& newReferenceBase);
122 
123  /** Rotate the covariance matrix by replacing it by \f$
124  * \mathbf{R}~\mathbf{COV}~\mathbf{R}^t \f$, where \f$ \mathbf{R} = \left[
125  * \begin{array}{ccc} \cos\alpha & -\sin\alpha & 0 \\ \sin\alpha &
126  * \cos\alpha & 0 \\ 0 & 0 & 1 \end{array}\right] \f$. */
127  void rotateCov(const double ang);
128 
129  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
130  * operator and the covariances through the corresponding Jacobians (For
131  * 'x0' and 'x1' being independent variables!). */
132  void inverseComposition(
134 
135  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
136  * operator and the covariances through the corresponding Jacobians (Given
137  * the 3x3 cross-covariance matrix of variables x0 and x1). */
138  void inverseComposition(
139  const CPosePDFGaussianInf& x1, const CPosePDFGaussianInf& x0,
140  const mrpt::math::CMatrixDouble33& COV_01);
141 
142  /** Draws a single sample from the distribution */
143  void drawSingleSample(CPose2D& outPart) const override;
144 
145  /** Draws a number of samples from the distribution, and saves as a list of
146  * 1x3 vectors, where each row contains a (x,y,phi) datum. */
147  void drawManySamples(
148  size_t N,
149  std::vector<mrpt::math::CVectorDouble>& outSamples) const override;
150 
151  /** Bayesian fusion of two points gauss. distributions, then save the result
152  *in this object.
153  * The process is as follows:<br>
154  * - (x1,S1): Mean and variance of the p1 distribution.
155  * - (x2,S2): Mean and variance of the p2 distribution.
156  * - (x,S): Mean and variance of the resulting distribution.
157  *
158  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
159  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
160  */
161  void bayesianFusion(
162  const CPosePDF& p1, const CPosePDF& p2,
163  const double minMahalanobisDistToDrop = 0) override;
164 
165  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
166  void inverse(CPosePDF& o) const override;
167 
168  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
169  * mean, and the covariance matrix are updated). */
170  void operator+=(const CPose2D& Ap);
171 
172  /** Evaluates the PDF at a given point */
173  double evaluatePDF(const CPose2D& x) const;
174 
175  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in
176  * the range [0,1]. */
177  double evaluateNormalizedPDF(const CPose2D& x) const;
178 
179  /** Computes the Mahalanobis distance between the centers of two Gaussians.
180  */
181  double mahalanobisDistanceTo(const CPosePDFGaussianInf& theOther);
182 
183  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
184  * mean, and the covariance matrix are updated) (see formulas in
185  * jacobiansPoseComposition ). */
186  void operator+=(const CPosePDFGaussianInf& Ap);
187 
188  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition
189  * (both the mean, and the covariance matrix are updated) */
190  inline void operator-=(const CPosePDFGaussianInf& ref)
191  {
192  this->inverseComposition(*this, ref);
193  }
194 
195 }; // End of class def.
196 
197 bool operator==(const CPosePDFGaussianInf& p1, const CPosePDFGaussianInf& p2);
198 /** Pose compose operator: RES = A (+) B , computing both the mean and the
199  * covariance */
200 CPosePDFGaussianInf operator+(
201  const CPosePDFGaussianInf& a, const CPosePDFGaussianInf& b);
202 /** Pose inverse compose operator: RES = A (-) B , computing both the mean and
203  * the covariance */
204 CPosePDFGaussianInf operator-(
205  const CPosePDFGaussianInf& a, const CPosePDFGaussianInf& b);
206 /** Returns the Gaussian distribution of \f$ \mathbf{C} \f$, for \f$ \mathbf{C}
207  * = \mathbf{A} \oplus \mathbf{B} \f$. */
210 
211 /** Dumps the mean and covariance matrix to a text stream. */
212 std::ostream& operator<<(std::ostream& out, const CPosePDFGaussianInf& obj);
213 
214 }
215 #endif
216 
217 
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double minMahalanobisDistToDrop=0) override
Bayesian fusion of two points gauss.
void operator+=(const CPose2D &Ap)
Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matri...
CPosePDFGaussianInf(const CPose3DPDF &o)
Copy constructor, including transformations between other PDFs.
GLenum GLint ref
Definition: glext.h:4050
mrpt::math::TPoint2D operator+(const CPose2D &pose, const mrpt::math::TPoint2D &pnt)
Compose a 2D point from a new coordinate base given by a 2D pose.
Definition: CPose2D.cpp:364
bool saveToTextFile(const std::string &file) const override
Save PDF&#39;s particles to a text file, containing the 2D pose in the first line, then the covariance ma...
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPose2D &mean_point) const override
Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once...
void drawManySamples(size_t N, std::vector< mrpt::math::CVectorDouble > &outSamples) const override
Draws a number of samples from the distribution, and saves as a list of 1x3 vectors, where each row contains a (x,y,phi) datum.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
void operator-=(const CPosePDFGaussianInf &ref)
Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated)
double evaluateNormalizedPDF(const CPose2D &x) const
Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
void copyFrom(const CPosePDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
void inverse(CPosePDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
CPosePDFGaussianInf(const CPosePDF &o)
Copy constructor, including transformations between other PDFs.
double evaluatePDF(const CPose2D &x) const
Evaluates the PDF at a given point.
const CPose2D & getPoseMean() const
CPose2D operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
Definition: CPose2D.cpp:315
GLubyte GLubyte b
Definition: glext.h:6279
GLsizei const GLchar ** string
Definition: glext.h:4101
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:39
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void rotateCov(const double ang)
Rotate the covariance matrix by replacing it by , where .
CPosePDFGaussianInf()
Default constructor (mean=all zeros, inverse covariance=all zeros -> so be careful!) ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
A Probability Density function (PDF) of a 2D pose as a Gaussian with a mean and the inverse of the c...
bool operator==(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
Definition: CPoint.h:164
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:38
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
CMatrixFixedNumeric< double, 3, 3 > CMatrixDouble33
Definition: eigen_frwds.h:57
void drawSingleSample(CPose2D &outPart) const override
Draws a single sample from the distribution.
Eigen::Matrix< typename MATRIX::Scalar, MATRIX::ColsAtCompileTime, MATRIX::ColsAtCompileTime > cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
Definition: ops_matrices.h:148
GLenum GLint x
Definition: glext.h:3538
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
void inverseComposition(const CPosePDFGaussianInf &x, const CPosePDFGaussianInf &ref)
Set , computing the mean using the "-" operator and the covariances through the corresponding Jacobi...
bool isInfType() const override
Returns whether the class instance holds the uncertainty in covariance or information form...
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
virtual void getInformationMatrix(mrpt::math::CMatrixDouble33 &inf) const override
Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) ...
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:40
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
mrpt::math::CMatrixDouble33 cov_inv
The inverse of the 3x3 covariance matrix (the "information" matrix)
void getMean(CPose2D &mean_pose) const override
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
double mahalanobisDistanceTo(const CPosePDFGaussianInf &theOther)
Computes the Mahalanobis distance between the centers of two Gaussians.
std::ostream & operator<<(std::ostream &o, const CPoint< DERIVEDCLASS > &p)
Dumps a point as a string [x,y] or [x,y,z].
Definition: CPoint.h:138



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020