39 size_t numberParticles,
const CPoint3D& defaultValue)
42 m_particles.resize(numberParticles);
43 for (
auto& it : m_particles)
58 if (m_particles.empty())
63 double x = 0,
y = 0,
z = 0;
64 for (it = m_particles.begin(); it != m_particles.end(); it++)
66 const double w = exp(it->log_w);
95 size_t i,
n = m_particles.size();
96 double var_x = 0, var_y = 0, var_p = 0, var_xy = 0, var_xp = 0, var_yp = 0;
100 for (i = 0; i <
n; i++) lin_w_sum += exp(m_particles[i].log_w);
101 if (lin_w_sum == 0) lin_w_sum = 1;
103 for (i = 0; i <
n; i++)
105 double w = exp(m_particles[i].log_w) / lin_w_sum;
107 double err_x = m_particles[i].d->x -
mean.x();
108 double err_y = m_particles[i].d->y -
mean.y();
109 double err_phi = m_particles[i].d->z -
mean.z();
114 var_xy += err_x * err_y *
w;
115 var_xp += err_x * err_phi *
w;
116 var_yp += err_y * err_phi *
w;
126 cov(1, 0) =
cov(0, 1) = var_xy;
127 cov(2, 0) =
cov(0, 2) = var_xp;
128 cov(1, 2) =
cov(2, 1) = var_yp;
148 it != m_particles.end(); ++it)
149 out << it->log_w << it->d->x << it->d->y << it->d->z;
167 it != m_particles.end(); ++it)
168 in >> it->log_w >> it->d->x >> it->d->y >> it->d->z;
178 if (
this == &o)
return;
194 size_t i, N = m_particles.size();
195 for (i = 0; i < N; i++)
197 f,
"%f %f %f %e\n", m_particles[i].d->x, m_particles[i].d->y,
198 m_particles[i].d->z, m_particles[i].log_w);
209 const CPose3D& newReferenceBase)
213 it != m_particles.end(); ++it)
216 it->d->x, it->d->y, it->d->z,
241 it != m_particles.end(); ++it)
247 m *= 1.0 / m_particles.size();
251 it != m_particles.end(); ++it)
253 var[0] +=
square(it->d->x - m[0]);
254 var[1] +=
square(it->d->y - m[1]);
255 var[2] +=
square(it->d->z - m[2]);
257 var *= 1.0 / m_particles.size();
264 it != m_particles.end(); ++it)
266 mu4[0] += pow(it->d->x - m[0], 4.0);
267 mu4[1] += pow(it->d->y - m[1], 4.0);
268 mu4[2] += pow(it->d->z - m[2], 4.0);
270 mu4 *= 1.0 / m_particles.size();
273 kurts.array() = mu4.array() / var.array();
294 const double& minMahalanobisDistToDrop)
void drawSingleSample(CPoint3D &outSample) const override
Draw a sample from the pdf.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
The virtual base class which provides a unified interface for all persistent objects in MRPT...
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.
#define THROW_EXCEPTION(msg)
This file implements several operations that operate element-wise on individual or pairs of container...
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
const Scalar * const_iterator
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
GLubyte GLubyte GLubyte GLubyte w
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...
This base provides a set of functions for maths stuff.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void setSize(size_t numberParticles, const CPoint3D &defaultValue=CPoint3D(0, 0, 0))
Erase all the previous particles and change the number of particles, with a given initial value...
EIGEN_STRONG_INLINE void setSize(size_t row, size_t col)
Changes the size of matrix, maintaining its previous content as possible and padding with zeros where...
Data within each particle.
double x
X,Y,Z coordinates.
void getMean(CPoint3D &mean_point) const override
Returns an estimate of the point, (the mean, or mathematical expectation of the PDF) ...
CONTAINER::Scalar maximum(const CONTAINER &v)
void bayesianFusion(const CPointPDF &p1, const CPointPDF &p2, const double &minMahalanobisDistToDrop=0) override
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!)
GLsizei const GLchar ** string
A class used to store a 3D point.
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.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
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 copyFrom(const CPointPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this.
void clear()
Clear all the particles (free memory)
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 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 writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
void getCovarianceAndMean(mrpt::math::CMatrixDouble33 &cov, CPoint3D &mean_point) const override
Returns an estimate of the point covariance matrix (3x3 cov matrix) and the mean, both at once...
unsigned __int32 uint32_t
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
double computeKurtosis()
Compute the kurtosis of the distribution.
A probability distribution of a 2D/3D point, represented as a set of random samples (particles)...
void saveToTextFile(const std::string &file) const override
Save PDF's particles to a text file, where each line is: X Y Z LOG_W.
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.