9 #ifndef CRejectionSamplingCapable_H 10 #define CRejectionSamplingCapable_H 28 template <
class TStateSpace>
49 size_t desiredSamples, std::vector<TParticle>& outSamples,
50 size_t timeoutTrials = 1000)
58 if (outSamples.size() != desiredSamples)
64 outSamples.resize(desiredSamples);
65 for (it = outSamples.begin(); it != outSamples.end(); ++it)
66 it->d.reset(
new TStateSpace);
70 double acceptanceProb;
71 for (it = outSamples.begin(); it != outSamples.end(); ++it)
73 size_t timeoutCount = 0;
74 double bestLik = -1e250;
80 ASSERT_(acceptanceProb >= 0 && acceptanceProb <= 1);
81 if (acceptanceProb > bestLik)
83 bestLik = acceptanceProb;
88 (++timeoutCount) < timeoutTrials);
91 if (timeoutCount >= timeoutTrials)
93 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.
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.
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
CProbabilityParticle< TStateSpace > TParticle