Thrill
0.1
|
Implementation of reservoir sampling using Vitter's Algorithm R.
The reservoir size is fixed, new items replace old ones such that all items in the stream are sampled with the same uniform probability.
Definition at line 32 of file reservoir_sampling.hpp.
#include <reservoir_sampling.hpp>
Public Member Functions | |
ReservoirSampling (size_t size, std::vector< Type > &samples, RNG &rng) | |
initialize reservoir sampler More... | |
void | add (const Type &item) |
visit item, maybe add it to the sample. More... | |
size_t | count () const |
number of items seen More... | |
const std::vector< Type > & | samples () const |
access to samples More... | |
size_t | size () const |
size of reservoir More... | |
Private Attributes | |
size_t | count_ = 0 |
number of items seen More... | |
RNG & | rng_ |
source of randomness More... | |
std::vector< Type > & | samples_ |
reservoir More... | |
size_t | size_ |
size of reservoir More... | |
|
inline |
initialize reservoir sampler
Definition at line 36 of file reservoir_sampling.hpp.
References ReservoirSampling< Type, RNG >::samples_, and ReservoirSampling< Type, RNG >::size_.
|
inline |
visit item, maybe add it to the sample.
Definition at line 43 of file reservoir_sampling.hpp.
References ReservoirSampling< Type, RNG >::count_, ReservoirSampling< Type, RNG >::rng_, ReservoirSampling< Type, RNG >::samples_, ReservoirSampling< Type, RNG >::size_, and gen_data::x.
|
inline |
number of items seen
Definition at line 61 of file reservoir_sampling.hpp.
References ReservoirSampling< Type, RNG >::count_.
|
inline |
access to samples
Definition at line 64 of file reservoir_sampling.hpp.
References ReservoirSampling< Type, RNG >::samples_.
|
inline |
size of reservoir
Definition at line 58 of file reservoir_sampling.hpp.
References ReservoirSampling< Type, RNG >::size_.
|
private |
number of items seen
Definition at line 70 of file reservoir_sampling.hpp.
Referenced by ReservoirSampling< Type, RNG >::add(), ReservoirSamplingFast< ValueType, decltype(rng_)>::add(), ReservoirSamplingGrow< SampleIndexPair >::add(), ReservoirSamplingGrow< SampleIndexPair >::calc_sample_size(), ReservoirSampling< Type, RNG >::count(), ReservoirSamplingFast< ValueType, decltype(rng_)>::count(), and ReservoirSamplingGrow< SampleIndexPair >::count().
|
private |
source of randomness
Definition at line 74 of file reservoir_sampling.hpp.
Referenced by ReservoirSampling< Type, RNG >::add(), ReservoirSamplingFast< ValueType, decltype(rng_)>::add(), ReservoirSamplingGrow< SampleIndexPair >::add(), and ReservoirSamplingFast< ValueType, decltype(rng_)>::ReservoirSamplingFast().
|
private |
reservoir
Definition at line 72 of file reservoir_sampling.hpp.
Referenced by ReservoirSampling< Type, RNG >::add(), ReservoirSamplingFast< ValueType, decltype(rng_)>::add(), ReservoirSamplingGrow< SampleIndexPair >::add(), ReservoirSampling< Type, RNG >::ReservoirSampling(), ReservoirSamplingFast< ValueType, decltype(rng_)>::ReservoirSamplingFast(), ReservoirSampling< Type, RNG >::samples(), ReservoirSamplingFast< ValueType, decltype(rng_)>::samples(), and ReservoirSamplingGrow< SampleIndexPair >::samples().
|
private |
size of reservoir
Definition at line 68 of file reservoir_sampling.hpp.
Referenced by ReservoirSampling< Type, RNG >::add(), ReservoirSamplingFast< ValueType, decltype(rng_)>::add(), ReservoirSamplingGrow< SampleIndexPair >::add(), ReservoirSamplingGrow< SampleIndexPair >::calc_next_gap(), ReservoirSampling< Type, RNG >::ReservoirSampling(), ReservoirSamplingFast< ValueType, decltype(rng_)>::ReservoirSamplingFast(), ReservoirSampling< Type, RNG >::size(), ReservoirSamplingFast< ValueType, decltype(rng_)>::size(), and ReservoirSamplingGrow< SampleIndexPair >::size().