array R[k]; // result integer i, j; // fill the reservoir array for each i in 1 to k do R[i] := S[i] done; // replace elements with gradually decreasing probability for each i in k+1 to length(S) do j := random(1, i); // important: inclusive range if j <= k then R[j] := S[i] fi done
Random commentary about Machine Learning, BigData, Spark, Deep Learning, C++, STL, Boost, Perl, Python, Algorithms, Problem Solving and Web Search
Wednesday, August 10, 2011
Reservoir sampling
Reservoir sampling, a good algo to know for randomly selecting k items from a list of N. the key observation here is that the replacement is happening with increasing probability i
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment