Main MRPT website > C++ reference for MRPT 1.9.9
CParticleFilter.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_H
10 #define CPARTICLEFILTER_H
11 
12 #include <mrpt/utils/core_defs.h>
15 #include <mrpt/utils/TEnumType.h>
16 
17 namespace mrpt
18 {
19 namespace obs
20 {
21 class CSensoryFrame;
22 class CActionCollection;
23 } // namespace obs
24 
25 /** The namespace for Bayesian filtering algorithm: different particle filters
26  * and Kalman filter algorithms. \ingroup mrpt_base_grp
27  */
28 namespace bayes
29 {
30 /** This class acts as a common interface to the different interfaces (see
31  *CParticleFilter::TParticleFilterAlgorithm) any bayes::CParticleFilterCapable
32  *class can implement: it is the invoker of particle filter algorithms.
33  * The particle filter is executed on a probability density function (PDF)
34  *described by a CParticleFilterCapable object, passed in the constructor or
35  *alternatively through the CParticleFilter::executeOn method.<br>
36  *
37  * For a complete example and further details, see the <a
38  *href="http://www.mrpt.org/Particle_Filter_Tutorial" >Particle Filter
39  *tutorial</a>.
40  *
41  * The basic SIR algorithm (pfStandardProposal) consists of:
42  * - Execute a prediction with the given "action".
43  * - Update the weights of the particles using the likelihood of the
44  *"observation".
45  * - Normalize weights.
46  * - Perform resampling if the ESS is below the threshold options.BETA.
47  *
48  * \ingroup mrpt_base_grp
49  * \sa mrpt::poses::CPoseParticlesPDF
50  */
51 class CParticleFilter : public mrpt::utils::COutputLogger
52 {
53  public:
54  /** Defines different types of particle filter algorithms.
55  * The defined SIR implementations are:
56  * - pfStandardProposal: Standard proposal distribution + weights
57  *according to likelihood function.
58  * - pfAuxiliaryPFStandard: An auxiliary PF using the standard proposal
59  *distribution.
60  * - pfOptimalProposal: Use the optimal proposal distribution (where
61  *available!, usually this will perform approximations)
62  * - pfAuxiliaryPFOptimal: Use the optimal proposal and a auxiliary
63  *particle filter (see <a
64  *href="http://www.mrpt.org/Paper:An_Optimal_Filtering_Algorithm_for_Non-Parametric_Observation_Models_in_Robot_Localization_(ICRA_2008)"
65  *>paper</a>).
66  *
67  * See the theoretical discussion in <a
68  *href="http://www.mrpt.org/Resampling_Schemes" >resampling schemes</a>.
69  */
71  {
76  };
77 
78  /** Defines the different resampling algorithms.
79  * The implemented resampling methods are:
80  * - prMultinomial (Default): Uses standard select with replacement
81  *(draws
82  *M random uniform numbers)
83  * - prResidual: The residual or "remainder" method.
84  * - prStratified: The stratified resampling, where a uniform sample is
85  *drawn for each of M subdivisions of the range (0,1].
86  * - prSystematic: A single uniform sample is drawn in the range
87  *(0,1/M].
88  *
89  * See the theoretical discussion in <a
90  *href="http://www.mrpt.org/Resampling_Schemes" >resampling schemes</a>.
91  */
93  {
98  };
99 
100  /** The configuration of a particle filter.
101  */
104  {
105  public:
106  /** Initilization of default parameters */
108  // See base docs:
109  void loadFromConfigFile(
111  const std::string& section) override;
112  virtual void saveToConfigFile(
114  const std::string& section) const override;
115 
116  /** A flag that indicates whether the CParticleFilterCapable object
117  * should perform adative sample size (default=false). */
119  /** The resampling of particles will be performed when ESS (in range
120  * [0,1]) < BETA (default is 0.5) */
121  double BETA;
122  /** The initial number of particles in the filter (it can change only if
123  * adaptiveSampleSize=true) (default=1) */
124  unsigned int sampleSize;
125 
126  /** In the algorithm "CParticleFilter::pfAuxiliaryPFOptimal" (and in
127  * "CParticleFilter::pfAuxiliaryPFStandard" only if
128  * pfAuxFilterStandard_FirstStageWeightsMonteCarlo = true) the number of
129  * samples for searching the maximum likelihood value and also to
130  * estimate the "first stage weights" (see papers!) (default=100)
131  */
133  /** An optional step to "smooth" dramatic changes in the observation
134  * model to affect the variance of the particle weights, eg
135  * weight*=likelihood^powFactor (default=1 = no effects). */
136  double powFactor;
137  /** The PF algorithm to use (default=pfStandardProposal) See
138  * TParticleFilterAlgorithm for the posibilities. */
140  /** The resampling algorithm to use (default=prMultinomial). */
142 
143  /** Only for PF_algorithm=pfAuxiliaryPFOptimal: If a given particle has
144  * a max_likelihood (from the a-priori estimate) below the maximum from
145  * all the samples - max_loglikelihood_dyn_range, then the particle is
146  * directly discarded.
147  * This is done to assure that the rejection sampling doesn't get
148  * stuck in an infinite loop trying to get an acceptable sample.
149  * Default = 15 (in logarithmic likelihood)
150  */
152 
153  /** Only for PF_algorithm==pfAuxiliaryPFStandard:
154  * If false, the APF will predict the first stage weights just at the
155  * mean of the prior of the next time step.
156  * If true, these weights will be estimated as described in the papers
157  * for the "pfAuxiliaryPFOptimal" method, i.e. through a monte carlo
158  * simulation.
159  * In that case, "pfAuxFilterOptimal_MaximumSearchSamples" is the
160  * number of MC samples used.
161  */
163 
164  /** (Default=false) In the algorithm
165  * "CParticleFilter::pfAuxiliaryPFOptimal", if set to true, do not
166  * perform rejection sampling, but just the most-likely (ML) particle
167  * found in the preliminary weight-determination stage. */
169  };
170 
171  /** Statistics for being returned from the "execute" method. */
173  {
176  {
177  }
180  };
181 
182  /** Default constructor.
183  * After creating the PF object, set the options in
184  * CParticleFilter::m_options, then execute steps through
185  * CParticleFilter::executeOn.
186  */
187  CParticleFilter();
188 
189  virtual ~CParticleFilter() {}
190  /** Executes a complete prediction + update step of the selected particle
191  * filtering algorithm.
192  * The member CParticleFilter::m_options must be set before calling this
193  * to settle the algorithm parameters.
194  *
195  * \param obj The object representing the probability distribution
196  * function (PDF) which apply the particle filter algorithm to.
197  * \param action A pointer to an action in the form of a
198  * CActionCollection,
199  * or nullptr if there is no action.
200  * \param observation A pointer to observations in the form of a
201  * CSensoryFrame, or nullptr if there is no observation.
202  * \param stats An output structure for gathering statistics of the particle
203  * filter execution, or set to nullptr if you do not need it (see
204  * CParticleFilter::TParticleFilterStats).
205  *
206  * \sa CParticleFilterCapable, executeOn
207  */
208  template <class PARTICLEFILTERCAPABLE, class PF_ALGORITHM>
209  void executeOn(
210  PARTICLEFILTERCAPABLE& obj, const mrpt::obs::CActionCollection* action,
211  const mrpt::obs::CSensoryFrame* observation,
212  TParticleFilterStats* stats = nullptr);
213 
214  /** The options to be used in the PF, must be set before executing any step
215  * of the particle filter.
216  */
218 
219 }; // End of class def.
220 
221 } // namespace bayes
222 // Specializations MUST occur at the same namespace:
223 namespace utils
224 {
225 template <>
227 {
229  static void fill(bimap<enum_t, std::string>& m_map)
230  {
231  using namespace mrpt::bayes;
232  m_map.insert(CParticleFilter::pfStandardProposal, "pfStandardProposal");
233  m_map.insert(
234  CParticleFilter::pfAuxiliaryPFOptimal, "pfAuxiliaryPFOptimal");
235  m_map.insert(
236  CParticleFilter::pfAuxiliaryPFStandard, "pfAuxiliaryPFStandard");
237  m_map.insert(CParticleFilter::pfOptimalProposal, "pfOptimalProposal");
238  }
239 };
240 template <>
243 {
245  static void fill(bimap<enum_t, std::string>& m_map)
246  {
247  using namespace mrpt::bayes;
248  m_map.insert(CParticleFilter::prMultinomial, "prMultinomial");
249  m_map.insert(CParticleFilter::prResidual, "prResidual");
250  m_map.insert(CParticleFilter::prStratified, "prStratified");
251  m_map.insert(CParticleFilter::prSystematic, "prSystematic");
252  }
253 };
254 
255 } // namespace utils
256 } // namespace mrpt
257 #endif
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string &section) override
This method load the options from a ".ini"-like file or memory-stored string list.
unsigned int pfAuxFilterOptimal_MaximumSearchSamples
In the algorithm "CParticleFilter::pfAuxiliaryPFOptimal" (and in "CParticleFilter::pfAuxiliaryPFStand...
The namespace for Bayesian filtering algorithm: different particle filters and Kalman filter algorith...
Only specializations of this class are defined for each enum type of interest.
Definition: TEnumType.h:24
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.
This class allows loading and storing values and vectors of different types from a configuration text...
TParticleResamplingAlgorithm
Defines the different resampling algorithms.
TParticleResamplingAlgorithm resamplingMethod
The resampling algorithm to use (default=prMultinomial).
TParticleFilterOptions()
Initilization of default parameters.
A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std...
Definition: bimap.h:34
virtual void saveToConfigFile(mrpt::utils::CConfigFileBase &target, const std::string &section) const override
This method saves the options to a ".ini"-like file or memory-stored string list. ...
Declares a class for storing a "sensory frame", a set of "observations" taken by the robot approximat...
Definition: CSensoryFrame.h:54
This class acts as a common interface to the different interfaces (see CParticleFilter::TParticleFilt...
bool pfAuxFilterStandard_FirstStageWeightsMonteCarlo
Only for PF_algorithm==pfAuxiliaryPFStandard: If false, the APF will predict the first stage weights ...
GLsizei const GLchar ** string
Definition: glext.h:4101
double BETA
The resampling of particles will be performed when ESS (in range [0,1]) < BETA (default is 0...
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.
TParticleFilterAlgorithm
Defines different types of particle filter algorithms.
double max_loglikelihood_dyn_range
Only for PF_algorithm=pfAuxiliaryPFOptimal: If a given particle has a max_likelihood (from the a-prio...
double powFactor
An optional step to "smooth" dramatic changes in the observation model to affect the variance of the ...
The configuration of a particle filter.
CParticleFilter()
Default constructor.
GLsizei GLsizei GLchar * source
Definition: glext.h:4082
unsigned int sampleSize
The initial number of particles in the filter (it can change only if adaptiveSampleSize=true) (defaul...
bool pfAuxFilterOptimal_MLE
(Default=false) In the algorithm "CParticleFilter::pfAuxiliaryPFOptimal", if set to true...
void insert(const KEY &k, const VALUE &v)
Insert a new pair KEY<->VALUE in the bi-map.
Definition: bimap.h:75
CParticleFilter::TParticleFilterOptions m_options
The options to be used in the PF, must be set before executing any step of the particle filter...
TParticleFilterAlgorithm PF_algorithm
The PF algorithm to use (default=pfStandardProposal) See TParticleFilterAlgorithm for the posibilitie...
This is a virtual base class for sets of options than can be loaded from and/or saved to configuratio...
bool adaptiveSampleSize
A flag that indicates whether the CParticleFilterCapable object should perform adative sample size (d...



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