Main MRPT website > C++ reference
MRPT logo
CParticleFilter.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CPARTICLEFILTER_H
29 #define CPARTICLEFILTER_H
30 
31 #include <mrpt/utils/utils_defs.h>
34 
35 namespace mrpt
36 {
37  namespace slam
38  {
39  class CActionCollection;
40  class CSensoryFrame;
41  }
42 
43  /** The namespace for Bayesian filtering algorithm: different particle filters and Kalman filter algorithms. \ingroup mrpt_base_grp
44  */
45  namespace bayes
46  {
48 
49  /** This class acts as a common interface to the different interfaces (see CParticleFilter::TParticleFilterAlgorithm) any bayes::CParticleFilterCapable class can implement: it is the invoker of particle filter algorithms.
50  * The particle filter is executed on a probability density function (PDF) described by a CParticleFilterCapable object, passed in the constructor or alternatively through the CParticleFilter::executeOn method.<br>
51  *
52  * For a complete example and further details, see the <a href="http://www.mrpt.org/Particle_Filter_Tutorial" >Particle Filter tutorial</a>.
53  *
54  * The basic SIR algorithm (pfStandardProposal) consists of:
55  * - Execute a prediction with the given "action".
56  * - Update the weights of the particles using the likelihood of the "observation".
57  * - Normalize weights.
58  * - Perform resampling if the ESS is below the threshold options.BETA.
59  *
60  * \ingroup mrpt_base_grp
61  * \sa mrpt::poses::CPoseParticlesPDF
62  */
64  {
65  public:
66 
67  /** Defines different types of particle filter algorithms.
68  * The defined SIR implementations are:
69  * - pfStandardProposal: Standard proposal distribution + weights according to likelihood function.
70  * - pfAuxiliaryPFStandard: An auxiliary PF using the standard proposal distribution.
71  * - pfOptimalProposal: Use the optimal proposal distribution (where available!, usually this will perform approximations)
72  * - pfAuxiliaryPFOptimal: Use the optimal proposal and a auxiliary particle filter (see <a href="http://www.mrpt.org/Paper:An_Optimal_Filtering_Algorithm_for_Non-Parametric_Observation_Models_in_Robot_Localization_(ICRA_2008)" >paper</a>).
73  *
74  * See the theoretical discussion in <a href="http://www.mrpt.org/Resampling_Schemes" >resampling schemes</a>.
75  */
77  {
78  pfStandardProposal = 0,
81  pfAuxiliaryPFOptimal
82  };
83 
84  /** Defines the different resampling algorithms.
85  * The implemented resampling methods are:
86  * - prMultinomial (Default): Uses standard select with replacement (draws M random uniform numbers)
87  * - prResidual: The residual or "remainder" method.
88  * - prStratified: The stratified resampling, where a uniform sample is drawn for each of M subdivisions of the range (0,1].
89  * - prSystematic: A single uniform sample is drawn in the range (0,1/M].
90  *
91  * See the theoretical discussion in <a href="http://www.mrpt.org/Resampling_Schemes" >resampling schemes</a>.
92  */
94  {
95  prMultinomial = 0,
98  prSystematic
99  };
100 
101  /** The configuration of a particle filter.
102  */
104  {
105  public:
106  /** Initilization of default parameters
107  */
109 
110  /** See mrpt::utils::CLoadableOptions
111  */
112  void loadFromConfigFile(
113  const mrpt::utils::CConfigFileBase &source,
114  const std::string &section);
115 
116  /** See mrpt::utils::CLoadableOptions
117  */
118  void dumpToTextStream(mrpt::utils::CStream &out) const;
119 
120  /** A flag that indicates whether the CParticleFilterCapable object should perform adative sample size (default=false).
121  */
123 
124  /** The resampling of particles will be performed when ESS (in range [0,1]) < BETA (default is 0.5)
125  */
126  double BETA;
127 
128  /** The initial number of particles in the filter (it can change only if adaptiveSampleSize=true) (default=1)
129  */
130  unsigned int sampleSize;
131 
132  /** In the algorithm "CParticleFilter::pfAuxiliaryPFOptimal" (and in "CParticleFilter::pfAuxiliaryPFStandard" only if pfAuxFilterStandard_FirstStageWeightsMonteCarlo = true) the number of samples for searching the maximum likelihood value and also to estimate the "first stage weights" (see papers!) (default=100)
133  */
135 
136  /** An optional step to "smooth" dramatic changes in the observation model to affect the variance of the particle weights, eg weight*=likelihood^powFactor (default=1 = no effects).
137  */
138  double powFactor;
139 
140  /** The PF algorithm to use (default=pfStandardProposal) See TParticleFilterAlgorithm for the posibilities.
141  */
143 
144  /** The resampling algorithm to use (default=prMultinomial).
145  */
147 
148 
149  /** Only for PF_algorithm=pfAuxiliaryPFOptimal: If a given particle has a max_likelihood (from the a-priori estimate) below the maximum from all the samples - max_loglikelihood_dyn_range, then the particle is directly discarded.
150  * This is done to assure that the rejection sampling doesn't get stuck in an infinite loop trying to get an acceptable sample.
151  * Default = 15 (in logarithmic likelihood)
152  */
154 
155  /** Only for PF_algorithm==pfAuxiliaryPFStandard:
156  * If false, the APF will predict the first stage weights just at the mean of the prior of the next time step.
157  * If true, these weights will be estimated as described in the papers for the "pfAuxiliaryPFOptimal" method, i.e. through a monte carlo simulation.
158  * In that case, "pfAuxFilterOptimal_MaximumSearchSamples" is the number of MC samples used.
159  */
161 
162  bool verbose; //!< Enable extra messages for each PF iteration (Default=false)
163 
164  /** (Default=false) In the algorithm "CParticleFilter::pfAuxiliaryPFOptimal", if set to true, do not perform rejection sampling, but just the most-likely (ML) particle found in the preliminary weight-determination stage.
165  */
167  };
168 
169 
170  /** Statistics for being returned from the "execute" method.
171  */
173  {
174  TParticleFilterStats() : ESS_beforeResample(0), weightsVariance_beforeResample (0) { }
177  };
178 
179  /** Default constructor.
180  * After creating the PF object, set the options in CParticleFilter::m_options, then execute steps through CParticleFilter::executeOn.
181  */
182  CParticleFilter( );
183 
184  virtual ~CParticleFilter() {}
185 
186  /** Executes a complete prediction + update step of the selected particle filtering algorithm.
187  * The member CParticleFilter::m_options must be set before calling this to settle the algorithm parameters.
188  *
189  * \param obj The object representing the probability distribution function (PDF) which apply the particle filter algorithm to.
190  * \param action A pointer to an action in the form of a CActionCollection, or NULL if there is no action.
191  * \param observation A pointer to observations in the form of a CSensoryFrame, or NULL if there is no observation.
192  * \param stats An output structure for gathering statistics of the particle filter execution, or set to NULL if you do not need it (see CParticleFilter::TParticleFilterStats).
193  *
194  * \sa CParticleFilterCapable, executeOn
195  */
196  void executeOn(
198  const mrpt::slam::CActionCollection *action,
199  const mrpt::slam::CSensoryFrame *observation,
200  TParticleFilterStats *stats = NULL);
201 
202 
203  /** The options to be used in the PF, must be set before executing any step of the particle filter.
204  */
206 
207  }; // End of class def.
208 
209  } // end namespace
210 } // end namespace
211 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013