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