Skip to content
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

Louvain method #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

afternone
Copy link

Here is an efficient implementation of the Louvain fast-unfolding algorithm based on PR #3 . It calculates the modularity change directly and fixes some problems of the implementation in #3. The comparison shows that its performance is very good. Please feel free to comment or make changes.

julia> g = CliqueGraph(10, 100)
{1000, 4600} undirected simple Int64 graph

julia> @benchmark c = community_detection_louvain_old(g)
BenchmarkTools.Trial: 11 samples with 1 evaluation.
 Range (min … max):  475.899 ms … 493.400 ms  ┊ GC (min … max): 3.34% … 3.14%
 Time  (median):     478.429 ms               ┊ GC (median):    3.41%
 Time  (mean ± σ):   480.148 ms ±   5.228 ms  ┊ GC (mean ± σ):  3.40% ± 0.13%

  █
  █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁
  493 ms           Histogram: frequency by time          486 ms <

 Memory estimate: 1.47 GiB, allocs estimate: 8927625.

julia> @benchmark c = community_detection_louvain(g)
BenchmarkTools.Trial: 4721 samples with 1 evaluation.
 Range (min … max):  721.900 μs …   3.174 ms  ┊ GC (min … max): 0.00% … 64.60%
 Time  (median):       1.018 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):     1.055 ms ± 255.500 μs  ┊ GC (mean ± σ):  3.90% ±  9.54%

  █
  █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁▁▁▁▁▁▁▁  ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁
  1.21 ms          Histogram: frequency by time          859 μs <

 Memory estimate: 1.28 MiB, allocs estimate: 4788.
 
 
 julia> g = CliqueGraph(5,8)
{40, 88} undirected simple Int64 graph

julia> c = community_detection_louvain_old(g)'
1×40 adjoint(::Vector{Int64}) with eltype Int64:
 1  1  1  1  1  1  1  1  1  1  2  2  2  2  2  2  2  2  2  2  3  3  3  3  3  3  3  3  3  3  4  4  4  4  4  4  4  4  4  4

julia> c = community_detection_louvain(g)'
1×40 adjoint(::Vector{Int64}) with eltype Int64:
 1  1  1  1  1  2  2  2  2  2  3  3  3  3  3  4  4  4  4  4  5  5  5  5  5  6  6  6  6  6  7  7  7  7  7  8  8  8  8  8     

@afternone afternone changed the title louvain method Louvain method Aug 16, 2021
@storopoli
Copy link
Contributor

storopoli commented Aug 17, 2021

This is great I hope this gets merged soon!

We could tackle Leiden afterwards. There is an old implementation in bicycle1885 /Leiden.jl that is MIT licensed.

@storopoli
Copy link
Contributor

Now that CommunityDetection.jl is being somewhat maintained we can take a look at this.

@matbesancon do you want me to review this PR? You can assign me as a reviewer if you want.

@afternone do you think something should be updated in the PR? I can deal with the LighGraphs -> Graphs migration for you. What I mean is "do you think any Julia 1.6 feature might be incorporated or updated in this PR?"

@elisno
Copy link

elisno commented Nov 22, 2021

I hope we can add a resolution parameter (γ=1.0) like the one Graphs.modularity accepts.

AFAICT, it should be sufficient to scale the updates to node_comm_W[neighbor_comm] by this resolution.

EDIT: Maybe comm_W[...] as well?

@matbesancon
Copy link
Member

yes that would be great, after the conflict has been resolved

@gdalle
Copy link
Member

gdalle commented Nov 15, 2023

@afternone sorry for the huge delay, this repo is barely active as you can see. Can I suggest you submit the same PR to Graphs.jl?

@gdalle
Copy link
Member

gdalle commented Nov 15, 2023

Without the SimpleWeightedGraphs dependency of course

@gdalle
Copy link
Member

gdalle commented Nov 15, 2023

@matbesancon can you think of a way to remove the dependency on Clustering in order to add this code to the main repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants