Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor changes to graph construction in read_graph function #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'''
Reference implementation of node2vec.
Reference implementation of node2vec.

Author: Aditya Grover

For more details, refer to the paper:
node2vec: Scalable Feature Learning for Networks
Aditya Grover and Jure Leskovec
Aditya Grover and Jure Leskovec
Knowledge Discovery and Data Mining (KDD), 2016
'''

Expand Down Expand Up @@ -67,15 +67,14 @@ def read_graph():
'''
Reads the input network in networkx.
'''
initial_graph = nx.DiGraph() if args.directed else nx.Graph()

if args.weighted:
G = nx.read_edgelist(args.input, nodetype=int, data=(('weight',float),), create_using=nx.DiGraph())
G = nx.read_edgelist(args.input, nodetype=int, data=(('weight',float),), create_using=initial_graph)
else:
G = nx.read_edgelist(args.input, nodetype=int, create_using=nx.DiGraph())
for edge in G.edges():
G[edge[0]][edge[1]]['weight'] = 1

if not args.directed:
G = G.to_undirected()
G = nx.read_edgelist(args.input, nodetype=int, create_using=initial_graph)
for u, v in G.edges_iter():
G[u][v]['weight'] = 1

return G

Expand All @@ -86,7 +85,7 @@ def learn_embeddings(walks):
walks = [map(str, walk) for walk in walks]
model = Word2Vec(walks, size=args.dimensions, window=args.window_size, min_count=0, sg=1, workers=args.workers, iter=args.iter)
model.save_word2vec_format(args.output)

return

def main(args):
Expand Down