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



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST