Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/community_louvair' into communit…
Browse files Browse the repository at this point in the history
…y_louvair
  • Loading branch information
saibalmars committed Aug 22, 2023
2 parents 644f677 + c69ff42 commit e7cf46a
Show file tree
Hide file tree
Showing 3 changed files with 365 additions and 190 deletions.
4 changes: 2 additions & 2 deletions GraphRicciCurvature/OllivierRicci.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@


import heapq
import importlib
import math
import multiprocessing as mp
import time
from functools import lru_cache
from importlib import util

import networkit as nk
import networkx as nx
Expand Down Expand Up @@ -690,7 +690,7 @@ def __init__(self, G: nx.Graph, weight="weight", alpha=0.5, method="OTDSinkhornM
self.lengths = {} # all pair shortest path dictionary
self.densities = {} # density distribution dictionary

assert importlib.util.find_spec("ot"), \
assert util.find_spec("ot"), \
"Package POT: Python Optimal Transport is required for Sinkhorn distance."

if not nx.get_edge_attributes(self.G, weight):
Expand Down
16 changes: 11 additions & 5 deletions my_surgery.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from importlib import util

import community as community_louvain
import networkx as nx
import numpy as np
import importlib
import community as community_louvain
import matplotlib.pyplot as plt


def ARI(G, clustering, clustering_label="club"):
Expand All @@ -24,10 +24,10 @@ def ARI(G, clustering, clustering_label="club"):
Adjust Rand Index for predicted community.
"""

if importlib.util.find_spec("sklearn") is not None:
if util.find_spec("sklearn") is not None:
from sklearn import preprocessing, metrics
else:
print("scikit-learn not installed...")
print("scikit-learn not installed, skipped...")
return -1

complex_list = nx.get_node_attributes(G, clustering_label)
Expand Down Expand Up @@ -107,6 +107,12 @@ def check_accuracy(G_origin, weight="weight", clustering_label="value", plot_cut
To plot the good guessed cut or not.
"""
if util.find_spec("matplotlib") is not None:
import matplotlib.pyplot as plt
else:
print("matplotlib not installed, skipped to show the cut graph...")
return -1

G = G_origin.copy()
modularity, ari = [], []
maxw = max(nx.get_edge_attributes(G, weight).values())
Expand Down
Loading

0 comments on commit e7cf46a

Please sign in to comment.