@@ -44,7 +44,7 @@ def setUp(self):
44
44
self .community = community
45
45
46
46
def test_init (self ):
47
- part = wm .Partition (self .graph )
47
+ part = wm .WeightedPartition (self .graph )
48
48
self .assertEqual (type (part .degrees ), type ({}))
49
49
npt .assert_array_almost_equal (part .total_edge_weight , 1500.5653444 )
50
50
# generated communities
@@ -53,14 +53,14 @@ def test_init(self):
53
53
54
54
def test_community_degree (self ):
55
55
## if no community, method will raise error
56
- part = wm .Partition (self .graph )
57
- part = wm .Partition (self .graph , self .community )
56
+ part = wm .WeightedPartition (self .graph )
57
+ part = wm .WeightedPartition (self .graph , self .community )
58
58
cdegree = part .community_degree ()
59
59
self .assertEqual (round (cdegree [0 ]), 1462.0 )
60
60
61
61
62
62
def test_set_community (self ):
63
- part = wm .Partition (self .graph , self .community )
63
+ part = wm .WeightedPartition (self .graph , self .community )
64
64
self .assertEqual (part .community , self .community )
65
65
with self .assertRaises (TypeError ):
66
66
# raise error if not list of sets
@@ -75,49 +75,49 @@ def test_set_community(self):
75
75
def test_allnodes_in_community (self ):
76
76
"""checks communities contain all nodes
77
77
with no repetition"""
78
- part = wm .Partition (self .graph )
78
+ part = wm .WeightedPartition (self .graph )
79
79
self .assertTrue (part ._allnodes_in_community (self .community ))
80
80
self .assertFalse (part ._allnodes_in_community ([self .community [0 ]]))
81
81
82
82
83
83
def test_get_node_community (self ):
84
- part = wm .Partition (self .graph , self .community )
84
+ part = wm .WeightedPartition (self .graph , self .community )
85
85
self .assertEqual (part .get_node_community (0 ), 0 )
86
86
self .assertEqual (part .get_node_community (self .graph .nodes ()[- 1 ]),1 )
87
87
with self .assertRaises (ValueError ):
88
88
part .get_node_community (- 1 )
89
- part = wm .Partition (self .graph )
89
+ part = wm .WeightedPartition (self .graph )
90
90
self .assertEqual (part .get_node_community (0 ), 0 )
91
91
92
92
93
93
def test_modularity ():
94
94
graph , comm = get_test_data ()
95
- part = wm .Partition (graph , comm )
95
+ part = wm .WeightedPartition (graph , comm )
96
96
npt .assert_almost_equal (wm .modularity (part ), 0.0555463 )
97
97
98
98
99
99
def test_total_links ():
100
100
graph , community = get_test_data ()
101
- part = wm .Partition (graph ) # one comm per node
101
+ part = wm .WeightedPartition (graph ) # one comm per node
102
102
## summ of all links in or out of community
103
103
## since one per scommunity, just weighted degree of each node
104
104
tot_per_comm = wm .total_links (part )
105
105
degw = graph .degree (weight = 'weight' ).values ()
106
106
npt .assert_equal (tot_per_comm , degw )
107
107
## This isnt true of we have communities with multiple nodes
108
- part_2comm = wm .Partition (graph , community )
108
+ part_2comm = wm .WeightedPartition (graph , community )
109
109
npt .assert_equal (part_2comm == degw , False )
110
110
111
111
def test_internal_links ():
112
112
graph , community = get_test_data ()
113
- part = wm .Partition (graph ) # one comm per node
113
+ part = wm .WeightedPartition (graph ) # one comm per node
114
114
weights = wm .internal_links (part )
115
115
## this inlcudes seld links so
116
116
117
117
118
118
def test_dnodecom ():
119
119
graph , community = get_test_data ()
120
- part = wm .Partition (graph ) # one comm per node
120
+ part = wm .WeightedPartition (graph ) # one comm per node
121
121
node = 0
122
122
node2comm_weights = wm .dnodecom (node , part )
123
123
# self loops not added to weight
@@ -127,18 +127,18 @@ def test_dnodecom():
127
127
neighbor = 1
128
128
expected = graph [node ][neighbor ]['weight' ]
129
129
npt .assert_equal (node2comm_weights [neighbor ],expected )
130
- part = wm .Partition (graph , community )
130
+ part = wm .WeightedPartition (graph , community )
131
131
node2comm_weights = wm .dnodecom (node , part )
132
132
npt .assert_equal (len (node2comm_weights ), 2 )
133
133
134
134
def test_meta_graph ():
135
135
graph , community = get_test_data ()
136
- part = wm .Partition (graph )
136
+ part = wm .WeightedPartition (graph )
137
137
metagraph ,_ = wm .meta_graph (part )
138
138
## each node is a comm, so no change to metagraph
139
139
npt .assert_equal (metagraph .nodes (), graph .nodes ())
140
140
## two communitties
141
- part = wm .Partition (graph , community )
141
+ part = wm .WeightedPartition (graph , community )
142
142
metagraph ,mapping = wm .meta_graph (part )
143
143
npt .assert_equal (metagraph .nodes (), [0 ,1 ])
144
144
npt .assert_equal (metagraph .edges (), [(0 ,0 ),(0 ,1 ), (1 ,1 )])
@@ -151,24 +151,24 @@ def test_meta_graph():
151
151
152
152
def test_communities_without_node ():
153
153
graph , community = get_test_data ()
154
- part = wm .Partition (graph ) # one comm per node
154
+ part = wm .WeightedPartition (graph ) # one comm per node
155
155
node = 0
156
156
updated_comm = wm ._communities_without_node (part , node )
157
157
npt .assert_equal (updated_comm [0 ], set ([]))
158
- part = wm .Partition (graph , community )
158
+ part = wm .WeightedPartition (graph , community )
159
159
updated_comm = wm ._communities_without_node (part , node )
160
160
## make sure we dont break community from original partition
161
161
npt .assert_equal (part .community , community )
162
162
npt .assert_equal (0 not in updated_comm [0 ], True )
163
163
164
164
def test_community_nodes_alledgesw ():
165
165
graph , community = get_test_data ()
166
- part = wm .Partition (graph , community )
166
+ part = wm .WeightedPartition (graph , community )
167
167
node = 0
168
168
weights = wm ._community_nodes_alledgesw (part , node )
169
169
npt .assert_almost_equal (weights [0 ], 1424.0220362 )
170
170
## test with possible empty node set
171
- part = wm .Partition (graph )
171
+ part = wm .WeightedPartition (graph )
172
172
weights = wm ._community_nodes_alledgesw (part , node )
173
173
npt .assert_equal (weights [0 ], 0 )
174
174
# other communities are made up of just one node
@@ -179,7 +179,7 @@ def test_community_nodes_alledgesw():
179
179
180
180
def test_node_degree ():
181
181
graph , community = get_test_data ()
182
- part = wm .Partition (graph ) # one comm per node
182
+ part = wm .WeightedPartition (graph ) # one comm per node
183
183
node = 0
184
184
res = wm .node_degree (graph , node )
185
185
npt .assert_almost_equal (res , 37.94151675 )
@@ -194,7 +194,7 @@ def test_combine():
194
194
195
195
def test_calc_delta_modularity ():
196
196
graph , community = get_test_data ()
197
- part = wm .Partition (graph ) # one comm per node
197
+ part = wm .WeightedPartition (graph ) # one comm per node
198
198
node = 0
199
199
change = wm ._calc_delta_modularity (node , part )
200
200
npt .assert_equal (len (change ), len (part .community ))
@@ -208,7 +208,7 @@ def test_calc_delta_modularity():
208
208
209
209
def test_move_node ():
210
210
graph , community = get_test_data ()
211
- part = wm .Partition (graph ) # one comm per node
211
+ part = wm .WeightedPartition (graph ) # one comm per node
212
212
#move first node to second community
213
213
node = 0
214
214
comm = 1
0 commit comments