18 #include <Eigen/Dense>    29     setSize(numParticles);
    41     m_particles.resize(numberParticles);
    42     for (
auto& it : m_particles)
    57     if (m_particles.empty())
    60     CParticleList::const_iterator it;
    62     double x = 0, y = 0, z = 0;
    63     for (it = m_particles.begin(); it != m_particles.end(); it++)
    65         const double w = exp(it->log_w);
    94     size_t i, n = m_particles.size();
    95     double var_x = 0, var_y = 0, var_p = 0, var_xy = 0, var_xp = 0, var_yp = 0;
    99     for (i = 0; i < n; i++) lin_w_sum += exp(m_particles[i].log_w);
   100     if (lin_w_sum == 0) lin_w_sum = 1;
   102     for (i = 0; i < n; i++)
   104         double w = exp(m_particles[i].log_w) / lin_w_sum;
   106         double err_x = m_particles[i].d->x - 
mean.x();
   107         double err_y = m_particles[i].d->y - 
mean.y();
   108         double err_phi = m_particles[i].d->z - 
mean.z();
   110         var_x += 
square(err_x) * w;
   111         var_y += 
square(err_y) * w;
   112         var_p += 
square(err_phi) * w;
   113         var_xy += err_x * err_y * w;
   114         var_xp += err_x * err_phi * w;
   115         var_yp += err_y * err_phi * w;
   125         cov(1, 0) = 
cov(0, 1) = var_xy;
   126         cov(2, 0) = 
cov(0, 2) = var_xp;
   127         cov(1, 2) = 
cov(2, 1) = var_yp;
   140     for (
const auto& m_particle : m_particles)
   141         out << m_particle.log_w << m_particle.d->x << m_particle.d->y
   156             for (
auto& m_particle : m_particles)
   157                 in >> m_particle.log_w >> m_particle.d->x >> m_particle.d->y >>
   168     if (
this == &o) 
return;  
   182     if (!f) 
return false;
   184     size_t i, N = m_particles.size();
   185     for (i = 0; i < N; i++)
   187             f, 
"%f %f %f %e\n", m_particles[i].d->x, m_particles[i].d->y,
   188             m_particles[i].d->z, m_particles[i].log_w);
   199     const CPose3D& newReferenceBase)
   202     for (
auto& m_particle : m_particles)
   205             m_particle.d->x, m_particle.d->y, m_particle.d->z,  
   208         m_particle.d->x = 
d2f(pt.
x);
   209         m_particle.d->y = 
d2f(pt.
y);
   210         m_particle.d->z = 
d2f(pt.
z);
   222     Eigen::Vector3d kurts, mu4, m, var;
   229     for (
auto& m_particle : m_particles)
   231         m[0] += m_particle.d->x;
   232         m[1] += m_particle.d->y;
   233         m[2] += m_particle.d->z;
   235     m *= 1.0 / m_particles.size();
   238     for (
auto& m_particle : m_particles)
   240         var[0] += 
square(m_particle.d->x - m[0]);
   241         var[1] += 
square(m_particle.d->y - m[1]);
   242         var[2] += 
square(m_particle.d->z - m[2]);
   244     var *= 1.0 / m_particles.size();
   250     for (
auto& m_particle : m_particles)
   252         mu4[0] += pow(m_particle.d->x - m[0], 4.0);
   253         mu4[1] += pow(m_particle.d->y - m[1], 4.0);
   254         mu4[2] += pow(m_particle.d->z - m[2], 4.0);
   256     mu4 *= 1.0 / m_particles.size();
   259     kurts.array() = mu4.array() / var.array();
   270     [maybe_unused]] 
CPoint3D& outSample)
 const   281     [[maybe_unused]] 
const double minMahalanobisDistToDrop)
 void drawSingleSample(CPoint3D &outSample) const override
Draw a sample from the pdf. 
 
#define THROW_EXCEPTION(msg)
 
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object. 
 
size_t size(const MATRIXLIKE &m, const int dim)
 
int void fclose(FILE *f)
An OS-independent version of fclose. 
 
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files. 
 
This file implements several operations that operate element-wise on individual or pairs of container...
 
bool saveToTextFile(const std::string &file) const override
Save PDF's particles to a text file, where each line is: X Y Z LOG_W. 
 
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations. 
 
#define ASSERT_(f)
Defines an assertion mechanism. 
 
float d2f(const double d)
shortcut for static_cast<float>(double) 
 
This base provides a set of functions for maths stuff. 
 
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!) 
 
CONTAINER::Scalar maximum(const CONTAINER &v)
 
double x() const
Common members of all points & poses classes. 
 
void getMean(CPoint3D &mean_point) const override
 
CMatrixDouble cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
 
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. 
 
return_t square(const num_t x)
Inline function for the square of a number. 
 
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries. 
 
std::tuple< cov_mat_t, type_value > getCovarianceAndMean() const override
Returns an estimate of the pose covariance matrix (STATE_LENxSTATE_LEN cov matrix) and the mean...
 
Virtual base class for "archives": classes abstracting I/O streams. 
 
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive. 
 
A class used to store a 3D pose (a 3D translation + a rotation in 3D). 
 
mrpt::vision::TStereoCalibResults out
 
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive. 
 
void copyFrom(const CPointPDF &o) override
Copy operator, translating if necesary (for example, between particles and gaussian representations) ...
 
void changeCoordinatesReference(const CPose3D &newReferenceBase) override
this = p (+) this. 
 
void setSize(size_t numberParticles, const mrpt::math::TPoint3Df &defaultValue=mrpt::math::TPoint3Df{0, 0, 0})
Erase all the previous particles and change the number of particles, with a given initial value...
 
double mean(const CONTAINER &v)
Computes the mean value of a vector. 
 
void clear()
Clear all the particles (free memory) 
 
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen. 
 
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::optional_ref< mrpt::math::CMatrixDouble33 > out_jacobian_df_dpoint=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dpose=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dse3=std::nullopt, 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...
 
TPoint3D_< float > TPoint3Df
 
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)...