Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,22 @@ function efraimidis_ares_wsample_norep!(a::AbstractArray, wv::WeightVec, x::Abst

# initialize priority queue
pq = Vector{Pair{Float64,Int}}(k)
@inbounds for i in 1:k
pq[i] = (wv.values[i]/randexp() => i)
i = 0
s = 0
@inbounds for s in 1:n
if wv.values[s] > 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> 0 should be enough, no?

i += 1
pq[i] = (wv.values[s]/randexp() => s)
end
i >= k && break
end
i < k && throw(DimensionMismatch("wv must have at least $k positive entries (got $i)"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"strictly positive"

heapify!(pq)

# set threshold
@inbounds threshold = pq[1].first

@inbounds for i in k+1:n
@inbounds for i in s+1:n
key = wv.values[i]/randexp()

# if key is larger than the threshold
Expand Down Expand Up @@ -561,17 +568,25 @@ function efraimidis_aexpj_wsample_norep!(a::AbstractArray, wv::WeightVec, x::Abs

# initialize priority queue
pq = Vector{Pair{Float64,Int}}(k)
@inbounds for i in 1:k
pq[i] = (wv.values[i]/randexp() => i)
i = 0
s = 0
@inbounds for s in 1:n
if wv.values[s] > 0.0
i += 1
pq[i] = (wv.values[s]/randexp() => s)
end
i >= k && break
end
i < k && throw(DimensionMismatch("wv must have at least $k positive entries (got $i)"))
heapify!(pq)

# set threshold
@inbounds threshold = pq[1].first
X = threshold*randexp()

@inbounds for i in k+1:n
@inbounds for i in s+1:n
w = wv.values[i]
w > 0.0 || continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Would be more consistent to use > 0 since <= 0 is used below.

X -= w
X <= 0 || continue

Expand Down