49 size_t desiredSamples, std::vector<TParticle>& outSamples,
50 size_t timeoutTrials = 1000)
55 typename std::vector<TParticle>::iterator it;
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;
86 }
while (acceptanceProb <
89 (++timeoutCount) < timeoutTrials);
92 if (timeoutCount >= timeoutTrials)
94 it->log_w = log(bestLik);
virtual ~CRejectionSamplingCapable()=default
Virtual destructor.
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.