Skip to content

Commit

Permalink
🐛 fix some open issues on algorithm implementation/inputs specification
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed Jun 8, 2023
1 parent 7531530 commit eec7e5a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions cdlib/algorithms/attribute_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ def eva(
g = convert_graph_formats(g_original, nx.Graph)
nx.set_node_attributes(g, labels)

mapping = dict(zip(g, range(0, len(g))))
rev_map = {v: k for k, v in mapping.items()}
relabel_g = nx.relabel_nodes(g, mapping)

coms, coms_labels = Eva.eva_best_partition(
g, weight=weight, resolution=resolution, alpha=alpha
relabel_g, weight=weight, resolution=resolution, alpha=alpha
)

# Reshaping the results
coms_to_node = defaultdict(list)
for n, c in coms.items():
coms_to_node[c].append(n)
coms_to_node[c].append(rev_map[n])

coms_eva = [list(c) for c in coms_to_node.values()]
return AttrNodeClustering(
Expand Down
2 changes: 1 addition & 1 deletion cdlib/algorithms/bipartite_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def bimlpa(g_original: object, theta: float = 0.3, lambd: int = 7) -> BiNodeClus
Yes No No Yes
========== ======== ======== =========
:param g_original: a networkx/igraph object
:param g_original: a networkx/igraph object (instance of igraph.Graph or nx.Graph).
:param theta: Label weights threshold. Default 0.3.
:param lambd: The max number of labels. Default 7.
:return: BiNodeClustering object
Expand Down
4 changes: 2 additions & 2 deletions cdlib/algorithms/internal/em.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def e_step(self, q):
q[i].append(x)
norm += x
for g in range(self.k):
q[i][g] /= norm
q[i][g] /= (norm + 1e-10) # tolerance adjustment

def m_step(self, q):
for g in range(self.k):
Expand All @@ -47,7 +47,7 @@ def m_step(self, q):

def execute(self):
# initial parameters
X = [1.0 + random.random() for i in range(self.k)]
X = [1.0 + random.random() for _ in range(self.k)]
norm = sum(X)
self.pi = [x / norm for x in X]

Expand Down
1 change: 1 addition & 0 deletions cdlib/test/test_attributeclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_eva(self):
l1 = ["one", "two", "three", "four"]
l2 = ["A", "B", "C"]
g = nx.barabasi_albert_graph(100, 5)

labels = dict()

for node in g.nodes():
Expand Down

0 comments on commit eec7e5a

Please sign in to comment.