9 #ifndef CRejectionSamplingCapable_H 10 #define CRejectionSamplingCapable_H 27 template <
class TStateSpace>
47 size_t desiredSamples,
48 std::vector<TParticle> &outSamples,
49 size_t timeoutTrials = 1000)
57 if ( outSamples.size() != desiredSamples )
63 outSamples.resize( desiredSamples );
64 for (it = outSamples.begin(); it != outSamples.end(); ++it)
65 it->d.reset(
new TStateSpace);
69 double acceptanceProb;
70 for (it = outSamples.begin();it!=outSamples.end();++it)
72 size_t timeoutCount = 0;
73 double bestLik = -1e250;
79 ASSERT_(acceptanceProb>=0 && acceptanceProb<=1);
80 if (acceptanceProb>bestLik)
82 bestLik = acceptanceProb;
86 (++timeoutCount)<timeoutTrials );
89 if (timeoutCount>=timeoutTrials)
91 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.
BASE_IMPEXP CRandomGenerator randomGenerator
A static instance of a CRandomGenerator class, for use in single-thread applications.
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.
virtual void RS_drawFromProposal(TStateSpace &outSample)=0
Generates one sample, drawing from some proposal distribution.
virtual ~CRejectionSamplingCapable()
Virtual destructor.
A base class for implementing rejection sampling in a generic state space.
CProbabilityParticle< TStateSpace > TParticle