-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
27 lines (23 loc) · 933 Bytes
/
utils.py
File metadata and controls
27 lines (23 loc) · 933 Bytes
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
import networkx as nx
import numpy as np
import warnings
# Suppress warnings
warnings.filterwarnings("ignore", category=RuntimeWarning)
def calculate_overlap(cycle1, cycle2):
"""Calculate the overlap (number of common edges) between two cycles."""
return len(set(cycle1).intersection(set(cycle2)))
def check_louvain_availability():
"""Check if python-louvain package is available."""
try:
import community.community_louvain as community_louvain
return True
except ImportError:
return False
def create_weighted_graph(original_graph, rho_star_map, min_weight=1e-6):
"""Create a new graph with edge weights from rho_star_map."""
G_weighted = nx.Graph()
for edge, rho_val in rho_star_map.items():
if rho_val > min_weight: # Add edges with significant weight
u, v = edge
G_weighted.add_edge(u, v, weight=rho_val)
return G_weighted