trsl logo

trsl::is_picked_systematic< ElementType, WeightType, WeightAccessor > Class Template Reference

Functor to use with persistent_filter_iterator for systematic sampling of a range. More...

#include <is_picked_systematic.hpp>

List of all members.

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.
 is_picked_systematic (size_t sampleSize, WeightType populationWeight, WeightAccessor const &wac=WeightAccessor())
 Construction with system-provided random number.
 is_picked_systematic (size_t sampleSize, WeightType populationWeight, WeightType uniform01, WeightAccessor const &wac=WeightAccessor())
 Construction with user-provided random number.
bool operator() (const ElementType &e)
 Decides whether e should be picked or not (used by persistent_filter_iterator).
bool is_first_pick (const ElementType &e) const
 Return whether e has been picked already.
bool operator== (const is_picked_systematic< ElementType, WeightType, WeightAccessor > &p) const
 Returns whether two predicates are at the same sampling advancement.

Detailed Description

template<typename ElementType, typename WeightType = double, typename WeightAccessor = mp_weight_accessor<WeightType, ElementType>>
class trsl::is_picked_systematic< ElementType, WeightType, WeightAccessor >

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.

Parameters:
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:

  • [1] R. Douc, O. Cappe, and E. Moulines. Comparison of resampling schemes for particle filtering. International Symposium on Parallel and Distributed Processing and Applications, 2005:64, 2005.
  • [2] J. Hol, T. Schön, and F. Gustafsson. On resampling algorithms for particle filters. In Nonlinear Statistical Signal Processing Workshop, 2006.
Examples:

ParticleCollection.hpp, trsl_example1.cpp, and trsl_example2.cpp.

Definition at line 77 of file is_picked_systematic.hpp.


Constructor & Destructor Documentation

template<typename ElementType, typename WeightType = double, typename WeightAccessor = mp_weight_accessor<WeightType, ElementType>>
trsl::is_picked_systematic< ElementType, WeightType, WeightAccessor >::is_picked_systematic (  )  [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.

template<typename ElementType, typename WeightType = double, typename WeightAccessor = mp_weight_accessor<WeightType, ElementType>>
trsl::is_picked_systematic< ElementType, WeightType, WeightAccessor >::is_picked_systematic ( size_t  sampleSize,
WeightType  populationWeight,
WeightAccessor const &  wac = WeightAccessor() 
) [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.

Parameters:
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.

template<typename ElementType, typename WeightType = double, typename WeightAccessor = mp_weight_accessor<WeightType, ElementType>>
trsl::is_picked_systematic< ElementType, WeightType, WeightAccessor >::is_picked_systematic ( size_t  sampleSize,
WeightType  populationWeight,
WeightType  uniform01,
WeightAccessor const &  wac = WeightAccessor() 
) [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.

Parameters:
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.


Member Function Documentation

template<typename ElementType, typename WeightType = double, typename WeightAccessor = mp_weight_accessor<WeightType, ElementType>>
bool trsl::is_picked_systematic< ElementType, WeightType, WeightAccessor >::is_first_pick ( const ElementType &  e  )  const [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.

template<typename ElementType, typename WeightType = double, typename WeightAccessor = mp_weight_accessor<WeightType, ElementType>>
bool trsl::is_picked_systematic< ElementType, WeightType, WeightAccessor >::operator() ( const ElementType &  e  )  [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.

template<typename ElementType, typename WeightType = double, typename WeightAccessor = mp_weight_accessor<WeightType, ElementType>>
bool trsl::is_picked_systematic< ElementType, WeightType, WeightAccessor >::operator== ( const is_picked_systematic< ElementType, WeightType, WeightAccessor > &  p  )  const [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.


The documentation for this class was generated from the following file:
© Copyright 2007-2011 Renaud Detry.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt.)
Revised Wed Apr 6 16:30:07 2011.
SourceForge.net Logo