-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode2vec.py
executable file
·70 lines (58 loc) · 3.21 KB
/
Node2vec.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pickle as pk
import networkx as nx
from pecanpy.graph import AdjlstGraph
from pecanpy import pecanpy as node2vec
filtered_weighted_exp_graph_significant = nx.read_weighted_edgelist("backbone_exp_graph_significant_weighted.edgelist")
filtered_unweighted_exp_graph_significant=nx.Graph()
for e in filtered_weighted_exp_graph_significant.edges():
filtered_unweighted_exp_graph_significant.add_edge(*e)
g = AdjlstGraph()
for e in list(filtered_weighted_exp_graph_significant.edges()):
weight = filtered_weighted_exp_graph_significant[e[0]][e[1]]["weight"]
g.add_edge(e[0],e[1],weight)
g.save("filtered_weighted_exp_graph_significant_new.edg")
g = node2vec.PreComp(p=1, q=1, workers=20, verbose=True,extend=True)
g.read_edg("filtered_weighted_exp_graph_significant_new.edg", weighted=True, directed=False)
g.preprocess_transition_probs()
filtered_weighted_emd = g.embed(dim=128,num_walks=200,walk_length=50)
#Let's write the results
with open('filtered_weighted_emd.pickle', 'wb') as handle:
pk.dump(filtered_weighted_emd, handle, protocol=pk.HIGHEST_PROTOCOL)
g = AdjlstGraph()
for e in list(filtered_unweighted_exp_graph_significant.edges()):
g.add_edge(e[0],e[1])
g.save("filtered_unweighted_exp_graph_significant_new.edg")
g = node2vec.PreComp(p=1, q=1, workers=20, verbose=True,extend=True)
g.read_edg("filtered_unweighted_exp_graph_significant_new.edg", weighted=False, directed=False)
g.preprocess_transition_probs()
filtered_unweighted_emd = g.embed(dim=128,num_walks=200,walk_length=50)
#Let's write the results
with open('filtered_unweighted_emd.pickle', 'wb') as handle:
pk.dump(filtered_unweighted_emd, handle, protocol=pk.HIGHEST_PROTOCOL)
unfiltered_weighted_exp_graph_significant = nx.read_weighted_edgelist("unfiltered_weighted_exp_graph_significant.edgelist")
unfiltered_unweighted_exp_graph_significant=nx.Graph()
for e in unfiltered_weighted_exp_graph_significant.edges():
unfiltered_unweighted_exp_graph_significant.add_edge(*e)
g = AdjlstGraph()
for e in list(unfiltered_unweighted_exp_graph_significant.edges()):
g.add_edge(e[0],e[1])
g.save("unfiltered_unweighted_exp_graph_significant_new.edg")
g = node2vec.PreComp(p=1, q=1, workers=20, verbose=False,extend=True)
g.read_edg("unfiltered_unweighted_exp_graph_significant_new.edg", weighted=False, directed=False)
g.preprocess_transition_probs()
unfiltered_unweighted_emd = g.embed(dim=128,num_walks=200,walk_length=50)
#Let's write the results
with open('unfiltered_unweighted_emd.pickle', 'wb') as handle:
pk.dump(unfiltered_unweighted_emd, handle, protocol=pk.HIGHEST_PROTOCOL)
g = AdjlstGraph()
for e in list(unfiltered_weighted_exp_graph_significant.edges()):
weight = unfiltered_weighted_exp_graph_significant[e[0]][e[1]]["weight"]
g.add_edge(e[0],e[1],weight)
g.save("unfiltered_weighted_exp_graph_significant_new.edg")
g = node2vec.PreComp(p=1, q=1, workers=20, verbose=False,extend=True)
g.read_edg("unfiltered_weighted_exp_graph_significant_new.edg", weighted=True, directed=False)
g.preprocess_transition_probs()
unfiltered_weighted_emd = g.embed(dim=128,num_walks=200,walk_length=50)
#Let's write the results
with open('unfiltered_weighted_emd.pickle', 'wb') as handle:
pk.dump(unfiltered_weighted_emd, handle, protocol=pk.HIGHEST_PROTOCOL)