"...git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "d42f43132df63ae64783d3bc4f6366dd325116af"
Unverified Commit a06899ab authored by shiyu1994's avatar shiyu1994 Committed by GitHub
Browse files

fix Reservoir Sampling in Sample of random.h (#4450)

parent e36cc9c1
...@@ -82,13 +82,10 @@ class Random { ...@@ -82,13 +82,10 @@ class Random {
ret.push_back(i); ret.push_back(i);
} }
} }
} else if (K == 1) {
int v = NextInt(0, N);
ret.push_back(v);
} else { } else {
std::set<int> sample_set; std::set<int> sample_set;
for (int r = N - K; r < N; ++r) { for (int r = N - K; r < N; ++r) {
int v = NextInt(0, r); int v = NextInt(0, r + 1);
if (!sample_set.insert(v).second) { if (!sample_set.insert(v).second) {
sample_set.insert(r); sample_set.insert(r);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment