Skip to content

Commit

Permalink
fix Reservoir Sampling in Sample of random.h (#4450)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyu1994 authored Jul 7, 2021
1 parent e36cc9c commit a06899a
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions include/LightGBM/utils/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,10 @@ class Random {
ret.push_back(i);
}
}
} else if (K == 1) {
int v = NextInt(0, N);
ret.push_back(v);
} else {
std::set<int> sample_set;
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) {
sample_set.insert(r);
}
Expand Down

0 comments on commit a06899a

Please sign in to comment.