MRPT
2.0.1
|
This virtual class defines the interface that any particles based PDF class must implement in order to be executed by a mrpt::bayes::CParticleFilter.
See the Particle Filter tutorial explaining how to use the particle filter-related classes.
Definition at line 31 of file CParticleFilterCapable.h.
#include <mrpt/bayes/CParticleFilterCapable.h>
Classes | |
struct | TFastDrawAuxVars |
Auxiliary vectors, see CParticleFilterCapable::prepareFastDrawSample for more information. More... | |
Public Types | |
using | TParticleProbabilityEvaluator = double(*)(const bayes::CParticleFilter::TParticleFilterOptions &PF_options, const CParticleFilterCapable *obj, size_t index, const void *action, const void *observation) |
A callback function type for evaluating the probability of m_particles of being selected, used in "fastDrawSample". More... | |
Public Member Functions | |
CParticleFilterCapable () | |
virtual | ~CParticleFilterCapable ()=default |
Virtual destructor. More... | |
void | prepareFastDrawSample (const bayes::CParticleFilter::TParticleFilterOptions &PF_options, TParticleProbabilityEvaluator partEvaluator=defaultEvaluator, const void *action=nullptr, const void *observation=nullptr) const |
Prepares data structures for calling fastDrawSample method next. More... | |
size_t | fastDrawSample (const bayes::CParticleFilter::TParticleFilterOptions &PF_options) const |
Draws a random sample from the particle filter, in such a way that each particle has a probability proportional to its weight (in the standard PF algorithm). More... | |
virtual double | getW (size_t i) const =0 |
Access to i'th particle (logarithm) weight, where first one is index 0. More... | |
virtual void | setW (size_t i, double w)=0 |
Modifies i'th particle (logarithm) weight, where first one is index 0. More... | |
virtual size_t | particlesCount () const =0 |
Get the m_particles count. More... | |
void | prediction_and_update (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options) |
Performs the prediction stage of the Particle Filter. More... | |
virtual void | performSubstitution (const std::vector< size_t > &indx)=0 |
Performs the substitution for internal use of resample in particle filter algorithm, don't call it directly. More... | |
virtual double | normalizeWeights (double *out_max_log_w=nullptr)=0 |
Normalize the (logarithmic) weights, such as the maximum weight is zero. More... | |
virtual double | ESS () const =0 |
Returns the normalized ESS (Estimated Sample Size), in the range [0,1]. More... | |
void | performResampling (const bayes::CParticleFilter::TParticleFilterOptions &PF_options, size_t out_particle_count=0) |
Performs a resample of the m_particles, using the method selected in the constructor. More... | |
Static Public Member Functions | |
static double | defaultEvaluator ([[maybe_unused]] const bayes::CParticleFilter::TParticleFilterOptions &PF_options, [[maybe_unused]] const CParticleFilterCapable *obj, size_t index, [[maybe_unused]] const void *action, [[maybe_unused]] const void *observation) |
The default evaluator function, which simply returns the particle weight. More... | |
static void | computeResampling (CParticleFilter::TParticleResamplingAlgorithm method, const std::vector< double > &in_logWeights, std::vector< size_t > &out_indexes, size_t out_particle_count=0) |
A static method to perform the computation of the samples resulting from resampling a given set of particles, given their logarithmic weights, and a resampling method. More... | |
static void | log2linearWeights (const std::vector< double > &in_logWeights, std::vector< double > &out_linWeights) |
A static method to compute the linear, normalized (the sum the unity) weights from log-weights. More... | |
Protected Member Functions | |
virtual void | prediction_and_update_pfStandardProposal (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options) |
Performs the particle filter prediction/update stages for the algorithm "pfStandardProposal" (if not implemented in heritated class, it will raise a 'non-implemented' exception). More... | |
virtual void | prediction_and_update_pfAuxiliaryPFStandard (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options) |
Performs the particle filter prediction/update stages for the algorithm "pfAuxiliaryPFStandard" (if not implemented in heritated class, it will raise a 'non-implemented' exception). More... | |
virtual void | prediction_and_update_pfOptimalProposal (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options) |
Performs the particle filter prediction/update stages for the algorithm "pfOptimalProposal" (if not implemented in heritated class, it will raise a 'non-implemented' exception). More... | |
virtual void | prediction_and_update_pfAuxiliaryPFOptimal (const mrpt::obs::CActionCollection *action, const mrpt::obs::CSensoryFrame *observation, const bayes::CParticleFilter::TParticleFilterOptions &PF_options) |
Performs the particle filter prediction/update stages for the algorithm "pfAuxiliaryPFOptimal" (if not implemented in heritated class, it will raise a 'non-implemented' exception). More... | |
Protected Attributes | |
TFastDrawAuxVars | m_fastDrawAuxiliary |
Auxiliary vectors, see CParticleFilterCapable::prepareFastDrawSample for more information. More... | |
Static Private Attributes | |
static const unsigned | PARTICLE_FILTER_CAPABLE_FAST_DRAW_BINS |
Friends | |
class | CParticleFilter |
using mrpt::bayes::CParticleFilterCapable::TParticleProbabilityEvaluator = double (*)( const bayes::CParticleFilter::TParticleFilterOptions& PF_options, const CParticleFilterCapable* obj, size_t index, const void* action, const void* observation) |
A callback function type for evaluating the probability of m_particles of being selected, used in "fastDrawSample".
The default evaluator function "defaultEvaluator" simply returns the particle weight.
index | This is the index of the particle its probability is being computed. |
action | The value of this is the parameter passed to "prepareFastDrawSample" |
observation | The value of this is the parameter passed to "prepareFastDrawSample" The action and the observation are declared as "void*" for a greater flexibility. |
Definition at line 60 of file CParticleFilterCapable.h.
|
inline |
Definition at line 39 of file CParticleFilterCapable.h.
|
virtualdefault |
Virtual destructor.
|
static |
A static method to perform the computation of the samples resulting from resampling a given set of particles, given their logarithmic weights, and a resampling method.
It returns the sequence of indexes from the resampling. The number of output samples is the same than the input population. This generic method just computes these indexes, to actually perform a resampling in a particle filter object, call performResampling
[in] | out_particle_count | The desired number of output particles after resampling; 0 means don't modify the current number. |
Definition at line 61 of file CParticleFilterCapable.cpp.
References ASSERT_, mrpt::random::CRandomGenerator::drawUniform(), mrpt::random::CRandomGenerator::drawUniformVector(), mrpt::format(), mrpt::random::getRandomGenerator(), mrpt::math::maximum(), MRPT_END, MRPT_START, mrpt::bayes::CParticleFilter::prMultinomial, mrpt::bayes::CParticleFilter::prResidual, mrpt::bayes::CParticleFilter::prStratified, mrpt::bayes::CParticleFilter::prSystematic, R, and THROW_EXCEPTION.
|
inlinestatic |
The default evaluator function, which simply returns the particle weight.
The action and the observation are declared as "void*" for a greater flexibility.
Definition at line 68 of file CParticleFilterCapable.h.
|
pure virtual |
Returns the normalized ESS (Estimated Sample Size), in the range [0,1].
Note that you do NOT need to normalize the weights before calling this.
Implemented in mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >, mrpt::bayes::CParticleFilterDataImpl< CLocalMetricHypothesis, mrpt::bayes::CParticleFilterData< CLSLAMParticleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPosePDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPose3DPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CRangeBearingParticleFilter, mrpt::bayes::CParticleFilterData< CParticleVehicleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPointPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPoint3Df >::CParticleList >, and mrpt::bayes::CParticleFilterDataImpl< CMultiMetricMapPDF, mrpt::bayes::CParticleFilterData< CRBPFParticleData >::CParticleList >.
Referenced by mrpt::bayes::CParticleFilter::executeOn().
size_t CParticleFilterCapable::fastDrawSample | ( | const bayes::CParticleFilter::TParticleFilterOptions & | PF_options | ) | const |
Draws a random sample from the particle filter, in such a way that each particle has a probability proportional to its weight (in the standard PF algorithm).
This method can be used to generate a variable number of m_particles when resampling: to vary the number of m_particles in the filter. See prepareFastDrawSample for more information, or the Particle Filter tutorial.
NOTES:
Definition at line 478 of file CParticleFilterCapable.cpp.
References mrpt::bayes::CParticleFilter::TParticleFilterOptions::adaptiveSampleSize, mrpt::random::CRandomGenerator::drawUniform(), mrpt::random::getRandomGenerator(), MRPT_END, MRPT_END_WITH_CLEAN_UP, MRPT_START, mrpt::bayes::CParticleFilter::prMultinomial, mrpt::bayes::CParticleFilter::TParticleFilterOptions::resamplingMethod, and THROW_EXCEPTION.
Referenced by mrpt::hmtslam::CLSLAM_RBPF_2DLASER::prediction_and_update_pfAuxiliaryPFOptimal().
|
pure virtual |
Access to i'th particle (logarithm) weight, where first one is index 0.
Implemented in mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >, mrpt::bayes::CParticleFilterDataImpl< CLocalMetricHypothesis, mrpt::bayes::CParticleFilterData< CLSLAMParticleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPosePDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPose3DPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CRangeBearingParticleFilter, mrpt::bayes::CParticleFilterData< CParticleVehicleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPointPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPoint3Df >::CParticleList >, and mrpt::bayes::CParticleFilterDataImpl< CMultiMetricMapPDF, mrpt::bayes::CParticleFilterData< CRBPFParticleData >::CParticleList >.
Referenced by mrpt::bayes::CParticleFilter::executeOn().
|
static |
A static method to compute the linear, normalized (the sum the unity) weights from log-weights.
Definition at line 544 of file CParticleFilterCapable.cpp.
References ASSERT_, MRPT_END, and MRPT_START.
|
pure virtual |
Normalize the (logarithmic) weights, such as the maximum weight is zero.
out_max_log_w | If provided, will return with the maximum log_w before normalizing, such as new_weights = old_weights - max_log_w. |
Implemented in mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >, mrpt::bayes::CParticleFilterDataImpl< CLocalMetricHypothesis, mrpt::bayes::CParticleFilterData< CLSLAMParticleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPosePDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPose3DPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CRangeBearingParticleFilter, mrpt::bayes::CParticleFilterData< CParticleVehicleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPointPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPoint3Df >::CParticleList >, and mrpt::bayes::CParticleFilterDataImpl< CMultiMetricMapPDF, mrpt::bayes::CParticleFilterData< CRBPFParticleData >::CParticleList >.
Referenced by mrpt::bayes::CParticleFilter::executeOn().
|
pure virtual |
Get the m_particles count.
Implemented in mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >, mrpt::bayes::CParticleFilterDataImpl< CLocalMetricHypothesis, mrpt::bayes::CParticleFilterData< CLSLAMParticleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPosePDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPose3DPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CRangeBearingParticleFilter, mrpt::bayes::CParticleFilterData< CParticleVehicleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPointPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPoint3Df >::CParticleList >, and mrpt::bayes::CParticleFilterDataImpl< CMultiMetricMapPDF, mrpt::bayes::CParticleFilterData< CRBPFParticleData >::CParticleList >.
Referenced by mrpt::bayes::CParticleFilter::executeOn().
void CParticleFilterCapable::performResampling | ( | const bayes::CParticleFilter::TParticleFilterOptions & | PF_options, |
size_t | out_particle_count = 0 |
||
) |
Performs a resample of the m_particles, using the method selected in the constructor.
After computing the surviving samples, this method internally calls "performSubstitution" to actually perform the particle replacement. This method is called automatically by CParticleFilter::execute, andshould not be invoked manually normally. To just obtaining the sequence of resampled indexes from a sequence of weights, use "resample"
[in] | out_particle_count | The desired number of output particles after resampling; 0 means don't modify the current number. |
Definition at line 29 of file CParticleFilterCapable.cpp.
References ASSERT_, MRPT_END, MRPT_START, and mrpt::bayes::CParticleFilter::TParticleFilterOptions::resamplingMethod.
Referenced by mrpt::bayes::CParticleFilter::executeOn().
|
pure virtual |
Performs the substitution for internal use of resample in particle filter algorithm, don't call it directly.
indx | The indices of current m_particles to be saved as the new m_particles set. |
Implemented in mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >, mrpt::bayes::CParticleFilterDataImpl< CLocalMetricHypothesis, mrpt::bayes::CParticleFilterData< CLSLAMParticleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPosePDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPose3DPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CRangeBearingParticleFilter, mrpt::bayes::CParticleFilterData< CParticleVehicleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPointPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPoint3Df >::CParticleList >, and mrpt::bayes::CParticleFilterDataImpl< CMultiMetricMapPDF, mrpt::bayes::CParticleFilterData< CRBPFParticleData >::CParticleList >.
void CParticleFilterCapable::prediction_and_update | ( | const mrpt::obs::CActionCollection * | action, |
const mrpt::obs::CSensoryFrame * | observation, | ||
const bayes::CParticleFilter::TParticleFilterOptions & | PF_options | ||
) |
Performs the prediction stage of the Particle Filter.
This method simply selects the appropiate protected method according to the particle filter algorithm to run.
Definition at line 273 of file CParticleFilterCapable.cpp.
References mrpt::bayes::CParticleFilter::TParticleFilterOptions::PF_algorithm, mrpt::bayes::CParticleFilter::pfAuxiliaryPFOptimal, mrpt::bayes::CParticleFilter::pfAuxiliaryPFStandard, mrpt::bayes::CParticleFilter::pfOptimalProposal, mrpt::bayes::CParticleFilter::pfStandardProposal, and THROW_EXCEPTION.
Referenced by mrpt::bayes::CParticleFilter::executeOn().
|
protectedvirtual |
Performs the particle filter prediction/update stages for the algorithm "pfAuxiliaryPFOptimal" (if not implemented in heritated class, it will raise a 'non-implemented' exception).
Reimplemented in mrpt::hmtslam::CLocalMetricHypothesis, mrpt::slam::CMonteCarloLocalization2D, mrpt::slam::CMonteCarloLocalization3D, and mrpt::maps::CMultiMetricMapPDF.
Definition at line 345 of file CParticleFilterCapable.cpp.
References THROW_EXCEPTION.
|
protectedvirtual |
Performs the particle filter prediction/update stages for the algorithm "pfAuxiliaryPFStandard" (if not implemented in heritated class, it will raise a 'non-implemented' exception).
Reimplemented in mrpt::slam::CMonteCarloLocalization2D, mrpt::maps::CMultiMetricMapPDF, and mrpt::slam::CMonteCarloLocalization3D.
Definition at line 320 of file CParticleFilterCapable.cpp.
References THROW_EXCEPTION.
|
protectedvirtual |
Performs the particle filter prediction/update stages for the algorithm "pfOptimalProposal" (if not implemented in heritated class, it will raise a 'non-implemented' exception).
Reimplemented in mrpt::hmtslam::CLocalMetricHypothesis, and mrpt::maps::CMultiMetricMapPDF.
Definition at line 333 of file CParticleFilterCapable.cpp.
References THROW_EXCEPTION.
|
protectedvirtual |
Performs the particle filter prediction/update stages for the algorithm "pfStandardProposal" (if not implemented in heritated class, it will raise a 'non-implemented' exception).
Reimplemented in CRangeBearingParticleFilter, mrpt::slam::CMonteCarloLocalization2D, mrpt::maps::CMultiMetricMapPDF, and mrpt::slam::CMonteCarloLocalization3D.
Definition at line 307 of file CParticleFilterCapable.cpp.
References THROW_EXCEPTION.
void CParticleFilterCapable::prepareFastDrawSample | ( | const bayes::CParticleFilter::TParticleFilterOptions & | PF_options, |
TParticleProbabilityEvaluator | partEvaluator = defaultEvaluator , |
||
const void * | action = nullptr , |
||
const void * | observation = nullptr |
||
) | const |
Prepares data structures for calling fastDrawSample method next.
This method must be called once before using "fastDrawSample" (calling this more than once has no effect, but it takes time for nothing!) The behavior depends on the configuration of the PF (see CParticleFilter::TParticleFilterOptions):
The function pointed by "partEvaluator" should take into account the particle filter algorithm selected in "m_PFAlgorithm". If called without arguments (defaultEvaluator), the default behavior is to draw samples with a probability proportional to their current weights. The action and the observation are declared as "void*" for a greater flexibility. For a more detailed information see the Particle Filter tutorial. Custom supplied "partEvaluator" functions must take into account the previous particle weight, i.e. multiplying the current observation likelihood by the weights.
Definition at line 359 of file CParticleFilterCapable.cpp.
References mrpt::bayes::CParticleFilter::TParticleFilterOptions::adaptiveSampleSize, ASSERT_, mrpt::math::maximum(), MRPT_CHECK_NORMAL_NUMBER, MRPT_END, MRPT_END_WITH_CLEAN_UP, MRPT_START, mrpt::bayes::CParticleFilter::prMultinomial, mrpt::bayes::CParticleFilter::TParticleFilterOptions::resamplingMethod, and THROW_EXCEPTION.
Referenced by mrpt::hmtslam::CLSLAM_RBPF_2DLASER::prediction_and_update_pfAuxiliaryPFOptimal().
|
pure virtual |
Modifies i'th particle (logarithm) weight, where first one is index 0.
Implemented in mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >, mrpt::bayes::CParticleFilterDataImpl< CLocalMetricHypothesis, mrpt::bayes::CParticleFilterData< CLSLAMParticleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPosePDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPose3DPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CRangeBearingParticleFilter, mrpt::bayes::CParticleFilterData< CParticleVehicleData >::CParticleList >, mrpt::bayes::CParticleFilterDataImpl< CPointPDFParticles, mrpt::bayes::CParticleFilterData< mrpt::math::TPoint3Df >::CParticleList >, and mrpt::bayes::CParticleFilterDataImpl< CMultiMetricMapPDF, mrpt::bayes::CParticleFilterData< CRBPFParticleData >::CParticleList >.
|
friend |
Definition at line 33 of file CParticleFilterCapable.h.
|
mutableprotected |
Auxiliary vectors, see CParticleFilterCapable::prepareFastDrawSample for more information.
Definition at line 282 of file CParticleFilterCapable.h.
|
staticprivate |
Definition at line 36 of file CParticleFilterCapable.h.
Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020 |