17 #ifndef INCLUDED_numeric_random_reservoir_sample_hh
18 #define INCLUDED_numeric_random_reservoir_sample_hh
35 template<
typename T >
45 Real const accept_prob(
87 Real const accept_prob(
88 static_cast< Real > (n_wanted) / static_cast< Real > (n_seen)
93 template<
typename T >
103 assert( n_wanted <= vec.size() );
106 values.reserve( n_wanted );
108 for ( iter it = vec.begin(),
end = vec.end(); it !=
end; ++it ) {
110 if ( values.size() < n_wanted ) {
111 values.push_back( *it );
113 Real const accept_prob(
117 if ( rg.
uniform() <= accept_prob ) {
129 #endif // INCLUDED_numeric_random_reservoir_sampling_HH
numeric::Size n_wanted() const
utility::vector1< T > values() const
RandomGenerator & rg()
Return the one-per-thread "singleton" random generator.
numeric::Size n_seen() const
numeric::Size n_vals() const
Random number generator system.
Simple container for keeping K random values.
utility::keys::lookup::end< KeyType > const end
Random number generator system.
int random_range(int low, int high)
Return a number uniformly drawn from the inclusive range between low and high. Threadsafe since each ...
utility::vector1< T > values_
ReservoirSampler(numeric::Size const wanted)
super::const_iterator const_iterator
rosetta project type declarations. Should be kept updated with core/types.hh. This exists because num...
numeric::Size const n_wanted_
vector1: std::vector with 1-based indexing
int random_range(int low, int high)
Returns a random int in the range specified by the arguments.
numeric::Real reservoir_sample_accept_prob(numeric::Size n_wanted, numeric::Size const n_seen)
Returns the probability that the Nth value in a sequence should be accepted using the reservoir sampl...
double uniform()
Generate a random number between 0 and 1. Threadsafe since each thread uses its own random generator...
utility::vector1< T > reservoir_sample(utility::vector1< T > const &vec, numeric::Size const n_wanted, RandomGenerator &rg)