society 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Society
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require_relative 'fixtures/clustering/clusterer_fixtures.rb'
3
+
4
+ describe Society::Clusterer do
5
+
6
+ describe "#cluster" do
7
+ let(:clusterer) { Society::Clusterer.new }
8
+
9
+ it "detects clusters" do
10
+ clusters = clusterer.cluster(MCL::GRAPH_1).map(&:sort)
11
+ expected = MCL::CLUSTERS_1.map(&:sort)
12
+ expect(clusters).to match_array(expected)
13
+ end
14
+
15
+ context "with inflation parameter set to 1.7" do
16
+ let(:clusterer) { Society::Clusterer.new(inflation: 1.7) }
17
+
18
+ it "detects clusters at coarser granularity" do
19
+ clusters = clusterer.cluster(MCL::GRAPH_1).map(&:sort)
20
+ expected = MCL::CLUSTERS_1_I17.map(&:sort)
21
+ expect(clusters).to match_array(expected)
22
+ end
23
+ end
24
+
25
+ context "with inflation parameter set to 4.0" do
26
+ let(:clusterer) { Society::Clusterer.new(inflation: 4.0) }
27
+
28
+ it "detects clusters at finer granularity" do
29
+ clusters = clusterer.cluster(MCL::GRAPH_1).map(&:sort)
30
+ expected = MCL::CLUSTERS_1_I40.map(&:sort)
31
+ expect(clusters).to match_array(expected)
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+
@@ -0,0 +1,144 @@
1
+ # Reference results were calculated using the `minimcl` perl script from
2
+ # release 14-137 of the MCL-edge library. http://micans.org/mcl
3
+
4
+ require 'set'
5
+
6
+ module MCL
7
+
8
+ def self.graph_from_edges(path)
9
+ full_path = File.join(File.dirname(__FILE__), path)
10
+ nodes = Set.new
11
+ edges = []
12
+ edges_with_weights = /(\S+)\s+(\S+)\s+(\S+)/
13
+ edges_only = /(\S+)\s+(\S+)/
14
+ File.readlines(full_path).each do |line|
15
+ if data = line.match(edges_with_weights)
16
+ a,b,weight = data[1..-1]
17
+ # FIXME: disregarding weight for now -- include it once we have
18
+ # weights in Edges
19
+ edges << Society::Edge.new(from: a.to_i, to: b.to_i)
20
+ nodes << a << b
21
+ elsif data = line.match(edges_only)
22
+ a,b = data[1..-1]
23
+ edges << Society::Edge.new(from: a.to_i, to: b.to_i)
24
+ nodes << a << b
25
+ end
26
+ end
27
+ Society::ObjectGraph.new(nodes: nodes.to_a, edges: edges)
28
+ end
29
+
30
+ GRAPH_1 = graph_from_edges('edges_1.txt')
31
+
32
+ CLUSTERS_1 = [
33
+ [9, 10, 19, 24, 25, 26, 28, 29, 30, 39, 58, 68, 102, 189, 198, 200],
34
+ [46, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139],
35
+ [0, 1, 4, 11, 38, 49, 52, 59, 60, 61, 71, 125],
36
+ [109, 110, 144, 145, 146, 147, 148, 149],
37
+ [81, 121, 122, 184, 185, 188],
38
+ [12, 31, 32, 79, 91, 124],
39
+ [7, 47, 53, 54, 78, 82],
40
+ [33, 83, 96, 113, 119],
41
+ [17, 55, 56, 57, 65],
42
+ [13, 42, 115, 120],
43
+ [14, 15, 27, 190],
44
+ [43, 90, 99, 118],
45
+ [173, 175, 193],
46
+ [88, 116, 117],
47
+ [73, 143, 176],
48
+ [77, 114, 116],
49
+ [20, 69, 103],
50
+ [41, 44, 112],
51
+ [16, 97, 98],
52
+ [3, 23, 126],
53
+ [183, 186],
54
+ [100, 101],
55
+ [107, 108],
56
+ [70, 104],
57
+ [87, 106],
58
+ [86, 105],
59
+ [50, 140],
60
+ [67, 95],
61
+ [85, 94],
62
+ [8, 111],
63
+ [66, 92],
64
+ [2, 84],
65
+ [182],
66
+ [93]]
67
+
68
+ CLUSTERS_1_I17 = [
69
+ [8, 9, 10, 13, 14, 15, 17, 19, 20, 24, 25, 26, 27, 28, 29, 30, 39, 41, 42, 43, 44, 55, 56, 57, 58, 65, 68, 69, 93, 102, 103, 111, 112, 115, 120, 189, 190, 198, 200],
70
+ [46, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139],
71
+ [0, 1, 4, 11, 38, 49, 52, 59, 60, 61, 71, 125],
72
+ [33, 83, 90, 96, 99, 113, 118, 119],
73
+ [109, 110, 144, 145, 146, 147, 148, 149],
74
+ [2, 7, 47, 53, 54, 78, 82, 84],
75
+ [70, 86, 87, 104, 105, 106],
76
+ [81, 121, 122, 184, 185, 188],
77
+ [12, 31, 32, 79, 91, 124],
78
+ [73, 143, 173, 176],
79
+ [88, 116, 117],
80
+ [77, 114, 116],
81
+ [16, 97, 98],
82
+ [3, 23, 126],
83
+ [183, 186],
84
+ [100, 101],
85
+ [50, 140],
86
+ [175, 193],
87
+ [107, 108],
88
+ [66, 92],
89
+ [67, 95],
90
+ [85, 94],
91
+ [182]]
92
+
93
+ CLUSTERS_1_I40 = [
94
+ [46, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139],
95
+ [10, 28, 29, 30, 39, 58, 146, 198, 200],
96
+ [109, 110, 144, 145, 147, 148, 149],
97
+ [81, 121, 122, 184, 185, 188],
98
+ [7, 47, 53, 54, 78, 82],
99
+ [14, 15, 24, 27, 190],
100
+ [0, 4, 38, 60, 125],
101
+ [13, 42, 115, 120],
102
+ [31, 32, 91, 124],
103
+ [17, 55, 56, 65],
104
+ [73, 143, 176],
105
+ [20, 69, 103],
106
+ [41, 44, 112],
107
+ [33, 83, 113],
108
+ [3, 23, 126],
109
+ [16, 97, 98],
110
+ [175, 193],
111
+ [107, 108],
112
+ [183, 186],
113
+ [100, 101],
114
+ [70, 104],
115
+ [43, 118],
116
+ [68, 102],
117
+ [88, 117],
118
+ [19, 189],
119
+ [50, 140],
120
+ [86, 105],
121
+ [77, 114],
122
+ [87, 106],
123
+ [8, 111],
124
+ [67, 95],
125
+ [25, 26],
126
+ [85, 94],
127
+ [12, 79],
128
+ [11, 49],
129
+ [52, 71],
130
+ [66, 92],
131
+ [2, 84],
132
+ [1, 61],
133
+ [119],
134
+ [173],
135
+ [116],
136
+ [182],
137
+ [57],
138
+ [93],
139
+ [90],
140
+ [99],
141
+ [59],
142
+ [96],
143
+ [9]]
144
+ end
@@ -0,0 +1,322 @@
1
+ 0 38 1
2
+ 2 53 1
3
+ 3 53 1
4
+ 3 53 1
5
+ 3 13 1
6
+ 3 47 1
7
+ 7 53 1
8
+ 8 58 1
9
+ 8 44 1
10
+ 8 16 1
11
+ 8 53 1
12
+ 9 19 1
13
+ 9 50 1
14
+ 10 58 1
15
+ 13 8 1
16
+ 13 58 1
17
+ 13 3 1
18
+ 13 3 1
19
+ 13 14 1
20
+ 14 13 1
21
+ 15 31 1
22
+ 15 16 1
23
+ 15 27 1
24
+ 15 14 1
25
+ 15 50 1
26
+ 15 43 1
27
+ 16 15 1
28
+ 16 8 1
29
+ 17 58 1
30
+ 17 57 1
31
+ 17 55 1
32
+ 17 56 1
33
+ 19 58 1
34
+ 19 9 1
35
+ 24 58 1
36
+ 24 25 1
37
+ 24 28 1
38
+ 24 27 1
39
+ 25 58 1
40
+ 25 24 1
41
+ 25 26 1
42
+ 25 29 1
43
+ 26 25 1
44
+ 27 24 1
45
+ 27 15 1
46
+ 28 24 1
47
+ 28 29 1
48
+ 29 58 1
49
+ 29 28 1
50
+ 29 25 1
51
+ 30 58 1
52
+ 30 58 1
53
+ 31 15 1
54
+ 31 58 1
55
+ 38 0 1
56
+ 41 44 1
57
+ 41 42 1
58
+ 41 43 1
59
+ 41 14 1
60
+ 42 41 1
61
+ 42 58 1
62
+ 43 41 1
63
+ 43 15 1
64
+ 44 41 1
65
+ 44 8 1
66
+ 47 3 1
67
+ 47 53 1
68
+ 49 58 1
69
+ 49 11 1
70
+ 50 15 1
71
+ 50 9 1
72
+ 52 58 1
73
+ 53 8 1
74
+ 53 47 1
75
+ 53 2 1
76
+ 53 7 1
77
+ 55 56 1
78
+ 55 17 1
79
+ 55 9 1
80
+ 56 57 1
81
+ 56 55 1
82
+ 56 17 1
83
+ 57 56 1
84
+ 57 17 1
85
+ 57 58 1
86
+ 58 13 1
87
+ 58 8 1
88
+ 58 42 1
89
+ 58 25 1
90
+ 58 29 1
91
+ 58 24 1
92
+ 58 52 1
93
+ 58 31 1
94
+ 58 19 1
95
+ 58 30 1
96
+ 58 30 1
97
+ 58 10 1
98
+ 58 49 1
99
+ 14 15 1
100
+ 14 41 1
101
+ 8 41 1
102
+ 8 15 1
103
+ 9 58 1
104
+ 13 53 1
105
+ 13 15 1
106
+ 13 41 1
107
+ 15 8 1
108
+ 15 24 1
109
+ 15 13 1
110
+ 15 58 1
111
+ 15 41 1
112
+ 24 58 1
113
+ 25 15 1
114
+ 25 28 1
115
+ 28 58 1
116
+ 28 25 1
117
+ 41 8 1
118
+ 41 58 1
119
+ 41 15 1
120
+ 41 13 1
121
+ 57 55 1
122
+ 58 8 1
123
+ 58 24 1
124
+ 58 15 1
125
+ 58 9 1
126
+ 58 58 1
127
+ 58 58 1
128
+ 0 0 1
129
+ 0 4 1
130
+ 0 125 1
131
+ 0 38 1
132
+ 0 11 1
133
+ 3 126 1
134
+ 3 23 1
135
+ 3 47 1
136
+ 8 58 1
137
+ 8 53 1
138
+ 12 31 1
139
+ 12 31 1
140
+ 12 91 1
141
+ 12 96 1
142
+ 13 53 1
143
+ 13 58 1
144
+ 13 120 1
145
+ 13 115 1
146
+ 15 8 1
147
+ 15 15 1
148
+ 15 58 1
149
+ 17 58 1
150
+ 32 31 1
151
+ 32 31 1
152
+ 32 31 1
153
+ 39 58 1
154
+ 39 39 1
155
+ 41 112 1
156
+ 41 58 1
157
+ 41 8 1
158
+ 42 13 1
159
+ 42 3 1
160
+ 46 46 1
161
+ 46 46 1
162
+ 46 132 1
163
+ 46 46 1
164
+ 46 46 1
165
+ 46 46 1
166
+ 46 46 1
167
+ 47 46 1
168
+ 50 140 1
169
+ 52 52 1
170
+ 52 52 1
171
+ 52 58 1
172
+ 53 54 1
173
+ 53 82 1
174
+ 55 9 1
175
+ 56 57 1
176
+ 57 58 1
177
+ 58 49 1
178
+ 58 58 1
179
+ 59 0 1
180
+ 59 52 1
181
+ 59 0 1
182
+ 59 11 1
183
+ 59 0 1
184
+ 60 0 1
185
+ 61 1 1
186
+ 61 1 1
187
+ 61 11 1
188
+ 61 11 1
189
+ 61 58 1
190
+ 61 58 1
191
+ 61 0 1
192
+ 61 58 1
193
+ 61 11 1
194
+ 61 0 1
195
+ 61 0 1
196
+ 65 17 1
197
+ 66 93 1
198
+ 67 31 1
199
+ 68 58 1
200
+ 68 58 1
201
+ 68 9 1
202
+ 68 19 1
203
+ 69 57 1
204
+ 70 105 1
205
+ 71 52 1
206
+ 71 0 1
207
+ 71 52 1
208
+ 73 143 1
209
+ 77 116 1
210
+ 78 53 1
211
+ 79 12 1
212
+ 79 12 1
213
+ 81 188 1
214
+ 81 184 1
215
+ 81 121 1
216
+ 81 185 1
217
+ 83 33 1
218
+ 83 33 1
219
+ 84 2 1
220
+ 85 94 1
221
+ 85 93 1
222
+ 86 105 1
223
+ 87 106 1
224
+ 88 117 1
225
+ 88 116 1
226
+ 90 118 1
227
+ 90 99 1
228
+ 91 31 1
229
+ 92 66 1
230
+ 93 8 1
231
+ 93 33 1
232
+ 93 15 1
233
+ 93 41 1
234
+ 93 58 1
235
+ 93 13 1
236
+ 93 33 1
237
+ 95 67 1
238
+ 96 15 1
239
+ 96 83 1
240
+ 96 119 1
241
+ 96 108 1
242
+ 97 98 1
243
+ 98 16 1
244
+ 99 15 1
245
+ 99 83 1
246
+ 100 101 1
247
+ 102 17 1
248
+ 102 68 1
249
+ 103 17 1
250
+ 103 20 1
251
+ 103 69 1
252
+ 103 58 1
253
+ 104 70 1
254
+ 105 15 1
255
+ 105 58 1
256
+ 106 105 1
257
+ 107 108 1
258
+ 109 58 1
259
+ 110 109 1
260
+ 110 109 1
261
+ 110 58 1
262
+ 110 58 1
263
+ 110 109 1
264
+ 110 109 1
265
+ 110 109 1
266
+ 110 109 1
267
+ 110 148 1
268
+ 111 8 1
269
+ 112 41 1
270
+ 113 41 1
271
+ 113 83 1
272
+ 114 77 1
273
+ 115 13 1
274
+ 118 43 1
275
+ 118 119 1
276
+ 119 83 1
277
+ 120 13 1
278
+ 121 121 1
279
+ 122 8 1
280
+ 122 81 1
281
+ 124 31 1
282
+ 124 12 1
283
+ 124 12 1
284
+ 130 46 1
285
+ 131 46 1
286
+ 130 46 1
287
+ 133 46 1
288
+ 130 132 1
289
+ 134 46 1
290
+ 135 46 1
291
+ 134 46 1
292
+ 136 46 1
293
+ 137 46 1
294
+ 138 46 1
295
+ 137 46 1
296
+ 139 46 1
297
+ 143 143 1
298
+ 144 109 1
299
+ 145 109 1
300
+ 146 58 1
301
+ 146 58 1
302
+ 146 109 1
303
+ 147 109 1
304
+ 148 109 1
305
+ 149 109 1
306
+ 173 193 1
307
+ 175 193 1
308
+ 173 143 1
309
+ 176 143 1
310
+ 182 182 1
311
+ 182 182 1
312
+ 183 183 1
313
+ 183 183 1
314
+ 186 183 1
315
+ 186 183 1
316
+ 189 19 1
317
+ 190 15 1
318
+ 190 190 1
319
+ 198 58 1
320
+ 198 39 1
321
+ 200 58 1
322
+ 200 39 1