Skip to content

Commit 3943ba8

Browse files
author
CindeeM
committed
RF: changed total_weights to degree_by_community for clarity
1 parent e662510 commit 3943ba8

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

brainx/tests/test_weighted_modularity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ def test_modularity(self):
109109
npt.assert_almost_equal(part.modularity(), 0.0555463)
110110

111111

112-
def test_total_links(self):
112+
def test_degree_by_community(self):
113113
part = wm.WeightedPartition(self.graph) # one comm per node
114114
## summ of all links in or out of communities
115115
## since one per scommunity, just weighted degree of each node
116-
tot_per_comm = part.total_links()
116+
tot_per_comm = part.degree_by_community()
117117
degw = self.graph.degree(weight='weight').values()
118118
self.assertEqual(tot_per_comm, degw)
119119
## This isnt true of we have communities with multiple nodes

brainx/weighted_modularity.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ def node_degree_by_community(self, node):
116116
return comm_weights
117117

118118

119-
def total_links(self):
120-
""" sum of all links inside or outside community
121-
no nodes are missing"""
119+
def degree_by_community(self):
120+
""" sum of all edges within or between communities
121+
for each community
122+
Returns
123+
-------
124+
weights : list
125+
list is size of total number of communities"""
122126
comm = self.communities
123127
weights = [0] * len(comm)
124128
all_degree_weights = self.graph.degree(weight='weight')
@@ -173,7 +177,7 @@ def modularity(self):
173177

174178
m2 = self.total_edge_weight
175179
internal_connect = np.array(self.internal_links())
176-
total = np.array(self.total_links())
180+
total = np.array(self.degree_by_community())
177181
return np.sum(internal_connect/m2 - (total/(2*m2))**2)
178182

179183

0 commit comments

Comments
 (0)