17 #ifndef INCLUDED_numeric_random_reservoir_sample_hh
18 #define INCLUDED_numeric_random_reservoir_sample_hh
41 Real const accept_prob(
42 static_cast< Real > (n_wanted) / static_cast< Real > (n_seen)
50 template<
typename T >
65 Real const accept_prob(
101 template<
typename T >
111 assert( n_wanted <= vec.size() );
114 values.reserve( n_wanted );
116 for ( iter it = vec.begin(),
end = vec.end(); it !=
end; ++it ) {
118 if ( values.size() < n_wanted ) {
119 values.push_back( *it );
121 Real const accept_prob(
137 #endif // INCLUDED_numeric_random_reservoir_sampling_HH
numeric::Size n_wanted() const
utility::vector1< T > reservoir_sample(utility::vector1< T > const &vec, numeric::Size n_wanted, RandomGenerator &rg=numeric::random::rg())
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.
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_
IntegerOptionKey const end
void add_value(T const &val)
IntegerOptionKey const iter
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...
utility::vector1< T > const & values() const
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.
double uniform()
Generate a random number between 0 and 1. Threadsafe since each thread uses its own random generator...
numeric::Real reservoir_sample_accept_prob(numeric::Size n_wanted, numeric::Size n_seen)
Returns the probability that the Nth value in a sequence should be accepted using the reservoir sampl...