9 #ifndef CRejectionSamplingCapable_H 10 #define CRejectionSamplingCapable_H 50 size_t desiredSamples, std::vector<TParticle>& outSamples,
51 size_t timeoutTrials = 1000)
59 if (outSamples.size() != desiredSamples)
65 outSamples.resize(desiredSamples);
66 for (it = outSamples.begin(); it != outSamples.end(); ++it)
67 it->d.reset(
new TStateSpace);
71 double acceptanceProb;
72 for (it = outSamples.begin(); it != outSamples.end(); ++it)
74 size_t timeoutCount = 0;
75 double bestLik = -1e250;
81 ASSERT_(acceptanceProb >= 0 && acceptanceProb <= 1);
82 if (acceptanceProb > bestLik)
84 bestLik = acceptanceProb;
87 }
while (acceptanceProb <
90 (++timeoutCount) < timeoutTrials);
93 if (timeoutCount >= timeoutTrials)
95 it->log_w = log(bestLik);
void rejectionSampling(size_t desiredSamples, std::vector< TParticle > &outSamples, size_t timeoutTrials=1000)
Generates a set of N independent samples via rejection sampling.
#define ASSERT_(f)
Defines an assertion mechanism.
virtual double RS_observationLikelihood(const TStateSpace &x)=0
Returns the NORMALIZED observation likelihood (linear, not exponential!!!) at a given point of the st...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A template class for holding a the data and the weight of a particle.
A base class for implementing rejection sampling in a generic state space.
particle_storage_mode
use for CProbabilityParticle
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
virtual void RS_drawFromProposal(TStateSpace &outSample)=0
Generates one sample, drawing from some proposal distribution.
virtual ~CRejectionSamplingCapable()
Virtual destructor.