Visual Servoing Platform
version 3.6.1 under development (2024-11-21)
|
#include <visp3/core/vpParticleFilter.h>
Classes | |
struct | vpParticlesWithWeights |
Public Types | |
typedef struct vpParticleFilter::vpParticlesWithWeights | vpParticlesWithWeights |
typedef std::function< vpColVector(const vpColVector &, const vpColVector &)> | vpStateAddFunction |
typedef std::function< vpColVector(const vpColVector &, const double &)> | vpProcessFunction |
typedef std::function< vpColVector(const vpColVector &, const vpColVector &, const double &)> | vpCommandStateFunction |
typedef std::function< double(const vpColVector &, const MeasurementsType &)> | vpLikelihoodFunction |
typedef std::function< vpColVector(const std::vector< vpColVector > &, const std::vector< double > &, const vpStateAddFunction &)> | vpFilterFunction |
typedef std::function< bool(const unsigned int &, const std::vector< double > &)> | vpResamplingConditionFunction |
typedef std::function< vpParticlesWithWeights(const std::vector< vpColVector > &, const std::vector< double > &)> | vpResamplingFunction |
Public Member Functions | |
VP_EXPLICIT | vpParticleFilter (const unsigned int &N, const std::vector< double > &stdev, const long &seed=-1, const int &nbThreads=-1) |
virtual | ~vpParticleFilter () |
void | init (const vpColVector &x0, const vpProcessFunction &f, const vpLikelihoodFunction &l, const vpResamplingConditionFunction &checkResamplingFunc, const vpResamplingFunction &resamplingFunc, const vpFilterFunction &filterFunc=weightedMean, const vpStateAddFunction &addFunc=simpleAdd) |
void | init (const vpColVector &x0, const vpCommandStateFunction &bx, const vpLikelihoodFunction &l, const vpResamplingConditionFunction &checkResamplingFunc, const vpResamplingFunction &resamplingFunc, const vpFilterFunction &filterFunc=weightedMean, const vpStateAddFunction &addFunc=simpleAdd) |
void | filter (const MeasurementsType &z, const double &dt, const vpColVector &u=vpColVector()) |
void | predict (const double &dt, const vpColVector &u=vpColVector()) |
void | update (const MeasurementsType &z) |
vpColVector | computeFilteredState () |
void | setProcessFunction (const vpProcessFunction &f) |
void | setCommandStateFunction (const vpCommandStateFunction &bx) |
void | setLikelihoodFunction (const vpLikelihoodFunction &likelihood) |
void | setFilterFunction (const vpFilterFunction &filterFunc) |
void | setCheckResamplingFunction (const vpResamplingConditionFunction &resamplingCondFunc) |
void | setResamplingFunction (const vpResamplingFunction &resamplingFunc) |
Static Public Member Functions | |
static vpColVector | simpleAdd (const vpColVector &a, const vpColVector &toAdd) |
static vpColVector | weightedMean (const std::vector< vpColVector > &particles, const std::vector< double > &weights, const vpStateAddFunction &addFunc) |
static bool | simpleResamplingCheck (const unsigned int &N, const std::vector< double > &weights) |
static vpParticlesWithWeights | simpleImportanceResampling (const std::vector< vpColVector > &particles, const std::vector< double > &weights) |
The class permits to use a Particle Filter.
MeasurementsType | The class that corresponds to the measurements used to compute the weights of the Particle Filter |
Be a particle representing the internal state of the PF, with and the state space. To each particle is associated a weight that represents its likelihood knowing the measurements and is used to compute the filtered state .
The first step of the PF is the prediction step. During this step, the particles of the PF are projected forward in time. Be the process function that project the forward in time. All the particles pass through the function , and some noise is independently added to each of them to form the new particles:
The second step of the PF is to update the weights associated to each particle based on new measurements. The update is based on the likelihood of a particle based on the measurements , where is the measurement space. Be the likelihood function, we have:
After an update, a check is performed to see if the PF is not degenerated (i.e. if the weigths of most particles became very low). If the PF became degenerated, the particles are resampled depending on a resampling scheme. Different kind of checks and of resampling algorithms exist in the litterature. In this class, we implemented the Simple Resampling algorithm in a dedicated method and let to the user the possibility of writing user-defined check and resampling methods.
Finally, we can compute the new state estimate by performing a weighted mean of the particles . Be , and the weighted mean function of the state space , we have:
Definition at line 96 of file vpParticleFilter.h.
typedef std::function<vpColVector(const vpColVector &, const vpColVector &, const double &)> vpParticleFilter< MeasurementsType >::vpCommandStateFunction |
Command model function, which projects a particle forward in time according to the command and its previous state. The first argument is the command(s), the second is the particle and the third is the period. The return is the updated particle after period seconds.
Definition at line 130 of file vpParticleFilter.h.
typedef std::function<vpColVector(const std::vector<vpColVector> &, const std::vector<double> &, const vpStateAddFunction &)> vpParticleFilter< MeasurementsType >::vpFilterFunction |
Filter function, which computes the filtered state of the particle filter. The first argument is the vector containing the particles, the second argument is the associated vector of weights and the third argument is a function to perform an addition in the state space. The return is the corresponding filtered state.
Definition at line 148 of file vpParticleFilter.h.
typedef std::function<double(const vpColVector &, const MeasurementsType &)> vpParticleFilter< MeasurementsType >::vpLikelihoodFunction |
Likelihood function, which evaluates the likelihood of a particle with regard to the measurements. The first argument is the particle that is evaluated. The second argument is the measurements vector. The return is the likelihood of the particle, which equals to 0 when the particle does not match at all the measurements and to 1 when it matches completely.
Definition at line 139 of file vpParticleFilter.h.
typedef struct vpParticleFilter::vpParticlesWithWeights vpParticleFilter< MeasurementsType >::vpParticlesWithWeights |
Structure of vectors for which the i^th element of the weights vector is associated to the i^th element of the particles vectors.
typedef std::function<vpColVector(const vpColVector &, const double &)> vpParticleFilter< MeasurementsType >::vpProcessFunction |
Process model function, which projects a particle forward in time. The first argument is a particle, the second is the period and the return is the particle projected in the future.
Definition at line 122 of file vpParticleFilter.h.
typedef std::function<bool(const unsigned int &, const std::vector<double> &)> vpParticleFilter< MeasurementsType >::vpResamplingConditionFunction |
Function that takes as argument the number of particles and the vector of weights associated to each particle and returns true if the resampling must be performed and false otherwise.
Definition at line 155 of file vpParticleFilter.h.
typedef std::function<vpParticlesWithWeights(const std::vector<vpColVector> &, const std::vector<double> &)> vpParticleFilter< MeasurementsType >::vpResamplingFunction |
Function that takes as argument the vector of particles and the vector of associated weights. It returns a pair < new_vector_particles, new_weights >.
Definition at line 161 of file vpParticleFilter.h.
typedef std::function<vpColVector(const vpColVector &, const vpColVector &)> vpParticleFilter< MeasurementsType >::vpStateAddFunction |
Function that computes either the equivalent of an addition in the state space. The first argument is the vector to which we must add something and the second argument is the thing to be added. The return is the result of this operation.
Definition at line 115 of file vpParticleFilter.h.
vpParticleFilter< MeasurementsType >::vpParticleFilter | ( | const unsigned int & | N, |
const std::vector< double > & | stdev, | ||
const long & | seed = -1 , |
||
const int & | nbThreads = -1 |
||
) |
Construct a new vpParticleFilter object.
[in] | N | The number of particles. |
[in] | stdev | The standard deviations of the noise, each item correspond to one component of the state. |
[in] | seed | The seed to use to create the noise generators. A negative value makes the seed to be based on the current time. |
[in] | nbThreads | The number of threads the user would like to use. Negative value to set the maximum number of threads available when using OpenMP. |
Definition at line 419 of file vpParticleFilter.h.
References vpTime::measureTimeMicros(), vpUniRand::setSeed(), and vpUniRand::uniform().
|
inlinevirtual |
Definition at line 175 of file vpParticleFilter.h.
vpColVector vpParticleFilter< MeasurementsType >::computeFilteredState |
Compute the filtered state from the particles and their associated weights.
Definition at line 554 of file vpParticleFilter.h.
void vpParticleFilter< MeasurementsType >::filter | ( | const MeasurementsType & | z, |
const double & | dt, | ||
const vpColVector & | u = vpColVector() |
||
) |
Perform first the prediction step and then the update step. If needed, resampling will also be performed.
[in] | z | The new measurement. |
[in] | dt | The time in the future we must predict. |
[in] | u | The command(s) given to the system, if the impact of the system is known. |
Definition at line 515 of file vpParticleFilter.h.
void vpParticleFilter< MeasurementsType >::init | ( | const vpColVector & | x0, |
const vpCommandStateFunction & | bx, | ||
const vpLikelihoodFunction & | l, | ||
const vpResamplingConditionFunction & | checkResamplingFunc, | ||
const vpResamplingFunction & | resamplingFunc, | ||
const vpFilterFunction & | filterFunc = weightedMean , |
||
const vpStateAddFunction & | addFunc = simpleAdd |
||
) |
Set the guess of the initial state.
[in] | x0 | Guess of the initial state. |
[in] | bx | Process model function, which projects the particles forward in time based on the previous state and on the input commands. The first argument is the command vector, the second is a particle and the last is the period. The return is the particle projected in the future. |
[in] | l | Likelihood function, that evaluates how much a particle matches the measurements. 0 means that the particle does not match the measurement at all and 1 that it maches completely. |
[in] | checkResamplingFunc | The function that returns true when the filter starts to degenerate and false otherwise. |
[in] | resamplingFunc | The resampling function that generate new particles and associated weights when the filter starts to degenerate. |
[in] | filterFunc | The function to compute the filtered state from the particles and their weights. |
[in] | addFunc | The function that permits to perform an addition in the state space. |
Definition at line 493 of file vpParticleFilter.h.
References vpException::dimensionError, and vpArray2D< Type >::size().
void vpParticleFilter< MeasurementsType >::init | ( | const vpColVector & | x0, |
const vpProcessFunction & | f, | ||
const vpLikelihoodFunction & | l, | ||
const vpResamplingConditionFunction & | checkResamplingFunc, | ||
const vpResamplingFunction & | resamplingFunc, | ||
const vpFilterFunction & | filterFunc = weightedMean , |
||
const vpStateAddFunction & | addFunc = simpleAdd |
||
) |
Set the guess of the initial state.
[in] | x0 | Guess of the initial state. |
[in] | f | Process model function, which projects the particles forward in time. The first argument is a particle, the second is the period and the return is the particle projected in the future. |
[in] | l | Likelihood function, that evaluates how much a particle matches the measurements. 0 means that the particle does not match the measurement at all and 1 that it maches completely. |
[in] | checkResamplingFunc | The function that returns true when the filter starts to degenerate and false otherwise. |
[in] | resamplingFunc | The resampling function that generate new particles and associated weights when the filter starts to degenerate. |
[in] | filterFunc | The function to compute the filtered state from the particles and their weights. |
[in] | addFunc | The function that permits to perform an addition in the state space. |
Definition at line 471 of file vpParticleFilter.h.
References vpException::dimensionError, and vpArray2D< Type >::size().
void vpParticleFilter< MeasurementsType >::predict | ( | const double & | dt, |
const vpColVector & | u = vpColVector() |
||
) |
Predict the new state based on the last state and how far in time we want to predict.
[in] | dt | The time in the future we must predict. |
[in] | u | The command(s) given to the system, if the impact of the system is known. |
Definition at line 522 of file vpParticleFilter.h.
|
inline |
Set the function that returns true when the filter starts to degenerate and false otherwise.
resamplingCondFunc | The evaluation function to use. |
Definition at line 318 of file vpParticleFilter.h.
|
inline |
Set the command function to use when projecting the particles in the future.
bx | The command function to use. |
Definition at line 283 of file vpParticleFilter.h.
|
inline |
Set the filter function that compute the filtered state from the particles and their associated weights.
filterFunc | The filtering function to use. |
Definition at line 307 of file vpParticleFilter.h.
|
inline |
Set the likelihood function that updates the weights of the particles based on the new measurements.
likelihood | The likelihood function. |
Definition at line 296 of file vpParticleFilter.h.
|
inline |
Set the process function to use when projecting the particles in the future.
f | The process function to use. |
Definition at line 269 of file vpParticleFilter.h.
|
inline |
Set the resampling function that generate new particles and associated weights when the filter starts to degenerate.
resamplingFunc | The resampling function to use. |
Definition at line 329 of file vpParticleFilter.h.
|
inlinestatic |
Simple function to compute an addition, which just does .
[in] | a | Vector to which we must add something. |
[in] | toAdd | The something we must add to a . |
Definition at line 341 of file vpParticleFilter.h.
|
static |
Function implementing the resampling of a Simple Importance Resampling Particle Filter.
[in] | particles | Vector containing the particles. |
[in] | weights | Vector containing the associated weights. |
Definition at line 589 of file vpParticleFilter.h.
References vpParticleFilter< MeasurementsType >::vpParticlesWithWeights::m_particles, and vpParticleFilter< MeasurementsType >::vpParticlesWithWeights::m_weights.
|
static |
Returns true if the following condition is fulfilled, or if all the particles diverged: .
[in] | N | The number of particles. |
[in] | weights | The weights associated to each particle. |
Definition at line 574 of file vpParticleFilter.h.
void vpParticleFilter< MeasurementsType >::update | ( | const MeasurementsType & | z | ) |
Update the weights of the particles based on a new measurement. The weights will be normalized (i.e. each weight will be divided by the sum of the weights).
[in] | z | The measurements at the current timestep. |
Definition at line 535 of file vpParticleFilter.h.
References vpParticleFilter< MeasurementsType >::vpParticlesWithWeights::m_particles, and vpParticleFilter< MeasurementsType >::vpParticlesWithWeights::m_weights.
|
static |
Simple function to compute a weighted mean, which just does .
[in] | particles | Vector that contains all the particles. |
[in] | weights | Vector that contains the weights associated to the particles. |
[in] | addFunc | How to perform the addition. |
Definition at line 560 of file vpParticleFilter.h.
References vpException::dimensionError, and vpArray2D< Type >::size().