Skip to content

Commit e3543a1

Browse files
aristizabal95Jaimemosgpa-uriza
committed
Fix issue with sampling without replacement
Before this fix uniform sampling is not guaranteed, over-representing the first combination of neighbors, and not sampling the last possible combination Co-authored-by: Jaime Mosquera Gutiérrez <[email protected]> Co-authored-by: Andres Uriza <[email protected]>
1 parent bd56751 commit e3543a1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

csrc/cpu/neighbor_sample_cpu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ hetero_sample(const vector<node_t> &node_types,
325325
} else {
326326
// Sample without replacement:
327327
unordered_set<int64_t> rnd_indices;
328-
for (int64_t j = col_count - num_samples; j < col_count; j++) {
328+
for (int64_t j = col_count - num_samples + 1; j < col_count + 1; j++) {
329329
int64_t rnd = uniform_randint(j);
330330
if (!rnd_indices.insert(rnd).second) {
331-
rnd = j;
332-
rnd_indices.insert(j);
331+
rnd = j - 1;
332+
rnd_indices.insert(rnd);
333333
}
334334
const int64_t offset = col_start + rnd;
335335
const int64_t &v = row_data[offset];

0 commit comments

Comments
 (0)