Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Attributes
mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t > Struct Template Reference

Detailed Description

template<class Derived, class particle_list_t>
struct mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >

A curiously recurring template pattern (CRTP) approach to providing the basic functionality of any CParticleFilterData<> class.

Users should inherit from CParticleFilterData<>, which in turn will automatically inhirit from this base class.

See also
CParticleFilter, CParticleFilterCapable, CParticleFilterData

Definition at line 33 of file CParticleFilterData.h.

#include <mrpt/bayes/CParticleFilterData.h>

Inheritance diagram for mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >:
Inheritance graph

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

const Derived & derived () const
 CRTP helper method. More...
 
Derived & derived ()
 CRTP helper method. More...
 
double getW (size_t i) const override
 Access to i'th particle (logarithm) weight, where first one is index 0. More...
 
void setW (size_t i, double w) override
 Modifies i'th particle (logarithm) weight, where first one is index 0. More...
 
size_t particlesCount () const override
 Get the m_particles count. More...
 
double normalizeWeights (double *out_max_log_w=nullptr) override
 Normalize the (logarithmic) weights, such as the maximum weight is zero. More...
 
double ESS () const override
 Returns the normalized ESS (Estimated Sample Size), in the range [0,1]. More...
 
void performSubstitution (const std::vector< size_t > &indx) override
 Replaces the old particles by copies determined by the indexes in "indx", performing an efficient copy of the necesary particles only and allowing the number of particles to change. 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...
 
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...
 
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 (const bayes::CParticleFilter::TParticleFilterOptions &PF_options, const CParticleFilterCapable *obj, size_t index, const void *action, 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
 

Member Typedef Documentation

◆ TParticleProbabilityEvaluator

using mrpt::bayes::CParticleFilterCapable::TParticleProbabilityEvaluator = double (*)( const bayes::CParticleFilter::TParticleFilterOptions& PF_options, const CParticleFilterCapable* obj, size_t index, const void* action, const void* observation)
inherited

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.

Parameters
indexThis is the index of the particle its probability is being computed.
actionThe value of this is the parameter passed to "prepareFastDrawSample"
observationThe value of this is the parameter passed to "prepareFastDrawSample" The action and the observation are declared as "void*" for a greater flexibility.
See also
prepareFastDrawSample

Definition at line 62 of file CParticleFilterCapable.h.

Member Function Documentation

◆ computeResampling()

void CParticleFilterCapable::computeResampling ( CParticleFilter::TParticleResamplingAlgorithm  method,
const std::vector< double > &  in_logWeights,
std::vector< size_t > &  out_indexes,
size_t  out_particle_count = 0 
)
staticinherited

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

Parameters
[in]out_particle_countThe desired number of output particles after resampling; 0 means don't modify the current number.
See also
performResampling

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.

◆ defaultEvaluator()

static double mrpt::bayes::CParticleFilterCapable::defaultEvaluator ( const bayes::CParticleFilter::TParticleFilterOptions PF_options,
const CParticleFilterCapable obj,
size_t  index,
const void action,
const void observation 
)
inlinestaticinherited

The default evaluator function, which simply returns the particle weight.

The action and the observation are declared as "void*" for a greater flexibility.

See also
prepareFastDrawSample

Definition at line 70 of file CParticleFilterCapable.h.

References MRPT_UNUSED_PARAM.

◆ derived() [1/2]

template<class Derived , class particle_list_t >
Derived& mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >::derived ( )
inline

CRTP helper method.

Definition at line 41 of file CParticleFilterData.h.

◆ derived() [2/2]

template<class Derived , class particle_list_t >
const Derived& mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >::derived ( ) const
inline

◆ ESS()

template<class Derived , class particle_list_t >
double mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >::ESS ( ) const
inlineoverridevirtual

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.

Implements mrpt::bayes::CParticleFilterCapable.

Definition at line 88 of file CParticleFilterData.h.

Referenced by mrpt::maps::CBeaconMap::internal_insertObservation(), mrpt::hmtslam::CHMTSLAM::LSLAM_process_message_from_AA(), mrpt::hmtslam::CLSLAM_RBPF_2DLASER::prediction_and_update_pfAuxiliaryPFOptimal(), and mrpt::slam::CMetricMapBuilderRBPF::processActionObservation().

◆ fastDrawSample()

size_t CParticleFilterCapable::fastDrawSample ( const bayes::CParticleFilter::TParticleFilterOptions PF_options) const
inherited

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:

  • You MUST call "prepareFastDrawSample" ONCE before calling this method. That method must be called after modifying the particle filter (executing one step, resampling, etc...)
  • This method returns ONE index for the selected ("drawn") particle, in the range [0,M-1]
  • You do not need to call "normalizeWeights" before calling this.
    See also
    prepareFastDrawSample

Definition at line 489 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().

◆ getW()

template<class Derived , class particle_list_t >
double mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >::getW ( size_t  i) const
inlineoverridevirtual

Access to i'th particle (logarithm) weight, where first one is index 0.

Implements mrpt::bayes::CParticleFilterCapable.

Definition at line 42 of file CParticleFilterData.h.

Referenced by mrpt::slam::CMetricMapBuilderRBPF::drawCurrentEstimationToImage(), and mrpt::slam::CMetricMapBuilderRBPF::getCurrentMostLikelyPath().

◆ log2linearWeights()

void CParticleFilterCapable::log2linearWeights ( const std::vector< double > &  in_logWeights,
std::vector< double > &  out_linWeights 
)
staticinherited

A static method to compute the linear, normalized (the sum the unity) weights from log-weights.

See also
performResampling

Definition at line 555 of file CParticleFilterCapable.cpp.

References ASSERT_, MRPT_END, and MRPT_START.

◆ normalizeWeights()

template<class Derived , class particle_list_t >
double mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >::normalizeWeights ( double *  out_max_log_w = nullptr)
inlineoverridevirtual

Normalize the (logarithmic) weights, such as the maximum weight is zero.

Parameters
out_max_log_wIf provided, will return with the maximum log_w before normalizing, such as new_weights = old_weights - max_log_w.
Returns
The max/min ratio of weights ("dynamic range")

Implements mrpt::bayes::CParticleFilterCapable.

Definition at line 61 of file CParticleFilterData.h.

Referenced by mrpt::hmtslam::CHierarchicalMapMHPartition::computeCoordinatesTransformationBetweenNodes(), mrpt::hmtslam::CLSLAM_RBPF_2DLASER::prediction_and_update_pfAuxiliaryPFOptimal(), and mrpt::hmtslam::CLSLAM_RBPF_2DLASER::prediction_and_update_pfOptimalProposal().

◆ particlesCount()

template<class Derived , class particle_list_t >
size_t mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >::particlesCount ( ) const
inlineoverridevirtual

◆ performResampling()

void CParticleFilterCapable::performResampling ( const bayes::CParticleFilter::TParticleFilterOptions PF_options,
size_t  out_particle_count = 0 
)
inherited

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"

Parameters
[in]out_particle_countThe desired number of output particles after resampling; 0 means don't modify the current number.
See also
resample

Definition at line 29 of file CParticleFilterCapable.cpp.

References ASSERT_, MRPT_END, MRPT_START, and mrpt::bayes::CParticleFilter::TParticleFilterOptions::resamplingMethod.

◆ performSubstitution()

template<class Derived , class particle_list_t >
void mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >::performSubstitution ( const std::vector< size_t > &  indx)
inlineoverridevirtual

Replaces the old particles by copies determined by the indexes in "indx", performing an efficient copy of the necesary particles only and allowing the number of particles to change.

Implements mrpt::bayes::CParticleFilterCapable.

Definition at line 115 of file CParticleFilterData.h.

Referenced by mrpt::maps::CBeaconMap::internal_insertObservation().

◆ prediction_and_update()

void CParticleFilterCapable::prediction_and_update ( const mrpt::obs::CActionCollection action,
const mrpt::obs::CSensoryFrame observation,
const bayes::CParticleFilter::TParticleFilterOptions PF_options 
)
inherited

◆ prediction_and_update_pfAuxiliaryPFOptimal()

void CParticleFilterCapable::prediction_and_update_pfAuxiliaryPFOptimal ( const mrpt::obs::CActionCollection action,
const mrpt::obs::CSensoryFrame observation,
const bayes::CParticleFilter::TParticleFilterOptions PF_options 
)
protectedvirtualinherited

Performs the particle filter prediction/update stages for the algorithm "pfAuxiliaryPFOptimal" (if not implemented in heritated class, it will raise a 'non-implemented' exception).

See also
prediction_and_update

Reimplemented in mrpt::hmtslam::CLocalMetricHypothesis, mrpt::slam::CMonteCarloLocalization2D, mrpt::maps::CMultiMetricMapPDF, and mrpt::slam::CMonteCarloLocalization3D.

Definition at line 355 of file CParticleFilterCapable.cpp.

References MRPT_UNUSED_PARAM, and THROW_EXCEPTION.

◆ prediction_and_update_pfAuxiliaryPFStandard()

void CParticleFilterCapable::prediction_and_update_pfAuxiliaryPFStandard ( const mrpt::obs::CActionCollection action,
const mrpt::obs::CSensoryFrame observation,
const bayes::CParticleFilter::TParticleFilterOptions PF_options 
)
protectedvirtualinherited

Performs the particle filter prediction/update stages for the algorithm "pfAuxiliaryPFStandard" (if not implemented in heritated class, it will raise a 'non-implemented' exception).

See also
prediction_and_update

Reimplemented in mrpt::slam::CMonteCarloLocalization2D, mrpt::maps::CMultiMetricMapPDF, and mrpt::slam::CMonteCarloLocalization3D.

Definition at line 326 of file CParticleFilterCapable.cpp.

References MRPT_UNUSED_PARAM, and THROW_EXCEPTION.

◆ prediction_and_update_pfOptimalProposal()

void CParticleFilterCapable::prediction_and_update_pfOptimalProposal ( const mrpt::obs::CActionCollection action,
const mrpt::obs::CSensoryFrame observation,
const bayes::CParticleFilter::TParticleFilterOptions PF_options 
)
protectedvirtualinherited

Performs the particle filter prediction/update stages for the algorithm "pfOptimalProposal" (if not implemented in heritated class, it will raise a 'non-implemented' exception).

See also
prediction_and_update

Reimplemented in mrpt::hmtslam::CLocalMetricHypothesis, and mrpt::maps::CMultiMetricMapPDF.

Definition at line 341 of file CParticleFilterCapable.cpp.

References MRPT_UNUSED_PARAM, and THROW_EXCEPTION.

◆ prediction_and_update_pfStandardProposal()

void CParticleFilterCapable::prediction_and_update_pfStandardProposal ( const mrpt::obs::CActionCollection action,
const mrpt::obs::CSensoryFrame observation,
const bayes::CParticleFilter::TParticleFilterOptions PF_options 
)
protectedvirtualinherited

Performs the particle filter prediction/update stages for the algorithm "pfStandardProposal" (if not implemented in heritated class, it will raise a 'non-implemented' exception).

See also
prediction_and_update

Reimplemented in mrpt::slam::CMonteCarloLocalization2D, mrpt::maps::CMultiMetricMapPDF, CRangeBearingParticleFilter, and mrpt::slam::CMonteCarloLocalization3D.

Definition at line 311 of file CParticleFilterCapable.cpp.

References MRPT_UNUSED_PARAM, and THROW_EXCEPTION.

◆ prepareFastDrawSample()

void CParticleFilterCapable::prepareFastDrawSample ( const bayes::CParticleFilter::TParticleFilterOptions PF_options,
TParticleProbabilityEvaluator  partEvaluator = defaultEvaluator,
const void action = nullptr,
const void observation = nullptr 
) const
inherited

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):

  • DYNAMIC SAMPLE SIZE=NO: In this case this method fills out an internal array (m_fastDrawAuxiliary.alreadyDrawnIndexes) with the random indexes generated according to the selected resample scheme in TParticleFilterOptions. Those indexes are read sequentially by subsequent calls to fastDrawSample.
  • DYNAMIC SAMPLE SIZE=YES: Then:
    • If TParticleFilterOptions.resamplingMethod = prMultinomial, the internal buffers will be filled out (m_fastDrawAuxiliary.CDF, CDF_indexes & PDF) and then fastDrawSample can be called an arbitrary number of times to generate random indexes.
    • For the rest of resampling algorithms, an exception will be raised since they are not appropriate for a dynamic (unknown in advance) number of particles.

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.

See also
fastDrawSample

Definition at line 371 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().

◆ setW()

template<class Derived , class particle_list_t >
void mrpt::bayes::CParticleFilterDataImpl< Derived, particle_list_t >::setW ( size_t  i,
double  w 
)
inlineoverridevirtual

Modifies i'th particle (logarithm) weight, where first one is index 0.

Implements mrpt::bayes::CParticleFilterCapable.

Definition at line 49 of file CParticleFilterData.h.

Member Data Documentation

◆ m_fastDrawAuxiliary

TFastDrawAuxVars mrpt::bayes::CParticleFilterCapable::m_fastDrawAuxiliary
mutableprotectedinherited

Auxiliary vectors, see CParticleFilterCapable::prepareFastDrawSample for more information.

Definition at line 293 of file CParticleFilterCapable.h.

◆ PARTICLE_FILTER_CAPABLE_FAST_DRAW_BINS

const unsigned CParticleFilterCapable::PARTICLE_FILTER_CAPABLE_FAST_DRAW_BINS
staticprivateinherited
Initial value:
=
20

Definition at line 38 of file CParticleFilterCapable.h.




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