Skip to content

Commit

Permalink
initseeds(KmCentralityAlg): vectorize
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Stukalov committed Dec 19, 2023
1 parent 633d78e commit 0167254
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/seeding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,11 @@ function initseeds_by_costs!(iseeds::AbstractVector{<:Integer}, alg::KmCentralit
k = length(iseeds)
check_seeding_args(n, k)

# compute score for each item
coefs = vec(sum(costs, dims=2))
for i = 1:n
@inbounds coefs[i] = inv(coefs[i])
end

# scores[j] = \sum_j costs[i,j] / (\sum_{j'} costs[i,j'])
# = costs[i,j] * coefs[i]
scores = costs'coefs
scores = costs'vec(mapslices(invsum, costs, dims=2))

# lower score indicates better seeds
sp = sortperm(scores)
for i = 1:k
@inbounds iseeds[i] = sp[i]
end
copyto!(iseeds, 1, sortperm(scores), 1, k)
return iseeds
end

Expand Down

0 comments on commit 0167254

Please sign in to comment.