Skip to content

Commit 2ad98d7

Browse files
authored
Merge pull request #117 from TheSignPainter/master
Fixed the violation of nodes ordering
2 parents 073b13a + 33eae18 commit 2ad98d7

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

cdt/causality/graph/GES.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ def orient_undirected_graph(self, data, graph):
137137
self.arguments['{VERBOSE}'] = str(self.verbose).upper()
138138
self.arguments['{SCORE}'] = self.scores[self.score]
139139

140-
fe = DataFrame(nx.adj_matrix(graph, weight=None).todense())
140+
fe = DataFrame(nx.adjacency_matrix(graph, nodelist=sorted(graph.nodes()), weight=None).todense())
141141
fg = DataFrame(1 - fe.values)
142142

143143
results = self._run_ges(data, fixedGaps=fg, verbose=self.verbose)
144144

145145
return nx.relabel_nodes(nx.DiGraph(results),
146-
{idx: i for idx, i in enumerate(data.columns)})
146+
{idx: i for idx, i in enumerate(sorted(data.columns))})
147147

148148
def orient_directed_graph(self, data, graph):
149149
"""Run GES on a directed graph.

cdt/causality/graph/GIES.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ def orient_undirected_graph(self, data, graph):
135135
self.arguments['{VERBOSE}'] = str(self.verbose).upper()
136136
self.arguments['{SCORE}'] = self.scores[self.score]
137137

138-
fe = DataFrame(nx.adj_matrix(graph, weight=None).todense())
138+
fe = DataFrame(nx.adjacency_matrix(graph, nodelist=sorted(graph.nodes()), weight=None).todense())
139139
fg = DataFrame(1 - fe.values)
140140

141141
results = self._run_gies(data, fixedGaps=fg, verbose=self.verbose)
142142

143143
return nx.relabel_nodes(nx.DiGraph(results),
144-
{idx: i for idx, i in enumerate(data.columns)})
144+
{idx: i for idx, i in enumerate(sorted(data.columns))})
145145

146146
def orient_directed_graph(self, data, graph):
147147
"""Run GIES on a directed_graph.

cdt/causality/graph/PC.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ def orient_undirected_graph(self, data, graph, **kwargs):
232232
self.arguments['{NJOBS}'] = str(self.njobs)
233233
self.arguments['{VERBOSE}'] = str(self.verbose).upper()
234234

235-
fe = DataFrame(nx.adj_matrix(graph, weight=None).todense())
235+
fe = DataFrame(nx.adjacency_matrix(graph, nodelist=sorted(graph.nodes()), weight=None).todense())
236236
fg = DataFrame(1 - fe.values)
237237

238238
results = self._run_pc(data, fixedEdges=fe, fixedGaps=fg, verbose=self.verbose)
239239

240240
return nx.relabel_nodes(nx.DiGraph(results),
241-
{idx: i for idx, i in enumerate(data.columns)})
241+
{idx: i for idx, i in enumerate(sorted(data.columns))})
242242

243243
def orient_directed_graph(self, data, graph, *args, **kwargs):
244244
"""Run PC on a directed_graph (Only takes account of the skeleton of

cdt/causality/graph/SAMv1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def run_SAM(df_data, skeleton=None, device=None, **kwargs):
210210
# Get the list of indexes to ignore
211211
if skeleton is not None:
212212
zero_components = [[] for i in range(cols)]
213-
skel = nx.adj_matrix(skeleton, weight=None)
213+
skel = nx.adjacency_matrix(skeleton, weight=None, nodelist=sorted(skeleton.nodes()))
214214
for i, j in zip(*((1-skel).nonzero())):
215215
zero_components[j].append(i)
216216
else:
@@ -427,7 +427,7 @@ def predict(self, data, graph=None,
427427
W /= self.nruns
428428
return nx.relabel_nodes(nx.DiGraph(W),
429429
{idx: i for idx,
430-
i in enumerate(data.columns)})
430+
i in enumerate(sorted(data.columns))})
431431

432432
def orient_directed_graph(self, *args, **kwargs):
433433
"""Orient a (partially directed) graph."""

0 commit comments

Comments
 (0)