Go to the documentation of this file.
33 m_particles.resize(M);
34 for (
auto&
p : m_particles)
40 resetDeterministic(nullPose);
43 void CPosePDFParticles::copyFrom(
const CPosePDF& o)
50 if (
this == &o)
return;
64 size_t M = m_particles.size();
65 std::vector<CVectorDouble> parts;
71 m_particles.resize(M);
73 for (itDest = m_particles.begin(), partsIt = parts.begin();
74 itDest != m_particles.end(); ++itDest, ++partsIt)
78 pdf->
mean.
x() + (*partsIt)[0], (pdf->
mean.
y() + (*partsIt)[1]),
79 (pdf->
mean.
phi() + (*partsIt)[2]));
80 itDest->d.normalizePhi();
89 void CPosePDFParticles::getMean(
CPose2D& est_)
const
92 const size_t n = m_particles.size();
96 for (
size_t i = 0; i <
n; i++)
98 double w = exp(m_particles[i].log_w);
99 se_averager.
append(m_particles[i].d,
w);
109 void CPosePDFParticles::getCovarianceAndMean(
115 size_t i,
n = m_particles.size();
116 double var_x = 0, var_y = 0, var_p = 0, var_xy = 0, var_xp = 0, var_yp = 0;
117 double mean_phi =
mean.phi();
119 if (mean_phi < 0) mean_phi =
M_2PI + mean_phi;
121 double lin_w_sum = 0;
123 for (i = 0; i <
n; i++) lin_w_sum += exp(m_particles[i].log_w);
124 if (lin_w_sum == 0) lin_w_sum = 1;
126 for (i = 0; i <
n; i++)
128 double w = exp(m_particles[i].log_w) / lin_w_sum;
131 double err_x = m_particles[i].d.x -
mean.x();
132 double err_y = m_particles[i].d.y -
mean.y();
139 var_xy += err_x * err_y *
w;
140 var_xp += err_x * err_phi *
w;
141 var_yp += err_y * err_phi *
w;
155 cov(1, 0) =
cov(0, 1) = var_xy;
156 cov(2, 0) =
cov(0, 2) = var_xp;
157 cov(1, 2) =
cov(2, 1) = var_yp;
161 uint8_t CPosePDFParticles::serializeGetVersion()
const {
return 0; }
164 writeParticlesToStream(out);
166 void CPosePDFParticles::serializeFrom(
173 readParticlesFromStream(
in);
181 void CPosePDFParticles::resetDeterministic(
184 if (particlesCount > 0)
185 m_particles.resize(particlesCount);
187 for (
auto&
p : m_particles)
194 void CPosePDFParticles::resetUniform(
195 const double x_min,
const double x_max,
const double y_min,
196 const double y_max,
const double phi_min,
const double phi_max,
197 const int particlesCount)
200 if (particlesCount > 0)
201 m_particles.resize(particlesCount);
203 for (
auto&
p : m_particles)
213 void CPosePDFParticles::resetAroundSetOfPoses(
214 const std::vector<mrpt::math::TPose2D>& list_poses,
215 const size_t num_particles_per_pose,
const double spread_x,
216 const double spread_y,
const double spread_phi_rad)
220 ASSERT_(num_particles_per_pose >= 1);
222 const size_t N = list_poses.size() * num_particles_per_pose;
225 m_particles.resize(N);
227 for (i = 0, nSpot = 0; nSpot < list_poses.size(); nSpot++)
230 for (
size_t k = 0; k < num_particles_per_pose; k++, i++)
234 p.x - spread_x * 0.5,
p.x + spread_x * 0.5);
237 p.y - spread_y * 0.5,
p.y + spread_y * 0.5);
239 p.phi - spread_phi_rad * 0.5,
p.phi + spread_phi_rad * 0.5);
240 m_particles[i].log_w = 0;
252 for (
const auto &
p : m_particles)
255 std::ofstream f(file);
256 if (!f.is_open())
return false;
261 TPose2D CPosePDFParticles::getParticlePose(
size_t i)
const
263 return m_particles[i].d;
266 void CPosePDFParticles::changeCoordinatesReference(
267 const CPose3D& newReferenceBase_)
270 for (
auto &
p : m_particles)
271 p.d = newReferenceBase +
p.d;
274 void CPosePDFParticles::drawSingleSample(
CPose2D& outPart)
const
279 for (
auto &
p : m_particles)
290 outPart =
CPose2D(m_particles.rbegin()->d);
295 for (
auto &
p : m_particles)
302 m_particles.emplace_back(
p);
316 p.d = nullPose -
p.d;
324 double max_w = -std::numeric_limits<double>::max();
325 for (
const auto &
p: m_particles)
336 void CPosePDFParticles::bayesianFusion(
338 const double minMahalanobisDistToDrop)
347 double CPosePDFParticles::evaluatePDF_parzen(
348 const double x,
const double y,
const double phi,
const double stdXY,
349 const double stdPhi)
const
352 for (
const auto &
p : m_particles)
355 ret += exp(
p.log_w) *
362 void CPosePDFParticles::saveParzenPDFToTextFile(
363 const char* fileName,
const double x_min,
const double x_max,
364 const double y_min,
const double y_max,
const double phi,
365 const double stepSizeXY,
const double stdXY,
const double stdPhi)
const
369 for (
double y = y_min;
y < y_max;
y += stepSizeXY)
370 for (
double x = x_min;
x < x_max;
x += stepSizeXY)
371 buf+=
mrpt::format(
"%f ", evaluatePDF_parzen(
x,
y, phi, stdXY, stdPhi));
374 std::ofstream f(fileName);
375 if (!f.is_open())
return;
mrpt::math::TPose2D asTPose() const
void clear()
Clear the contents of this container.
const Scalar * const_iterator
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
const double & phi() const
Get the phi angle of the 2D pose (in radians)
mrpt::math::CMatrixDouble33 cov
The 3x3 covariance matrix.
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
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.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLubyte GLubyte GLubyte GLubyte w
#define THROW_EXCEPTION(msg)
#define ASSERT_(f)
Defines an assertion mechanism.
T square(const T x)
Inline function for the square of a number.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Computes weighted and un-weighted averages of SE(2) poses.
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,...
Virtual base class for "archives": classes abstracting I/O streams.
double normalPDF(double x, double mu, double std)
Evaluates the univariate normal (Gaussian) distribution at a given point "x".
void get_average(mrpt::poses::CPose2D &out_mean) const
Returns the average pose.
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...
CPose2D mean
The mean value.
std::vector< T1 > & operator+=(std::vector< T1 > &a, const std::vector< T2 > &b)
a+=b (element-wise sum)
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm,...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
double x() const
Common members of all points & poses classes.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void copyFrom(const CPosePDF &o) override
Copy operator, translating if necesary (for example, between m_particles and gaussian representations...
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Declares a class that represents a Probability Density Function (PDF) over a 2D pose (x,...
Declares a class that represents a probability density function (pdf) of a 2D pose (x,...
CParticleList m_particles
The array of particles.
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
The namespace for Bayesian filtering algorithm: different particle filters and Kalman filter algorith...
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
This base provides a set of functions for maths stuff.
GLsizei const GLchar ** string
A namespace of pseudo-random numbers generators of diferent distributions.
Declares a class that represents a Probability Density function (PDF) of a 2D pose .
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
void append(const mrpt::poses::CPose2D &p)
Adds a new pose to the computation.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
virtual const mrpt::rtti::TRuntimeClassId * GetRuntimeClass() const override
Returns information about the class of an object in runtime.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |