MRPT  2.0.1
CPosePDFGaussian.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/math/CMatrixFixed.h>
12 #include <mrpt/poses/CPosePDF.h>
13 
14 namespace mrpt::poses
15 {
16 class CPose3DPDF;
17 class CPoint2DPDFGaussian;
18 
19 /** Declares a class that represents a Probability Density function (PDF) of a
20  * 2D pose \f$ p(\mathbf{x}) = [x ~ y ~ \phi ]^t \f$.
21  *
22  * This class implements that PDF using a mono-modal Gaussian distribution.
23  * See mrpt::poses::CPosePDF for more details.
24  *
25  * \sa CPose2D, CPosePDF, CPosePDFParticles
26  * \ingroup poses_pdf_grp
27  */
28 class CPosePDFGaussian : public CPosePDF
29 {
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 enforceCovSymmetry();
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 
70  void getMean(CPose2D& mean_pose) const override { mean_pose = mean; }
71 
72  std::tuple<cov_mat_t, type_value> getCovarianceAndMean() const override
73  {
74  return {cov, mean};
75  }
76 
77  /** Copy operator, translating if necesary (for example, between particles
78  * and gaussian representations) */
79  void copyFrom(const CPosePDF& o) override;
80 
81  /** Copy operator, translating if necesary (for example, between particles
82  * and gaussian representations) */
83  void copyFrom(const CPose3DPDF& o);
84 
85  /** Save PDF's particles to a text file, containing the 2D pose in the first
86  * line, then the covariance matrix in next 3 lines. */
87  bool saveToTextFile(const std::string& file) const override;
88 
89  /** this = p (+) this. This can be used to convert a PDF from local
90  * coordinates to global, providing the point (newReferenceBase) from which
91  * "to project" the current pdf. Result PDF substituted the currently
92  * stored one in the object.
93  */
94  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
95 
96  /** this = p (+) this. This can be used to convert a PDF from local
97  * coordinates to global, providing the point (newReferenceBase) from which
98  * "to project" the current pdf. Result PDF substituted the currently
99  * stored one in the object.
100  */
101  void changeCoordinatesReference(const CPose2D& newReferenceBase);
102 
103  /** Rotate the covariance matrix by replacing it by \f$
104  * \mathbf{R}~\mathbf{COV}~\mathbf{R}^t \f$, where \f$ \mathbf{R} = \left[
105  * \begin{array}{ccc} \cos\alpha & -\sin\alpha & 0 \\ \sin\alpha &
106  * \cos\alpha & 0 \\ 0 & 0 & 1 \end{array}\right] \f$.
107  */
108  void rotateCov(const double ang);
109 
110  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
111  * operator and the covariances through the corresponding Jacobians (For
112  * 'x0' and 'x1' being independent variables!). */
113  void inverseComposition(
114  const CPosePDFGaussian& x, const CPosePDFGaussian& ref);
115 
116  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
117  * operator and the covariances through the corresponding Jacobians (Given
118  * the 3x3 cross-covariance matrix of variables x0 and x1). */
119  void inverseComposition(
120  const CPosePDFGaussian& x1, const CPosePDFGaussian& x0,
121  const mrpt::math::CMatrixDouble33& COV_01);
122 
123  /** Draws a single sample from the distribution
124  */
125  void drawSingleSample(CPose2D& outPart) const override;
126 
127  /** Draws a number of samples from the distribution, and saves as a list of
128  * 1x3 vectors, where each row contains a (x,y,phi) datum.
129  */
130  void drawManySamples(
131  size_t N,
132  std::vector<mrpt::math::CVectorDouble>& outSamples) const override;
133 
134  /** Bayesian fusion of two points gauss. distributions, then save the result
135  *in this object.
136  * The process is as follows:<br>
137  * - (x1,S1): Mean and variance of the p1 distribution.
138  * - (x2,S2): Mean and variance of the p2 distribution.
139  * - (x,S): Mean and variance of the resulting distribution.
140  *
141  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
142  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
143  */
144  void bayesianFusion(
145  const CPosePDF& p1, const CPosePDF& p2,
146  const double minMahalanobisDistToDrop = 0) override;
147 
148  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF
149  */
150  void inverse(CPosePDF& o) const override;
151 
152  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
153  * mean, and the covariance matrix are updated). */
154  void operator+=(const CPose2D& Ap);
155 
156  /** Evaluates the PDF at a given point. */
157  double evaluatePDF(const CPose2D& x) const;
158 
159  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in
160  * the range [0,1]. */
161  double evaluateNormalizedPDF(const CPose2D& x) const;
162 
163  /** Computes the Mahalanobis distance between the centers of two Gaussians.
164  */
165  double mahalanobisDistanceTo(const CPosePDFGaussian& theOther);
166 
167  /** Substitutes the diagonal elements if (square) they are below some given
168  * minimum values (Use this before bayesianFusion, for example, to avoid
169  * inversion of singular matrixes, etc...) */
170  void assureMinCovariance(double minStdXY, double minStdPhi);
171 
172  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
173  * mean, and the covariance matrix are updated) (see formulas in
174  * jacobiansPoseComposition ). */
175  void operator+=(const CPosePDFGaussian& Ap);
176 
177  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition
178  * (both the mean, and the covariance matrix are updated) */
179  inline void operator-=(const CPosePDFGaussian& ref)
180  {
181  this->inverseComposition(*this, ref);
182  }
183 
184  /** Returns the PDF of the 2D point \f$ g = q \oplus l\f$ with "q"=this pose
185  * and "l" a point without uncertainty */
186  void composePoint(
187  const mrpt::math::TPoint2D& l, CPoint2DPDFGaussian& g) const;
188 
189 }; // End of class def.
190 
191 /** Pose compose operator: RES = A (+) B , computing both the mean and the
192  * covariance */
193 CPosePDFGaussian operator+(
194  const CPosePDFGaussian& a, const CPosePDFGaussian& b);
195 
196 /** Pose inverse compose operator: RES = A (-) B , computing both the mean and
197  * the covariance */
198 CPosePDFGaussian operator-(
199  const CPosePDFGaussian& a, const CPosePDFGaussian& b);
200 
201 /** Dumps the mean and covariance matrix to a text stream. */
202 std::ostream& operator<<(std::ostream& out, const CPosePDFGaussian& obj);
203 
204 /** Returns the Gaussian distribution of \f$ \mathbf{C} \f$, for \f$ \mathbf{C}
205  * = \mathbf{A} \oplus \mathbf{B} \f$. */
208 
209 bool operator==(const CPosePDFGaussian& p1, const CPosePDFGaussian& p2);
210 
211 } // namespace mrpt::poses
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.
std::tuple< cov_mat_t, type_value > getCovarianceAndMean() const override
Returns an estimate of the pose covariance matrix (STATE_LENxSTATE_LEN cov matrix) and the mean...
A gaussian distribution for 2D points.
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:394
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double minMahalanobisDistToDrop=0) override
Bayesian fusion of two points gauss.
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
void assureMinCovariance(double minStdXY, double minStdPhi)
Substitutes the diagonal elements if (square) they are below some given minimum values (Use this befo...
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.
#define DEFINE_SCHEMA_SERIALIZABLE()
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const CPose2D & getPoseMean() const
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
CMatrixFixed< double, 3, 3 > CMatrixDouble33
Definition: CMatrixFixed.h:367
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:356
double evaluatePDF(const CPose2D &x) const
Evaluates the PDF at a given point.
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].
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:38
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Base template for TPoint2D and TPoint2Df.
Definition: TPoint2D.h:32
void operator-=(const CPosePDFGaussian &ref)
Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool operator==(const CPoint< DERIVEDCLASS, DIM > &p1, const CPoint< DERIVEDCLASS, DIM > &p2)
Definition: CPoint.h:119
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:39
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults out
void enforceCovSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
void getMean(CPose2D &mean_pose) const override
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
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 .
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:39
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.



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020