Main MRPT website > C++ reference
MRPT logo
CPoint2DPDFGaussian.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CPoint2DPDFGaussian_H
29 #define CPoint2DPDFGaussian_H
30 
31 #include <mrpt/poses/CPoint2DPDF.h>
32 
33 namespace mrpt
34 {
35 namespace poses
36 {
37  using namespace mrpt::math;
38 
40 
41  /** A gaussian distribution for 2D points. Also a method for bayesian fusion is provided.
42  * \ingroup poses_pdf_grp
43  * \sa CPoint2DPDF
44  */
46  {
47  // This must be added to any CSerializable derived class:
49 
50  public:
51  /** Default constructor
52  */
54 
55  /** Constructor
56  */
57  CPoint2DPDFGaussian( const CPoint2D &init_Mean );
58 
59  /** Constructor
60  */
61  CPoint2DPDFGaussian( const CPoint2D &init_Mean, const CMatrixDouble22 &init_Cov );
62 
63  /** The mean value
64  */
66 
67  /** The 2x2 covariance matrix
68  */
70 
71  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF)
72  */
73  void getMean(CPoint2D &p) const {
74  p = this->mean;
75  }
76 
77  /** Returns an estimate of the point covariance matrix (2x2 cov matrix) and the mean, both at once.
78  * \sa getMean
79  */
80  void getCovarianceAndMean(CMatrixDouble22 &cov,CPoint2D &mean_point) const {
81  cov = this->cov;
82  mean_point = this->mean;
83  }
84 
85  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
86  */
87  void copyFrom(const CPoint2DPDF &o);
88 
89  /** Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance matrix in next 3 lines.
90  */
91  void saveToTextFile(const std::string &file) const;
92 
93  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
94  * "to project" the current pdf. Result PDF substituted the currently stored one in the object. Both the mean value and the covariance matrix are updated correctly.
95  */
96  void changeCoordinatesReference( const CPose3D &newReferenceBase );
97 
98  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
99  * The process is as follows:<br>
100  * - (x1,S1): Mean and variance of the p1 distribution.
101  * - (x2,S2): Mean and variance of the p2 distribution.
102  * - (x,S): Mean and variance of the resulting distribution.
103  *
104  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
105  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
106  */
107  void bayesianFusion( const CPoint2DPDFGaussian &p1, const CPoint2DPDFGaussian &p2 );
108 
109  /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF.
110  * The resulting number is >=0.
111  * \sa productIntegralNormalizedWith
112  * \exception std::exception On errors like covariance matrix with null determinant, etc...
113  */
114  double productIntegralWith( const CPoint2DPDFGaussian &p) const;
115 
116  /** Computes the "correspondence likelihood" of this PDF with another one: This is implemented as the integral from -inf to +inf of the product of both PDF.
117  * The resulting number is in the range [0,1].
118  * Note that the resulting value is in fact
119  * \f[ exp( -\frac{1}{2} D^2 ) \f]
120  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
121  * \sa productIntegralWith
122  * \exception std::exception On errors like covariance matrix with null determinant, etc...
123  */
124  double productIntegralNormalizedWith( const CPoint2DPDFGaussian &p) const;
125 
126  /** Draw a sample from the pdf.
127  */
128  void drawSingleSample(CPoint2D &outSample) const;
129 
130  /** Bayesian fusion of two point distributions (product of two distributions->new distribution), then save the result in this object (WARNING: See implementing classes to see classes that can and cannot be mixtured!)
131  * \param p1 The first distribution to fuse
132  * \param p2 The second distribution to fuse
133  * \param minMahalanobisDistToDrop If set to different of 0, the result of very separate Gaussian modes (that will result in negligible components) in SOGs will be dropped to reduce the number of modes in the output.
134  */
135  void bayesianFusion( const CPoint2DPDF &p1, const CPoint2DPDF &p2, const double &minMahalanobisDistToDrop = 0);
136 
137 
138  /** Returns the Mahalanobis distance from this PDF to another PDF, that is, it's evaluation at (0,0,0)
139  */
140  double mahalanobisDistanceTo( const CPoint2DPDFGaussian & other ) const;
141 
142 
143  }; // End of class def.
144 
145 
146  } // End of namespace
147 } // End of namespace
148 
149 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013