Main MRPT website > C++ reference for MRPT 1.3.2
CPoint2DPDFGaussian.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-2015, 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 CPoint2DPDFGaussian_H
10 #define CPoint2DPDFGaussian_H
11 
12 #include <mrpt/poses/CPoint2DPDF.h>
13 
14 namespace mrpt
15 {
16 namespace poses
17 {
18  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CPoint2DPDFGaussian, CPoint2DPDF )
19 
20  /** A gaussian distribution for 2D points. Also a method for bayesian fusion is provided.
21  * \ingroup poses_pdf_grp
22  * \sa CPoint2DPDF
23  */
25  {
26  // This must be added to any CSerializable derived class:
28 
29  public:
30  /** Default constructor
31  */
33 
34  /** Constructor
35  */
36  CPoint2DPDFGaussian( const CPoint2D &init_Mean );
37 
38  /** Constructor
39  */
40  CPoint2DPDFGaussian( const CPoint2D &init_Mean, const mrpt::math::CMatrixDouble22 &init_Cov );
41 
42  /** The mean value
43  */
45 
46  /** The 2x2 covariance matrix
47  */
49 
50  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF)
51  */
52  void getMean(CPoint2D &p) const {
53  p = this->mean;
54  }
55 
56  /** Returns an estimate of the point covariance matrix (2x2 cov matrix) and the mean, both at once.
57  * \sa getMean
58  */
60  cov = this->cov;
61  mean_point = this->mean;
62  }
63 
64  /** Copy operator, translating if necesary (for example, between particles and gaussian representations)
65  */
66  void copyFrom(const CPoint2DPDF &o);
67 
68  /** Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance matrix in next 3 lines.
69  */
70  void saveToTextFile(const std::string &file) const;
71 
72  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
73  * "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.
74  */
75  void changeCoordinatesReference( const CPose3D &newReferenceBase );
76 
77  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
78  * The process is as follows:<br>
79  * - (x1,S1): Mean and variance of the p1 distribution.
80  * - (x2,S2): Mean and variance of the p2 distribution.
81  * - (x,S): Mean and variance of the resulting distribution.
82  *
83  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
84  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
85  */
86  void bayesianFusion( const CPoint2DPDFGaussian &p1, const CPoint2DPDFGaussian &p2 );
87 
88  /** 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.
89  * The resulting number is >=0.
90  * \sa productIntegralNormalizedWith
91  * \exception std::exception On errors like covariance matrix with null determinant, etc...
92  */
93  double productIntegralWith( const CPoint2DPDFGaussian &p) const;
94 
95  /** 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.
96  * The resulting number is in the range [0,1].
97  * Note that the resulting value is in fact
98  * \f[ exp( -\frac{1}{2} D^2 ) \f]
99  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
100  * \sa productIntegralWith
101  * \exception std::exception On errors like covariance matrix with null determinant, etc...
102  */
103  double productIntegralNormalizedWith( const CPoint2DPDFGaussian &p) const;
104 
105  /** Draw a sample from the pdf.
106  */
107  void drawSingleSample(CPoint2D &outSample) const;
108 
109  /** 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!)
110  * \param p1 The first distribution to fuse
111  * \param p2 The second distribution to fuse
112  * \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.
113  */
114  void bayesianFusion( const CPoint2DPDF &p1, const CPoint2DPDF &p2, const double &minMahalanobisDistToDrop = 0);
115 
116 
117  /** Returns the Mahalanobis distance from this PDF to another PDF, that is, it's evaluation at (0,0,0) */
118  double mahalanobisDistanceTo( const CPoint2DPDFGaussian & other ) const;
119 
120  /** Returns the Mahalanobis distance from this PDF to some point */
121  double mahalanobisDistanceToPoint( const double x, const double y ) const;
122 
123 
124  }; // End of class def.
126 
127 
128  } // End of namespace
129 } // End of namespace
130 
131 #endif
A gaussian distribution for 2D points.
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...
A numeric matrix of compile-time fixed size.
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
Declares a class that represents a Probability Distribution function (PDF) of a 2D point (x...
Definition: CPoint2DPDF.h:35
#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 class used to store a 2D point.
Definition: CPoint2D.h:36
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 class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:72
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE(class_name, base_name)
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
void getCovarianceAndMean(mrpt::math::CMatrixDouble22 &cov, CPoint2D &mean_point) const
Returns an estimate of the point covariance matrix (2x2 cov matrix) and the mean, both at once...
CMatrixFixedNumeric< double, 2, 2 > CMatrixDouble22
Definition: eigen_frwds.h:45



Page generated by Doxygen 1.8.11 for MRPT 1.3.2 SVN: at Mon May 9 06:50:38 UTC 2016