MRPT  1.9.9
CPosePDFGaussian.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 CPosePDFGaussian_H
10 #define CPosePDFGaussian_H
11 
12 #include <mrpt/poses/CPosePDF.h>
14 
15 namespace mrpt::poses
16 {
17 class CPose3DPDF;
18 class CPoint2DPDFGaussian;
19 
20 /** Declares a class that represents a Probability Density function (PDF) of a
21  * 2D pose \f$ p(\mathbf{x}) = [x ~ y ~ \phi ]^t \f$.
22  *
23  * This class implements that PDF using a mono-modal Gaussian distribution.
24  * See mrpt::poses::CPosePDF for more details.
25  *
26  * \sa CPose2D, CPosePDF, CPosePDFParticles
27  * \ingroup poses_pdf_grp
28  */
29 class CPosePDFGaussian : public CPosePDF
30 {
32 
33  protected:
34  /** Assures the symmetry of the covariance matrix (eventually certain
35  * operations in the math-coprocessor lead to non-symmetric matrixes!)
36  */
37  void assureSymmetry();
38 
39  public:
40  /** @name Data fields
41  @{ */
42 
43  /** The mean value */
45  /** The 3x3 covariance matrix */
47 
48  /** @} */
49 
50  inline const CPose2D& getPoseMean() const { return mean; }
51  inline CPose2D& getPoseMean() { return mean; }
52  /** Default constructor
53  */
55 
56  /** Constructor
57  */
58  explicit CPosePDFGaussian(const CPose2D& init_Mean);
59 
60  /** Constructor
61  */
63  const CPose2D& init_Mean, const mrpt::math::CMatrixDouble33& init_Cov);
64 
65  /** Copy constructor, including transformations between other PDFs */
66  explicit CPosePDFGaussian(const CPosePDF& o) { copyFrom(o); }
67  /** Copy constructor, including transformations between other PDFs */
68  explicit CPosePDFGaussian(const CPose3DPDF& o) { copyFrom(o); }
69  /** Returns an estimate of the pose, (the mean, or mathematical expectation
70  * of the PDF).
71  * \sa getCovariance
72  */
73  void getMean(CPose2D& mean_pose) const override { mean_pose = mean; }
74  /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and
75  * the mean, both at once.
76  * \sa getMean
77  */
80  CPose2D& mean_point) const override
81  {
82  mean_point = mean;
83  out_cov = this->cov;
84  }
85 
86  /** Copy operator, translating if necesary (for example, between particles
87  * and gaussian representations) */
88  void copyFrom(const CPosePDF& o) override;
89 
90  /** Copy operator, translating if necesary (for example, between particles
91  * and gaussian representations) */
92  void copyFrom(const CPose3DPDF& o);
93 
94  /** Save PDF's particles to a text file, containing the 2D pose in the first
95  * line, then the covariance matrix in next 3 lines. */
96  bool saveToTextFile(const std::string& file) const override;
97 
98  /** this = p (+) this. This can be used to convert a PDF from local
99  * coordinates to global, providing the point (newReferenceBase) from which
100  * "to project" the current pdf. Result PDF substituted the currently
101  * stored one in the object.
102  */
103  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
104 
105  /** this = p (+) this. This can be used to convert a PDF from local
106  * coordinates to global, providing the point (newReferenceBase) from which
107  * "to project" the current pdf. Result PDF substituted the currently
108  * stored one in the object.
109  */
110  void changeCoordinatesReference(const CPose2D& newReferenceBase);
111 
112  /** Rotate the covariance matrix by replacing it by \f$
113  * \mathbf{R}~\mathbf{COV}~\mathbf{R}^t \f$, where \f$ \mathbf{R} = \left[
114  * \begin{array}{ccc} \cos\alpha & -\sin\alpha & 0 \\ \sin\alpha &
115  * \cos\alpha & 0 \\ 0 & 0 & 1 \end{array}\right] \f$.
116  */
117  void rotateCov(const double ang);
118 
119  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
120  * operator and the covariances through the corresponding Jacobians (For
121  * 'x0' and 'x1' being independent variables!). */
122  void inverseComposition(
123  const CPosePDFGaussian& x, const CPosePDFGaussian& ref);
124 
125  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
126  * operator and the covariances through the corresponding Jacobians (Given
127  * the 3x3 cross-covariance matrix of variables x0 and x1). */
128  void inverseComposition(
129  const CPosePDFGaussian& x1, const CPosePDFGaussian& x0,
130  const mrpt::math::CMatrixDouble33& COV_01);
131 
132  /** Draws a single sample from the distribution
133  */
134  void drawSingleSample(CPose2D& outPart) const override;
135 
136  /** Draws a number of samples from the distribution, and saves as a list of
137  * 1x3 vectors, where each row contains a (x,y,phi) datum.
138  */
139  void drawManySamples(
140  size_t N,
141  std::vector<mrpt::math::CVectorDouble>& outSamples) const override;
142 
143  /** Bayesian fusion of two points gauss. distributions, then save the result
144  *in this object.
145  * The process is as follows:<br>
146  * - (x1,S1): Mean and variance of the p1 distribution.
147  * - (x2,S2): Mean and variance of the p2 distribution.
148  * - (x,S): Mean and variance of the resulting distribution.
149  *
150  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
151  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
152  */
153  void bayesianFusion(
154  const CPosePDF& p1, const CPosePDF& p2,
155  const double minMahalanobisDistToDrop = 0) override;
156 
157  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
158  */
159  void inverse(CPosePDF& o) const override;
160 
161  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
162  * mean, and the covariance matrix are updated). */
163  void operator+=(const CPose2D& Ap);
164 
165  /** Evaluates the PDF at a given point. */
166  double evaluatePDF(const CPose2D& x) const;
167 
168  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in
169  * the range [0,1]. */
170  double evaluateNormalizedPDF(const CPose2D& x) const;
171 
172  /** Computes the Mahalanobis distance between the centers of two Gaussians.
173  */
174  double mahalanobisDistanceTo(const CPosePDFGaussian& theOther);
175 
176  /** Substitutes the diagonal elements if (square) they are below some given
177  * minimum values (Use this before bayesianFusion, for example, to avoid
178  * inversion of singular matrixes, etc...) */
179  void assureMinCovariance(const double& minStdXY, const double& minStdPhi);
180 
181  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
182  * mean, and the covariance matrix are updated) (see formulas in
183  * jacobiansPoseComposition ). */
184  void operator+=(const CPosePDFGaussian& Ap);
185 
186  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition
187  * (both the mean, and the covariance matrix are updated) */
188  inline void operator-=(const CPosePDFGaussian& ref)
189  {
190  this->inverseComposition(*this, ref);
191  }
192 
193  /** Returns the PDF of the 2D point \f$ g = q \oplus l\f$ with "q"=this pose
194  * and "l" a point without uncertainty */
195  void composePoint(
196  const mrpt::math::TPoint2D& l, CPoint2DPDFGaussian& g) const;
197 
198 }; // End of class def.
199 
200 /** Pose compose operator: RES = A (+) B , computing both the mean and the
201  * covariance */
202 CPosePDFGaussian operator+(
203  const CPosePDFGaussian& a, const CPosePDFGaussian& b);
204 
205 /** Pose inverse compose operator: RES = A (-) B , computing both the mean and
206  * the covariance */
207 CPosePDFGaussian operator-(
208  const CPosePDFGaussian& a, const CPosePDFGaussian& b);
209 
210 /** Dumps the mean and covariance matrix to a text stream. */
211 std::ostream& operator<<(std::ostream& out, const CPosePDFGaussian& obj);
212 
213 /** Returns the Gaussian distribution of \f$ \mathbf{C} \f$, for \f$ \mathbf{C}
214  * = \mathbf{A} \oplus \mathbf{B} \f$. */
217 
218 bool operator==(const CPosePDFGaussian& p1, const CPosePDFGaussian& p2);
219 
220 }
221 #endif
222 
223 
void copyFrom(const CPosePDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
CPosePDFGaussian(const CPosePDF &o)
Copy constructor, including transformations between other PDFs.
CPose2D mean
The mean value.
A gaussian distribution for 2D points.
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
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double minMahalanobisDistToDrop=0) override
Bayesian fusion of two points gauss.
double mahalanobisDistanceTo(const CPosePDFGaussian &theOther)
Computes the Mahalanobis distance between the centers of two Gaussians.
void composePoint(const mrpt::math::TPoint2D &l, CPoint2DPDFGaussian &g) const
Returns the PDF of the 2D point with "q"=this pose and "l" a point without uncertainty.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
const CPose2D & getPoseMean() const
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &out_cov, CPose2D &mean_point) const override
Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once...
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
CPosePDFGaussian()
Default constructor.
CPosePDFGaussian(const CPose3DPDF &o)
Copy constructor, including transformations between other PDFs.
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
double evaluatePDF(const CPose2D &x) const
Evaluates the PDF at a given point.
GLubyte g
Definition: glext.h:6279
GLubyte GLubyte b
Definition: glext.h:6279
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.
double evaluateNormalizedPDF(const CPose2D &x) const
Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
GLsizei const GLchar ** string
Definition: glext.h:4101
void inverseComposition(const CPosePDFGaussian &x, const CPosePDFGaussian &ref)
Set , computing the mean using the "-" operator and the covariances through the corresponding Jacobi...
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 operator-=(const CPosePDFGaussian &ref)
Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated)
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void assureMinCovariance(const double &minStdXY, const double &minStdPhi)
Substitutes the diagonal elements if (square) they are below some given minimum values (Use this befo...
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
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
void getMean(CPose2D &mean_pose) const override
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
GLenum GLint x
Definition: glext.h:3538
void operator+=(const CPose2D &Ap)
Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matri...
void rotateCov(const double ang)
Rotate the covariance matrix by replacing it by , where .
Lightweight 2D point.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
void drawSingleSample(CPose2D &outPart) const override
Draws a single sample from the distribution.
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:40
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 inverse(CPosePDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
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