This repository has been archived by the owner on Dec 3, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathanalysis-communities.texw
70 lines (64 loc) · 1.96 KB
/
analysis-communities.texw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<<echo = False>>=
import igraph
import numpy as np
import collections
from matrix2latex import matrix2latex
g = igraph.read('repositories.gml').components().giant()
@
We apply two community-finding algorithms implemented in igraph, the Infomap
method and the greedy optimization of modularity, to the graph. Tables
\ref{tab:infomap} and \ref{tab:greedy} present the largest communities found
by each of these algorithms, and the most common programming languages in each
community.
<<>>=
info = g.community_infomap(edge_weights='weight')
info_mod = info.modularity
info_largest = sorted(info.subgraphs(), key=lambda x: len(x.vs),
reverse=True)[0:5]
info_sizes = [len(s.vs) for s in info_largest]
info_langs = [collections.Counter(s.vs['language']).most_common(5)
for s in info_largest]
greedy = g.community_fastgreedy(weights='weight').as_clustering()
greedy_mod = greedy.modularity
greedy_largest = sorted(greedy.subgraphs(), key=lambda x: len(x.vs),
reverse=True)[0:5]
greedy_sizes = [len(s.vs) for s in greedy_largest]
greedy_langs = [collections.Counter(s.vs['language']).most_common(5)
for s in greedy_largest]
@
\begin{table}[htbp]
\begin{center}
\caption{Largest communities, Infomap (weighted modularity:~<%= '%.3f' % info_mod %>)}
\label{tab:infomap}
\begin{tabular}{rl}
\toprule
Size & Top languages \\
\midrule
<%
for size, langs in zip(info_sizes, info_langs):
print size, '&',
print ', '.join("%s (%d)" % (l.replace('#', r'\#'), n) for l, n in langs)
print r'\\'
%>
\bottomrule
\end{tabular}
\end{center}
\end{table}
\begin{table}[htbp]
\begin{center}
\caption{Largest communities, greedy (weighted modularity:~<%= '%.3f' % greedy_mod %>)}
\label{tab:greedy}
\begin{tabular}{rl}
\toprule
Size & Top languages \\
\midrule
<%
for size, langs in zip(greedy_sizes, greedy_langs):
print size, '&',
print ', '.join("%s (%d)" % (l.replace('#', r'\#'), n) for l, n in langs)
print r'\\'
%>
\bottomrule
\end{tabular}
\end{center}
\end{table}