Functor to use with persistent_filter_iterator for systematic sampling of a range. More...
#include <is_picked_systematic.hpp>
Public Types | |
typedef ElementType | element_type |
typedef WeightType | weight_type |
typedef WeightAccessor | weight_accessor_type |
Public Member Functions | |
is_picked_systematic () | |
Default constructor, shoud not be used explicitely. More... | |
is_picked_systematic (size_t sampleSize, WeightType populationWeight, WeightAccessor const &wac=WeightAccessor()) | |
Construction with system-provided random number. More... | |
is_picked_systematic (size_t sampleSize, WeightType populationWeight, WeightType uniform01, WeightAccessor const &wac=WeightAccessor()) | |
Construction with user-provided random number. More... | |
bool | operator() (const ElementType &e) |
Decides whether e should be picked or not (used by persistent_filter_iterator). More... | |
bool | is_first_pick (const ElementType &e) const |
Return whether e has been picked already. More... | |
bool | operator== (const is_picked_systematic< ElementType, WeightType, WeightAccessor > &p) const |
Returns whether two predicates are at the same sampling advancement. More... | |
Functor to use with persistent_filter_iterator for systematic sampling of a range.
The sampling method is systematic sampling [1, 2].
This class is intended to be used as a predicate functor to trsl::persistent_filter_iterator to form a sample iterator. The sample iterator accesses a population of elements through a range defined by a pair of Forward Iterators (begin/end), and provides on-the-fly iteration through a sample of the population.
Systematic sampling may perform very badly if the order in which the input population is presented is following a pattern. If a pattern is likely to occur in the population, the user may want to pipe the sample iterator after a trsl::random_permutation_iterator, or use is_picked_systematic with ppfilter_iterator. The resulting iterator effectively implements probability sampling. The price to pay for probability sampling is a Random Access Iterator. While persistent_filter_iterator will work e.g. with std::list
, ppfilter_iterator requires e.g. std::vector
or std::deque
.
ElementType | Type of the elements in the population. Constness and reference modifiers are handled internally; this parameter should be a bare type, e.g. Particle (not const Particle& ). |
WeightType | Element weight type, should be a floating point type. Defaults to double . |
WeightAccessor | Type of the accessor that will allow to extract weights from elements. Defaults to mp_weight_accessor, see Accessors for further details on accessors. |
References:
Definition at line 77 of file is_picked_systematic.hpp.
|
inline |
Default constructor, shoud not be used explicitely.
This constructor makes an invalid predicate. It should only be used in cases where the predicate is never used.
Definition at line 92 of file is_picked_systematic.hpp.
|
inline |
Construction with system-provided random number.
The systematic sampling predicate initialization needs a random number in [0,1[
. This constructor uses trsl::rand_gen::uniform_01 to generate that number. See Random Number Generators for more details.
sampleSize | Number of elements in the sample, within [0, infinity[ . |
populationWeight | Total weight of the population, within ]0, infinity[ . Generally equal to 1. |
wac | Weight accessor. Defaults to mp_weight_accessor. Note that if you don't pass explicitly a mp_weight_accessor(&ElementType::GETWEIGHTMETHOD ), the default constructor for mp_weight_accessor will setup to always return 1, ignoring element weights. See Accessors for further details. |
The population weight has to be strictly larger than 0. Also, WeightType
should be fine enough to allow the sum of all element weights to be close to populationWeight
.
Definition at line 124 of file is_picked_systematic.hpp.
|
inline |
Construction with user-provided random number.
The systematic sampling predicate initialization needs a random number in [0,1[
. This constructor allows the user to provide that number directly; the user is free to choose a fancy random number generator, such as the Boost Random Number Library or GSL.
sampleSize | Number of elements in the sample, within [0, infinity[ . |
populationWeight | Total weight of the population, within ]0, infinity[ . Generally equal to 1. |
uniform01 | Random number in [0,1[ . |
wac | Weight accessor. Defaults to mp_weight_accessor. Note that if you don't pass explicitly a mp_weight_accessor(&ElementType::GETWEIGHTMETHOD ), the default constructor for mp_weight_accessor will setup to always return 1, ignoring element weights. See Accessors for further details. |
The population weight has to be strictly larger than 0. Also, WeightType
should be fine enough to allow the sum of all element weights to be close to populationWeight
.
Definition at line 164 of file is_picked_systematic.hpp.
|
inline |
Return whether e
has been picked already.
This method will return a coherent value only if the last call of operator()(const ElementType&) was on e
and returned true. When is_picked_systematic is used with a presistent_filter_iterator i
, this assumption is always valid for *i
as long as i
is not the end.
This method is awkward to use directly; it is meant to be called by trsl::is_first_pick.
Definition at line 226 of file is_picked_systematic.hpp.
|
inline |
Decides whether e
should be picked or not (used by persistent_filter_iterator).
Part of the requirements for persistent_filter_iterator predicates.
Definition at line 181 of file is_picked_systematic.hpp.
|
inline |
Returns whether two predicates are at the same sampling advancement.
Part of the requirements for persistent_filter_iterator predicates.
Definition at line 243 of file is_picked_systematic.hpp.