Main MRPT website > C++ reference for MRPT 1.5.6
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-2017, 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 
20  class CPose3DPDF;
21 
22  // This must be added to any CSerializable derived class:
23  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPosePDFGaussianInf, CPosePDF );
24 
25  /** 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.
26  *
27  * This class implements a PDF as a mono-modal Gaussian distribution in its <b>information form</b>, that is,
28  * keeping the inverse of the covariance matrix instead of the covariance matrix itself.
29  *
30  * This class is the dual of CPosePDFGaussian.
31  *
32  * \sa CPose2D, CPosePDF, CPosePDFParticles
33  * \ingroup poses_pdf_grp
34  */
36  {
37  // This must be added to any CSerializable derived class:
40 
41  protected:
42  /** Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor lead to non-symmetric matrixes!)
43  */
44  void assureSymmetry();
45 
46  public:
47  /** @name Data fields
48  @{ */
49 
50  CPose2D mean; //!< The mean value
51  mrpt::math::CMatrixDouble33 cov_inv; //!< The inverse of the 3x3 covariance matrix (the "information" matrix)
52 
53  /** @} */
54 
55  inline const CPose2D & getPoseMean() const { return mean; }
56  inline CPose2D & getPoseMean() { return mean; }
57 
58  /** Default constructor (mean=all zeros, inverse covariance=all zeros -> so be careful!) */
60 
61  /** Constructor with a mean value (inverse covariance=all zeros -> so be careful!) */
62  explicit CPosePDFGaussianInf( const CPose2D &init_Mean );
63 
64  /** Constructor */
65  CPosePDFGaussianInf( const CPose2D &init_Mean, const mrpt::math::CMatrixDouble33 &init_CovInv );
66 
67  /** Copy constructor, including transformations between other PDFs */
68  explicit CPosePDFGaussianInf( const CPosePDF &o ) { copyFrom( o ); }
69 
70  /** Copy constructor, including transformations between other PDFs */
71  explicit CPosePDFGaussianInf( const CPose3DPDF &o ) { copyFrom( o ); }
72 
73  /** Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
74  * \sa getCovariance */
75  void getMean(CPose2D &mean_pose) const MRPT_OVERRIDE {
76  mean_pose = mean;
77  }
78  bool isInfType() const MRPT_OVERRIDE { return true; }
79 
80  /** Returns an estimate of the pose covariance matrix (3x3 cov matrix) and the mean, both at once.
81  * \sa getMean */
83  mean_point = mean;
84  this->cov_inv.inv(cov);
85  }
86 
87  /** Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) \sa getMean, getCovarianceAndMean */
88  virtual void getInformationMatrix(mrpt::math::CMatrixDouble33 &inf) const MRPT_OVERRIDE { inf=cov_inv; }
89 
90  /** Copy operator, translating if necesary (for example, between particles and gaussian representations) */
91  void copyFrom(const CPosePDF &o) MRPT_OVERRIDE;
92 
93  /** Copy operator, translating if necesary (for example, between particles 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 line, then the covariance matrix in next 3 lines. */
97  void saveToTextFile(const std::string &file) const MRPT_OVERRIDE;
98 
99  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
100  * "to project" the current pdf. Result PDF substituted the currently stored one in the object */
101  void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
102 
103  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
104  * "to project" the current pdf. Result PDF substituted the currently stored one in the object. */
105  void changeCoordinatesReference( const CPose2D &newReferenceBase );
106 
107  /** 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$. */
108  void rotateCov(const double ang);
109 
110  /** 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!). */
111  void inverseComposition( const CPosePDFGaussianInf &x, const CPosePDFGaussianInf &ref );
112 
113  /** 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). */
114  void inverseComposition(
115  const CPosePDFGaussianInf &x1,
116  const CPosePDFGaussianInf &x0,
117  const mrpt::math::CMatrixDouble33 &COV_01
118  );
119 
120  /** Draws a single sample from the distribution */
121  void drawSingleSample( CPose2D &outPart ) const MRPT_OVERRIDE;
122 
123  /** 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. */
124  void drawManySamples( size_t N, std::vector<mrpt::math::CVectorDouble> & outSamples ) const MRPT_OVERRIDE;
125 
126  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
127  * The process is as follows:<br>
128  * - (x1,S1): Mean and variance of the p1 distribution.
129  * - (x2,S2): Mean and variance of the p2 distribution.
130  * - (x,S): Mean and variance of the resulting distribution.
131  *
132  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
133  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
134  */
135  void bayesianFusion(const CPosePDF &p1,const CPosePDF &p2, const double &minMahalanobisDistToDrop = 0 ) MRPT_OVERRIDE;
136 
137  /** Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF */
138  void inverse(CPosePDF &o) const MRPT_OVERRIDE;
139 
140  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated). */
141  void operator += ( const CPose2D &Ap);
142 
143  /** Evaluates the PDF at a given point */
144  double evaluatePDF( const CPose2D &x ) const;
145 
146  /** Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1]. */
147  double evaluateNormalizedPDF( const CPose2D &x ) const;
148 
149  /** Computes the Mahalanobis distance between the centers of two Gaussians. */
150  double mahalanobisDistanceTo( const CPosePDFGaussianInf& theOther );
151 
152  /** Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matrix are updated) (see formulas in jacobiansPoseComposition ). */
153  void operator += ( const CPosePDFGaussianInf &Ap);
154 
155  /** Makes: thisPDF = thisPDF - Ap, where "-" is pose inverse composition (both the mean, and the covariance matrix are updated) */
156  inline void operator -=( const CPosePDFGaussianInf &ref ) {
157  this->inverseComposition(*this,ref);
158  }
159 
160  }; // End of class def.
161  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE( CPosePDFGaussianInf, CPosePDF );
162 
163  bool BASE_IMPEXP operator==(const CPosePDFGaussianInf &p1,const CPosePDFGaussianInf &p2);
164  /** Pose compose operator: RES = A (+) B , computing both the mean and the covariance */
165  CPosePDFGaussianInf BASE_IMPEXP operator +( const CPosePDFGaussianInf &a, const CPosePDFGaussianInf &b );
166  /** Pose inverse compose operator: RES = A (-) B , computing both the mean and the covariance */
167  CPosePDFGaussianInf BASE_IMPEXP operator -( const CPosePDFGaussianInf &a, const CPosePDFGaussianInf &b );
168  /** Returns the Gaussian distribution of \f$ \mathbf{C} \f$, for \f$ \mathbf{C} = \mathbf{A} \oplus \mathbf{B} \f$. */
170 
171  /** Dumps the mean and covariance matrix to a text stream. */
172  std::ostream BASE_IMPEXP & operator << (std::ostream & out, const CPosePDFGaussianInf& obj);
173 
174  } // End of namespace
175 } // End of namespace
176 
177 #endif
DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(CPose3DPDFGaussianInf, CPose3DPDF)
CPosePDFGaussianInf(const CPose3DPDF &o)
Copy constructor, including transformations between other PDFs.
bool isInfType() const MRPT_OVERRIDE
Returns whether the class instance holds the uncertainty in covariance or information form...
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
void getMean(CPose2D &mean_pose) const MRPT_OVERRIDE
Returns an estimate of the pose, (the mean, or mathematical expectation of the PDF).
GLenum GLint ref
Definition: glext.h:3888
mrpt::math::TPoint2D BASE_IMPEXP 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:359
void saveToTextFile(const std::string &file, mrpt::math::TMatrixTextFileFormat fileFormat=mrpt::math::MATRIX_FORMAT_ENG, bool appendMRPTHeader=false, const std::string &userHeader=std::string()) const
Save matrix to a text file, compatible with MATLAB text format (see also the methods of matrix classe...
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
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:135
CPosePDFGaussianInf(const CPosePDF &o)
Copy constructor, including transformations between other PDFs.
const CPose2D & getPoseMean() const
CPose2D BASE_IMPEXP 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:307
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
Definition: Miscellaneous.h:74
GLubyte GLubyte b
Definition: glext.h:5575
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
GLsizei const GLchar ** string
Definition: glext.h:3919
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:39
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
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 > &p1, const CPoint< DERIVEDCLASS > &p2)
Definition: CPoint.h:130
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:36
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
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...
virtual void getInformationMatrix(mrpt::math::CMatrixDouble33 &inf) const MRPT_OVERRIDE
Returns the information (inverse covariance) matrix (a STATE_LEN x STATE_LEN matrix) ...
GLenum GLint x
Definition: glext.h:3516
GLubyte GLubyte GLubyte a
Definition: glext.h:5575
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:40
mrpt::math::CMatrixDouble33 cov_inv
The inverse of the 3x3 covariance matrix (the "information" matrix)
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
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:106



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019