-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added rich club metric with tests and support for directed graphs Co-authored-by: Victor <[email protected]> Co-authored-by: vboussange <[email protected]>
- Loading branch information
1 parent
4b184cc
commit 1421e94
Showing
5 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
rich_club(g, k) | ||
Return the non-normalised [rich-club coefficient](https://en.wikipedia.org/wiki/Rich-club_coefficient) of graph `g`, | ||
with degree cut-off `k`. | ||
```jldoctest | ||
julia> using LightGraphs | ||
julia> g = star_graph(5) | ||
julia> rich_club(g, 1) | ||
0.4 | ||
``` | ||
""" | ||
function rich_club(g::AbstractGraph{T}, k::Int) where T | ||
E = zero(T) | ||
for e in edges(g) | ||
if (outdegree(g, src(e)) >= k) && (indegree(g, dst(e)) >= k ) | ||
E +=1 | ||
end | ||
end | ||
N = count(degree(g) .>= k) | ||
if is_directed(g) | ||
return E / (N*(N-1)) | ||
else | ||
return 2*E / (N*(N-1)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
@testset "Rich club coefficient" begin | ||
@testset "Small graphs" for _n in 5:10 | ||
@test @inferred rich_club(star_graph(_n), 1) ≈ 2 / _n | ||
@test @inferred rich_club(DiGraph(star_graph(_n)), 1) ≈ 2 / _n | ||
end | ||
@testset "Directed ($seed)" for seed in [1, 2, 3], (n, ne) in [(14, 18), (10, 22), (7, 16)] | ||
g = erdos_renyi(n, ne; is_directed=true, seed=seed) | ||
_r = rich_club(g, 1) | ||
@test @inferred rich_club(g, 1) > 0. | ||
end | ||
@testset "Undirected ($seed)" for seed in [1, 2, 3], (n, ne) in [(14, 18), (10, 22), (7, 16)] | ||
g = erdos_renyi(n, ne; is_directed=false, seed=seed) | ||
_r = rich_club(g, 1) | ||
@test @inferred rich_club(g, 1) > 0. | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters