Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
15namespace mrpt
16{
17namespace poses
18{
19 class CPose3DPDF;
20
21 // This must be added to any CSerializable derived class:
23
24 /** A Probability Density function (PDF) of a 2D pose \f$ p(\mathbf{x}) = [x ~ 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 <b>information form</b>, that is,
27 * keeping the inverse of the covariance matrix instead of the covariance matrix itself.
28 *
29 * This class is the dual of CPosePDFGaussian.
30 *
31 * \sa CPose2D, CPosePDF, CPosePDFParticles
32 * \ingroup poses_pdf_grp
33 */
35 {
36 // This must be added to any CSerializable derived class:
38
39 protected:
40 /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
41 */
43
44 public:
45 /** @name Data fields
46 @{ */
47
48 CPose2D mean; //!< The mean value
49 mrpt::math::CMatrixDouble33 cov_inv; //!< The inverse of the 3x3 covariance matrix (the "information" matrix)
50
51 /** @} */
52
53 inline const CPose2D & getPoseMean() const { return mean; }
54 inline CPose2D & getPoseMean() { return mean; }
55
56 /** Default constructor (mean=all zeros, inverse covariance=all zeros -> so be careful!) */
58
59 /** Constructor with a mean value (inverse covariance=all zeros -> so be careful!) */
60 explicit CPosePDFGaussianInf( const CPose2D &init_Mean );
61
62 /** Constructor */
63 CPosePDFGaussianInf( const CPose2D &init_Mean, const mrpt::math::CMatrixDouble33 &init_CovInv );
64
65 /** Copy constructor, including transformations between other PDFs */
66 explicit CPosePDFGaussianInf( const CPosePDF &o ) { copyFrom( o ); }
67
68 /** Copy constructor, including transformations between other PDFs */
69 explicit CPosePDFGaussianInf( const CPose3DPDF &o ) { copyFrom( o ); }
70
71 /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
72 * \sa getCovariance */
73 void getMean(CPose2D &mean_pose) const MRPT_OVERRIDE {
74 mean_pose = mean;
75 }
76
77 /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once.
78 * \sa getMean */
80 mean_point = mean;
81 this->cov_inv.inv(cov);
82 }
83
84 /** Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
85 virtual void getInformationMatrix(mrpt::math::CMatrixDouble33 &inf) const MRPT_OVERRIDE { inf=cov_inv; }
86
87 /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
89
90 /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
91 void copyFrom(const CPose3DPDF &o);
92
93 /** Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance matrix in next 3 lines. */
94 void saveToTextFile(const std::string &file) const MRPT_OVERRIDE;
95
96 /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
97 * "to project" the current pdf. Result PDF substituted the currently stored one in the object */
98 void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
99
100 /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
101 * "to project" the current pdf. Result PDF substituted the currently stored one in the object. */
102 void changeCoordinatesReference( const CPose2D &newReferenceBase );
103
104 /** Rotate the covariance matrix by replacing it by \f$ \mathbf{R}~\mathbf{COV}~\mathbf{R}^t \f$, where \f$ \mathbf{R} = \left[ \begin{array}{ccc} \cos\alpha & -\sin\alpha & 0 \\ \sin\alpha & \cos\alpha & 0 \\ 0 & 0 & 1 \end{array}\right] \f$. */
105 void rotateCov(const double ang);
106
107 /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-" operator and the covariances through the corresponding Jacobians (For 'x0' and 'x1' being independent variables!). */
109
110 /** Set \f$ this = x1 \ominus x0 \f$ , computing the mean using the "-" operator and the covariances through the corresponding Jacobians (Given the 3x3 cross-covariance matrix of variables x0 and x1). */
112 const CPosePDFGaussianInf &x1,
113 const CPosePDFGaussianInf &x0,
114 const mrpt::math::CMatrixDouble33 &COV_01
115 );
116
117 /** Draws a single sample from the distribution */
118 void drawSingleSample( CPose2D &outPart ) const MRPT_OVERRIDE;
119
120 /** 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. */
121 void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const MRPT_OVERRIDE;
122
123 /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
124 * The process is as follows:<br>
125 * - (x1,S1): Mean and variance of the p1 distribution.
126 * - (x2,S2): Mean and variance of the p2 distribution.
127 * - (x,S): Mean and variance of the resulting distribution.
128 *
129 * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
130 * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
131 */
132 void bayesianFusion(const CPosePDF &p1,const CPosePDF &p2, const double &minMahalanobisDistToDrop = 0 ) MRPT_OVERRIDE;
133
134 /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
135 void inverse(CPosePDF &o) const MRPT_OVERRIDE;
136
137 /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated). */
138 void operator += ( const CPose2D &Ap);
139
140 /** Evaluates the PDF at a given point */
141 double evaluatePDF( const CPose2D &x ) const;
142
143 /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1]. */
144 double evaluateNormalizedPDF( const CPose2D &x ) const;
145
146 /** Computes the Mahalanobis distance between the centers of two Gaussians. */
147 double mahalanobisDistanceTo( const CPosePDFGaussianInf& theOther );
148
149 /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated) (see formulas in jacobiansPoseComposition ). */
150 void operator += ( const CPosePDFGaussianInf &Ap);
151
152 /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated) */
153 inline void operator -=( const CPosePDFGaussianInf &ref ) {
154 this->inverseComposition(*this,ref);
155 }
156
157 }; // End of class def.
158 DEFINE_SERIALIZABLE_POST_CUSTOM_BASE( CPosePDFGaussianInf, CPosePDF )
159
160 bool BASE_IMPEXP operator==(const CPosePDFGaussianInf &p1,const CPosePDFGaussianInf &p2);
161 /** Pose compose operator: RES = A (+) B , computing both the mean and the covariance */
163 /** Pose inverse compose operator: RES = A (-) B , computing both the mean and the covariance */
165 /** Returns the Gaussian distribution of \f$ \mathbf{C} \f$, for \f$ \mathbf{C} = \mathbf{A} \oplus \mathbf{B} \f$. */
166 poses::CPosePDFGaussianInf BASE_IMPEXP operator + ( const mrpt::poses::CPose2D &A, const mrpt::poses::CPosePDFGaussianInf &B );
167
168 /** Dumps the mean and covariance matrix to a text stream. */
169 std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPosePDFGaussianInf& obj);
170
171 } // End of namespace
172} // End of namespace
173
174#endif
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
A numeric matrix of compile-time fixed size.
A class used to store a 2D pose.
Definition CPose2D.h:37
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition CPose3D.h:73
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually).
Definition CPose3DPDF.h:41
A Probability Density function (PDF) of a 2D pose as a Gaussian with a mean and the inverse of the c...
virtual void getInformationMatrix(mrpt::math::CMatrixDouble33 &inf) const MRPT_OVERRIDE
Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix)
void changeCoordinatesReference(const CPose2D &newReferenceBase)
this = p (+) this.
CPosePDFGaussianInf()
Default constructor (mean=all zeros, inverse covariance=all zeros -> so be careful!...
void drawSingleSample(CPose2D &outPart) const MRPT_OVERRIDE
Draws a single sample from the distribution.
CPosePDFGaussianInf(const CPose2D &init_Mean, const mrpt::math::CMatrixDouble33 &init_CovInv)
Constructor.
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPose2D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once.
void changeCoordinatesReference(const CPose3D &newReferenceBase) MRPT_OVERRIDE
this = p (+) this.
void inverseComposition(const CPosePDFGaussianInf &x1, const CPosePDFGaussianInf &x0, const mrpt::math::CMatrixDouble33 &COV_01)
Set , computing the mean using the "-" operator and the covariances through the corresponding Jacobi...
void getMean(CPose2D &mean_pose) const MRPT_OVERRIDE
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
void drawManySamples(size_t N, std::vector< mrpt::math::CVectorDouble > &outSamples) const MRPT_OVERRIDE
Draws a number of samples from the distribution, and saves as a list of 1x3 vectors,...
void copyFrom(const CPosePDF &o) MRPT_OVERRIDE
Copy operator, translating if necesary (for example, between particles and gaussian representations)
void saveToTextFile(const std::string &file) const MRPT_OVERRIDE
Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance ma...
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
void inverseComposition(const CPosePDFGaussianInf &x, const CPosePDFGaussianInf &ref)
Set , computing the mean using the "-" operator and the covariances through the corresponding Jacobi...
mrpt::math::CMatrixDouble33 cov_inv
The inverse of the 3x3 covariance matrix (the "information" matrix)
CPosePDFGaussianInf(const CPose3DPDF &o)
Copy constructor, including transformations between other PDFs.
void copyFrom(const CPose3DPDF &o)
Copy operator, translating if necesary (for example, between particles and gaussian representations)
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double &minMahalanobisDistToDrop=0) MRPT_OVERRIDE
Bayesian fusion of two points gauss.
CPosePDFGaussianInf(const CPosePDF &o)
Copy constructor, including transformations between other PDFs.
void rotateCov(const double ang)
Rotate the covariance matrix by replacing it by , where .
const CPose2D & getPoseMean() const
CPosePDFGaussianInf(const CPose2D &init_Mean)
Constructor with a mean value (inverse covariance=all zeros -> so be careful!)
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
Definition CPosePDF.h:40
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition mrpt_macros.h:28
class BASE_IMPEXP CPose3DPDF
Definition CPose3DPDF.h:23
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
STL namespace.



Page generated by Doxygen 1.9.7 for MRPT 1.4.0 SVN: at Tue Jun 13 13:45:58 UTC 2023