MRPT  1.9.9
CPosePDFGaussianInf.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 
18 // This must be added to any CSerializable derived class:
19 
20 /** A Probability Density function (PDF) of a 2D pose \f$ p(\mathbf{x}) = [x ~
21  * y ~ \phi ]^t \f$ as a Gaussian with a mean and the inverse of the covariance.
22  *
23  * This class implements a PDF as a mono-modal Gaussian distribution in its
24  * <b>information form</b>, that is,
25  * keeping the inverse of the covariance matrix instead of the covariance
26  * matrix itself.
27  *
28  * This class is the dual of CPosePDFGaussian.
29  *
30  * \sa CPose2D, CPosePDF, CPosePDFParticles
31  * \ingroup poses_pdf_grp
32  */
34 {
35  // 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 enforceCovSymmetry();
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 
82  std::tuple<cov_mat_t, type_value> getCovarianceAndMean() const override
83  {
84  return {cov_inv.inverse_LLt(), mean};
85  }
86 
87  /** Returns the information (inverse covariance) matrix (a STATE_LEN x
88  * STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
90  {
91  inf = cov_inv;
92  }
93 
94  /** Copy operator, translating if necesary (for example, between particles
95  * and gaussian representations) */
96  void copyFrom(const CPosePDF& o) override;
97 
98  /** Copy operator, translating if necesary (for example, between particles
99  * and gaussian representations) */
100  void copyFrom(const CPose3DPDF& o);
101 
102  /** Save PDF's particles to a text file, containing the 2D pose in the first
103  * line, then the covariance matrix in next 3 lines. */
104  bool saveToTextFile(const std::string& file) const override;
105 
106  /** this = p (+) this. This can be used to convert a PDF from local
107  * coordinates to global, providing the point (newReferenceBase) from which
108  * "to project" the current pdf. Result PDF substituted the currently
109  * stored one in the object */
110  void changeCoordinatesReference(const CPose3D& newReferenceBase) override;
111 
112  /** this = p (+) this. This can be used to convert a PDF from local
113  * coordinates to global, providing the point (newReferenceBase) from which
114  * "to project" the current pdf. Result PDF substituted the currently
115  * stored one in the object. */
116  void changeCoordinatesReference(const CPose2D& newReferenceBase);
117 
118  /** Rotate the covariance matrix by replacing it by \f$
119  * \mathbf{R}~\mathbf{COV}~\mathbf{R}^t \f$, where \f$ \mathbf{R} = \left[
120  * \begin{array}{ccc} \cos\alpha & -\sin\alpha & 0 \\ \sin\alpha &
121  * \cos\alpha & 0 \\ 0 & 0 & 1 \end{array}\right] \f$. */
122  void rotateCov(const double ang);
123 
124  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
125  * operator and the covariances through the corresponding Jacobians (For
126  * 'x0' and 'x1' being independent variables!). */
127  void inverseComposition(
128  const CPosePDFGaussianInf& x, const CPosePDFGaussianInf& ref);
129 
130  /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-"
131  * operator and the covariances through the corresponding Jacobians (Given
132  * the 3x3 cross-covariance matrix of variables x0 and x1). */
133  void inverseComposition(
134  const CPosePDFGaussianInf& x1, const CPosePDFGaussianInf& x0,
135  const mrpt::math::CMatrixDouble33& COV_01);
136 
137  /** Draws a single sample from the distribution */
138  void drawSingleSample(CPose2D& outPart) const override;
139 
140  /** Draws a number of samples from the distribution, and saves as a list of
141  * 1x3 vectors, where each row contains a (x,y,phi) datum. */
142  void drawManySamples(
143  size_t N,
144  std::vector<mrpt::math::CVectorDouble>& outSamples) const override;
145 
146  /** Bayesian fusion of two points gauss. distributions, then save the result
147  *in this object.
148  * The process is as follows:<br>
149  * - (x1,S1): Mean and variance of the p1 distribution.
150  * - (x2,S2): Mean and variance of the p2 distribution.
151  * - (x,S): Mean and variance of the resulting distribution.
152  *
153  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
154  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
155  */
156  void bayesianFusion(
157  const CPosePDF& p1, const CPosePDF& p2,
158  const double minMahalanobisDistToDrop = 0) override;
159 
160  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
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 CPosePDFGaussianInf& theOther);
177 
178  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the
179  * mean, and the covariance matrix are updated) (see formulas in
180  * jacobiansPoseComposition ). */
181  void operator+=(const CPosePDFGaussianInf& Ap);
182 
183  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition
184  * (both the mean, and the covariance matrix are updated) */
185  inline void operator-=(const CPosePDFGaussianInf& ref)
186  {
187  this->inverseComposition(*this, ref);
188  }
189 
190 }; // End of class def.
191 
192 bool operator==(const CPosePDFGaussianInf& p1, const CPosePDFGaussianInf& p2);
193 /** Pose compose operator: RES = A (+) B , computing both the mean and the
194  * covariance */
195 CPosePDFGaussianInf operator+(
196  const CPosePDFGaussianInf& a, const CPosePDFGaussianInf& b);
197 /** Pose inverse compose operator: RES = A (-) B , computing both the mean and
198  * the covariance */
199 CPosePDFGaussianInf operator-(
200  const CPosePDFGaussianInf& a, const CPosePDFGaussianInf& b);
201 /** Returns the Gaussian distribution of \f$ \mathbf{C} \f$, for \f$ \mathbf{C}
202  * = \mathbf{A} \oplus \mathbf{B} \f$. */
205 
206 /** Dumps the mean and covariance matrix to a text stream. */
207 std::ostream& operator<<(std::ostream& out, const CPosePDFGaussianInf& obj);
208 
209 } // namespace mrpt::poses
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.
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
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
Definition: CPoint2D.cpp:102
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 enforceCovSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
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.
#define DEFINE_SCHEMA_SERIALIZABLE()
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
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...
void operator-=(const CPosePDFGaussianInf &ref)
Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated)
CMatrixFixed< double, 3, 3 > CMatrixDouble33
Definition: CMatrixFixed.h:367
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:356
Derived inverse_LLt() const
Returns the inverse of a symmetric matrix using LLt.
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...
void getInformationMatrix(mrpt::math::CMatrixDouble33 &inf) const override
Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) ...
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.
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, 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 drawSingleSample(CPose2D &outPart) const override
Draws a single sample from the distribution.
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
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...
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:39
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.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020