Main MRPT website > C++ reference for MRPT 1.5.9
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-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 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  CPoint2DPDFGaussian(); //!< Default constructor
31  CPoint2DPDFGaussian( const CPoint2D &init_Mean ); //!< Constructor
32  CPoint2DPDFGaussian( const CPoint2D &init_Mean, const mrpt::math::CMatrixDouble22 &init_Cov ); //!< Constructor
33 
34  CPoint2D mean; //!< The mean value
35  mrpt::math::CMatrixDouble22 cov; //!< The 2x2 covariance matrix
36 
37  /** Returns an estimate of the point, (the mean, or mathematical expectation of the PDF) */
39  p = this->mean;
40  }
41 
42  /** Returns an estimate of the point covariance matrix (2x2 cov matrix) and the mean, both at once. \sa getMean */
44  out_cov = this->cov;
45  mean_point = this->mean;
46  }
47 
48  void copyFrom(const CPoint2DPDF &o) MRPT_OVERRIDE; //!< Copy operator, translating if necesary (for example, between particles and gaussian representations)
49 
50  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 matrix in next 3 lines
51 
52  /** this = p (+) this. This can be used to convert a PDF from local coordinates to global, providing the point (newReferenceBase) from which
53  * "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. */
54  void changeCoordinatesReference( const CPose3D &newReferenceBase ) MRPT_OVERRIDE;
55 
56  /** Bayesian fusion of two points gauss. distributions, then save the result in this object.
57  * The process is as follows:<br>
58  * - (x1,S1): Mean and variance of the p1 distribution.
59  * - (x2,S2): Mean and variance of the p2 distribution.
60  * - (x,S): Mean and variance of the resulting distribution.
61  *
62  * S = (S1<sup>-1</sup> + S2<sup>-1</sup>)<sup>-1</sup>;
63  * x = S * ( S1<sup>-1</sup>*x1 + S2<sup>-1</sup>*x2 );
64  */
65  void bayesianFusion( const CPoint2DPDFGaussian &p1, const CPoint2DPDFGaussian &p2 );
66 
67  /** 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.
68  * The resulting number is >=0.
69  * \sa productIntegralNormalizedWith
70  * \exception std::exception On errors like covariance matrix with null determinant, etc...
71  */
72  double productIntegralWith( const CPoint2DPDFGaussian &p) const;
73 
74  /** 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.
75  * The resulting number is in the range [0,1].
76  * Note that the resulting value is in fact
77  * \f[ exp( -\frac{1}{2} D^2 ) \f]
78  * , with \f$ D^2 \f$ being the square Mahalanobis distance between the two pdfs.
79  * \sa productIntegralWith
80  * \exception std::exception On errors like covariance matrix with null determinant, etc...
81  */
82  double productIntegralNormalizedWith( const CPoint2DPDFGaussian &p) const;
83 
84  void drawSingleSample(CPoint2D &outSample) const MRPT_OVERRIDE; //!< Draw a sample from the pdf
85 
86  /** 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!)
87  * \param p1 The first distribution to fuse
88  * \param p2 The second distribution to fuse
89  * \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.
90  */
91  void bayesianFusion( const CPoint2DPDF &p1, const CPoint2DPDF &p2, const double &minMahalanobisDistToDrop = 0) MRPT_OVERRIDE;
92 
93  double mahalanobisDistanceTo( const CPoint2DPDFGaussian & other ) const; //!< Returns the Mahalanobis distance from this PDF to another PDF, that is, it's evaluation at (0,0,0)
94  double mahalanobisDistanceToPoint( const double x, const double y ) const; //!< Returns the Mahalanobis distance from this PDF to some point
95 
96  }; // End of class def.
98  } // End of namespace
99 } // End of namespace
100 #endif
A gaussian distribution for 2D points.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
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...
void getMean(CPoint2D &p) const MRPT_OVERRIDE
Returns an estimate of the point, (the mean, or mathematical expectation of the PDF) ...
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...
GLsizei const GLchar ** string
Definition: glext.h:3919
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)
GLenum GLint GLint y
Definition: glext.h:3516
void getCovarianceAndMean(mrpt::math::CMatrixDouble22 &out_cov, CPoint2D &mean_point) const MRPT_OVERRIDE
Returns an estimate of the point covariance matrix (2x2 cov matrix) and the mean, both at once...
GLenum GLint x
Definition: glext.h:3516
GLfloat GLfloat p
Definition: glext.h:5587
mrpt::math::CMatrixDouble22 cov
The 2x2 covariance matrix.
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020