Main MRPT website > C++ reference for MRPT 1.9.9
CParticleFilter_impl.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 CPARTICLEFILTER_IMPL_H
10 #define CPARTICLEFILTER_IMPL_H
11 
14 #include <mrpt/utils/bits.h> // for format, square
15 
16 namespace mrpt
17 {
18 namespace bayes
19 {
20 using namespace mrpt::utils;
21 
22 template <class PARTICLEFILTERCAPABLE, class PF_ALGORITHM>
24  PARTICLEFILTERCAPABLE& obj, const mrpt::obs::CActionCollection* action,
25  const mrpt::obs::CSensoryFrame* observation, TParticleFilterStats* stats)
26 {
28 
29  // 1,2) Prediction & Update stages:
30  // ---------------------------------------------------
31  obj.template prediction_and_update<PF_ALGORITHM>(
32  action, observation, m_options);
33 
34  // 3) Normalize weights:
35  // ---------------------------------------------------
36  obj.m_poseParticles.normalizeWeights();
37 
38  // Save weights statistics?
39  // ---------------------------------------------------
40  if (stats)
41  {
42  const size_t M = obj.m_poseParticles.particlesCount();
43 
44  // ESS:
45  stats->ESS_beforeResample = obj.m_poseParticles.ESS();
46 
47  // Variance:
48  if (M > 1)
49  {
50  double weightsMean = 0, var = 0;
51  for (size_t i = 0; i < M; i++)
52  weightsMean += exp(obj.m_poseParticles.getW(i));
53  weightsMean /= M;
54  for (size_t i = 0; i < M; i++)
55  var += square(exp(obj.m_poseParticles.getW(i)) - weightsMean);
56 
57  var /= (M - 1);
58  stats->weightsVariance_beforeResample = var;
59  }
60  }
61 
62  // 4) Particles resampling stage
63  // ---------------------------------------------------
64  if (!m_options.adaptiveSampleSize &&
65  (PF_ALGORITHM::DoesResampling))
66  {
67  if (obj.m_poseParticles.ESS() < m_options.BETA)
68  {
70  "Resampling particles (ESS was %.02f)\n",
71  obj.m_poseParticles.ESS()));
72  obj.m_poseParticles.performResampling(m_options); // Resample
73  }
74  }
75 
76  MRPT_END
77 }
78 } // namespace bayes
79 } // namespace mrpt
80 #endif
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
This file contains the implementations of the template members declared in mrpt::slam::PF_implementat...
Statistics for being returned from the "execute" method.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
Declares a class for storing a collection of robot actions.
T square(const T x)
Inline function for the square of a number.
Definition: bits.h:55
#define MRPT_END
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
#define MRPT_LOG_DEBUG(_STRING)
#define MRPT_START
void executeOn(PARTICLEFILTERCAPABLE &obj, const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, TParticleFilterStats *stats=nullptr)
Executes a complete prediction + update step of the selected particle filtering algorithm.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019