42 CPosePDFGaussian::CPosePDFGaussian(
44 :
mean(init_Mean),
cov(init_Cov)
68 out <<
cov(0, 0) <<
cov(1, 1) <<
cov(2, 2);
69 out <<
cov(0, 1) <<
cov(0, 2) <<
cov(1, 2);
130 cov = auxCov.cast<
double>();
143 if (
this == &o)
return;
161 C(2, 0) = C(0, 2) = C(0, 3);
162 C(2, 1) = C(1, 2) = C(1, 3);
164 cov = C.block(0, 0, 3, 3);
188 const CPose3D& newReferenceBase_)
203 const CPose2D& newReferenceBase)
216 const double ccos = cos(ang);
217 const double ssin = sin(ang);
220 const double rot_vals[] = {ccos, -ssin, 0., ssin, ccos, 0., 0., 0., 1.};
223 cov = (rot *
cov * rot.adjoint()).eval();
244 cov.saveToTextFile(
"__DEBUG_EXC_DUMP_drawSingleSample_COV.txt"););
251 size_t N, std::vector<CVectorDouble>& outSamples)
const 255 std::vector<CVectorDouble> rndSamples;
258 outSamples.resize(N);
259 for (
unsigned int i = 0; i < N; i++)
261 outSamples[i].resize(3);
262 outSamples[i][0] =
mean.
x() + rndSamples[i][0];
263 outSamples[i][1] =
mean.
y() + rndSamples[i][1];
264 outSamples[i][2] =
mean.
phi() + rndSamples[i][2];
277 const double& minMahalanobisDistToDrop)
327 const double ccos = ::cos(
mean.
phi());
328 const double ssin = ::sin(
mean.
phi());
331 alignas(16)
const double H_values[] = {
332 -ccos, -ssin,
mean.
x() * ssin -
mean.
y() * ccos,
333 ssin, -ccos,
mean.
x() * ccos +
mean.
y() * ssin,
338 (H *
cov * H.adjoint()).eval();
397 if (MU[0] == 0 && MU[1] == 0 && MU[2] == 0)
402 COV_ += theOther.
cov;
405 COV_.inv_fast(COV_inv);
419 out <<
"Mean: " <<
obj.mean <<
"\n";
420 out <<
"Covariance:\n" <<
obj.cov <<
"\n";
440 const double& minStdXY,
const double& minStdPhi)
456 double cpi = cos(xi.
mean.
phi());
457 double spi = sin(xi.
mean.
phi());
476 dh_xi(0, 2) = -xv_xi * spi + yv_yi * cpi;
479 dh_xi(1, 2) = -xv_xi * cpi - yv_yi * spi;
484 dh_xv.multiply_HCHt(xv.
cov, this->cov);
485 dh_xi.multiply_HCHt(xi.
cov, this->cov,
true);
501 double cp0 = cos(x0.
mean.
phi());
502 double sp0 = sin(x0.
mean.
phi());
521 dh_x0(0, 2) = -xv_xi * sp0 + yv_yi * cp0;
524 dh_x0(1, 2) = -xv_xi * cp0 - yv_yi * sp0;
530 dh_x0.multiply_HCHt(x0.
cov, this->cov);
531 dh_x1.multiply_HCHt(x1.
cov, this->cov,
true);
534 M.multiply_ABCt(dh_x0, COV_01, dh_x1);
536 this->
cov.add_AAt(M);
557 df_dx.multiply_HCHt(OLD_COV,
cov);
558 df_du.multiply_HCHt(Ap.
cov,
cov,
true);
586 g.cov = dp_dx * this->
cov * dp_dx.transpose();
607 res.inverseComposition(
a,
b);
A namespace of pseudo-random numbers genrators of diferent distributions.
double x() const
Common members of all points & poses classes.
void copyFrom(const CPosePDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
CPose2D mean
The mean value.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
#define MRPT_END_WITH_CLEAN_UP(stuff)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
A gaussian distribution for 2D points.
int void fclose(FILE *f)
An OS-independent version of fclose.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
mrpt::math::TPoint2D operator+(const CPose2D &pose, const mrpt::math::TPoint2D &pnt)
Compose a 2D point from a new coordinate base given by a 2D pose.
TDATA getMeanVal() const
Returns the mean, or mathematical expectation of the probability density distribution (PDF)...
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
MAT_C::Scalar multiply_HCHt_scalar(const VECTOR_H &H, const MAT_C &C)
r (a scalar) = H * C * H^t (with a vector H and a symmetric matrix C)
void getCovariance(mrpt::math::CMatrixDouble &cov) const
Returns the estimate of the covariance matrix (STATE_LEN x STATE_LEN covariance matrix) ...
double mahalanobisDistanceTo(const CPosePDFGaussian &theOther)
Computes the Mahalanobis distance between the centers of two Gaussians.
void composePoint(const mrpt::math::TPoint2D &l, CPoint2DPDFGaussian &g) const
Returns the PDF of the 2D point with "q"=this pose and "l" a point without uncertainty.
void composePoint(double lx, double ly, double &gx, double &gy) const
An alternative, slightly more efficient way of doing with G and L being 2D points and P this 2D pose...
GLsizei GLsizei GLuint * obj
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
T square(const T x)
Inline function for the square of a number.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
void wrapToPiInPlace(T &a)
Modifies the given angle to translate it into the ]-pi,pi] range.
This base provides a set of functions for maths stuff.
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
CPosePDFGaussian()
Default constructor.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void drawGaussianMultivariateMany(VECTOR_OF_VECTORS &ret, size_t desiredSamples, const COVMATRIX &cov, const typename VECTOR_OF_VECTORS::value_type *mean=nullptr)
Generate a given number of multidimensional random samples according to a given covariance matrix...
CPose2D operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
void saveToTextFile(const std::string &file) const override
Save PDF's particles to a text file, containing the 2D pose in the first line, then the covariance ma...
double evaluatePDF(const CPose2D &x) const
Evaluates the PDF at a given point.
void drawManySamples(size_t N, std::vector< mrpt::math::CVectorDouble > &outSamples) const override
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.
double evaluateNormalizedPDF(const CPose2D &x) const
Evaluates the ratio PDF(x) / PDF(MEAN), that is, the normalized PDF in the range [0,1].
virtual void getMean(TDATA &mean_point) const =0
Returns the mean, or mathematical expectation of the probability density distribution (PDF)...
GLsizei const GLchar ** string
void inverseComposition(const CPosePDFGaussian &x, const CPosePDFGaussian &ref)
Set , computing the mean using the "-" operator and the covariances through the corresponding Jacobi...
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
virtual const mrpt::utils::TRuntimeClassId * GetRuntimeClass() const override
Returns information about the class of an object in runtime.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void assureMinCovariance(const double &minStdXY, const double &minStdPhi)
Substitutes the diagonal elements if (square) they are below some given minimum values (Use this befo...
bool operator==(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
static void jacobiansPoseComposition(const CPose2D &x, const CPose2D &u, mrpt::math::CMatrixDouble33 &df_dx, mrpt::math::CMatrixDouble33 &df_du, const bool compute_df_dx=true, const bool compute_df_du=true)
This static method computes the pose composition Jacobians, with these formulas:
const double & phi() const
Get the phi angle of the 2D pose (in radians)
void composeFrom(const CPose2D &A, const CPose2D &B)
Makes .
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
void assureSymmetry()
Assures the symmetry of the covariance matrix (eventually certain operations in the math-coprocessor ...
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
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...
void drawGaussianMultivariate(std::vector< T > &out_result, const mrpt::math::CMatrixTemplateNumeric< T > &cov, const std::vector< T > *mean=nullptr)
Generate multidimensional random samples according to a given covariance matrix.
void operator+=(const CPose2D &Ap)
Makes: thisPDF = thisPDF + Ap, where "+" is pose composition (both the mean, and the covariance matri...
This class is a "CSerializable" wrapper for "CMatrixFloat".
void rotateCov(const double ang)
Rotate the covariance matrix by replacing it by , where .
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
double normalPDF(double x, double mu, double std)
Evaluates the univariate normal (Gaussian) distribution at a given point "x".
GLubyte GLubyte GLubyte a
void drawSingleSample(CPose2D &outPart) const override
Draws a single sample from the distribution.
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
void normalizePhi()
Forces "phi" to be in the range [-pi,pi];.
CMatrixFixedNumeric< double, 3, 1 > CMatrixDouble31
void inverse(CPosePDF &o) const override
Returns a new PDF such as: NEW_PDF = (0,0,0) - THIS_PDF.
std::ostream & operator<<(std::ostream &o, const CPoint< DERIVEDCLASS > &p)
Dumps a point as a string [x,y] or [x,y,z].
void bayesianFusion(const CPosePDF &p1, const CPosePDF &p2, const double &minMahalanobisDistToDrop=0) override
Bayesian fusion of two points gauss.