Skip to content

Commit

Permalink
New approach!
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Nov 2, 2024
1 parent 1cb6a1e commit 99d8f26
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/utils/wsample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ function wsample_single(a, w, wsum)
end
return @inbounds a[j]
end

"""
weighted sampling single implementation - v2
Based on https://www.aarondefazio.com/tangentially/?p=58
"""
function wsample_single_2(a, w, wmax)
n = length(w)
idx = rand(1:n)
u = wmax * rand()
while u > w[idx]
idx = rand(1:n)
u = wmax * rand()
end
return idx
end

0 comments on commit 99d8f26

Please sign in to comment.