-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accelerate to calcuration modularity #34
Comments
Hello thank you for the feedback. I tried to run your code. In my tests (see below) your code takes twice as long to compute. using SimpleHypergraphs
using Random
using StatsBase
using BenchmarkTools
Random.seed!(0)
m = sample([nothing, true], Weights([0.8,0.2]),(30,30))
h = Hypergraph(m)
part = SimpleHypergraphs.randompartition(h,5)
ha = SimpleHypergraphs.HypergraphAggs(h)
function modularity2(h::Hypergraph, partition::Vector{Set{Int}},
ha::SimpleHypergraphs.HypergraphAggs=SimpleHypergraphs.HypergraphAggs(h))
@boundscheck sum(length.(partition)) == nhv(h)
@boundscheck union(partition...) == Set(1:nhv(h))
volP_volV = [sum(ha.deg_vs[i] for i in p)/ha.volV for p in partition]
eP = [count(i-> ha.hes[i]>0 && (keys(h.he2v[i]) ⊆ p), 1:nhe(h)) for p in partition]
mr = 0
v = 0
for i in 1:nhv(h) v += length(gethyperedges(h, i)) end
dict = Dict([])
for i in 1:nhe(h)
dict[length(getvertices(h, i))] = get(dict, length(getvertices(h, i)), 0) + 1
end
va = Dict([i => 0.0 for i in 1:length(partition)])
for (i, cluster) in enumerate(partition)
for node in cluster va[i] += length(gethyperedges(h, node)) end
va[i] /= v
end
for (key, val) in dict
tmp = 0
for (key2, val2) in va
tmp += (val2 ^ key)
end
tmp *= val
mr += tmp
end
# (sum(eP) - sum( ha.Ed[d]*sum(volP_volV.^d) for d in 1:ha.max_hes)) / nhe(h)
(sum(eP) - mr) / nhe(h)
end And now the tests:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SimpleHypergraphs.jl version v1.6.0
SimpleHypergraphs.jl/src/modularity.jl
Line 62 in 1b03ab3
This line takes time. I succeeded acceleration. I confirm this program works correctly and fast some hypergraphs and partitions.
However, I can't description why acceleration... (Originally, I was improving other line.)
So you can ignore and close this issue. Please refer this program if you like.
And sorry my poor English. Thank you.
The text was updated successfully, but these errors were encountered: