Skip to content

Commit

Permalink
Custom implementation of weighted sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Oct 27, 2024
1 parent 8b9f65c commit 0aefc33
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/utils/wsample.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

"""
weighted sampling single implementation
"""
function wsample_single(a, w)
stop_w = rand() * sum(w)
partial_w = first(w)
j = 1
for i in 2:length(w)
@inbounds partial_w += w[i]
if partial_w > stop_w
j = i - 1
break
end
end
return a[j]
end

0 comments on commit 0aefc33

Please sign in to comment.