Skip to content

Commit

Permalink
edit demo
Browse files Browse the repository at this point in the history
  • Loading branch information
peetal committed Mar 29, 2024
1 parent ddcd85d commit 1783405
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 54 deletions.
3 changes: 2 additions & 1 deletion bgfc_kit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
construct_graphs,
compute_threshold,
construct_threshold_binary_graphs,
participation_coefficient
participation_coefficient,
compute_network_pc
)
31 changes: 31 additions & 0 deletions bgfc_kit/bgfc_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,34 @@ def participation_coefficient(G, module_partition):
pc_dict[v] = 1 - ((float(wm_degree) / float(degree))**2)

return pc_dict

def compute_network_pc(pc, partition):
'''
This function takes in the PC for each parcel, then compute the PC for each network.
Parameters
----------
PC:
A (subject-level) dict with 200 items, one for each parcel
partition:
A dictionary mapping each community name to a list of nodes in G
Returns
-------
network_pc:
PC measure for each network included in the input partition list.
'''
# get network structure
partition_reverse = {}
for k, v in partition.items():
for p in v:
partition_reverse[str(p)] = k

# compute PC for each network
network_pc = defaultdict(list)
for k, v in pc.items():
network_pc[partition_reverse[k]].append(v)
for k, v in network_pc.items():
network_pc[k] = np.mean(v)

return list(network_pc.values())
Loading

0 comments on commit 1783405

Please sign in to comment.