Skip to content

Commit

Permalink
initial codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Grover authored and Aditya Grover committed Jun 28, 2016
1 parent 3c81d87 commit 6b91f8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.pyc
9 changes: 7 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
'''
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
Knowledge Discovery and Data Mining (KDD), 2016
'''


import argparse
import numpy as np
import networkx as nx
import node2vec
from gensim.models import Word2Vec

def parse_args():
'''
Expand Down
16 changes: 11 additions & 5 deletions src/node2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
# for details

def alias_setup(probs):
K = len(probs)
q = np.zeros(K)
J = np.zeros(K, dtype=np.int)
'''
Compute utility lists for non-uniform sampling from discrete distributions.
'''
K = len(probs)
q = np.zeros(K)
J = np.zeros(K, dtype=np.int)

smaller = []
larger = []
larger = []
for kk, prob in enumerate(probs):
q[kk] = K*prob
if q[kk] < 1.0:
Expand All @@ -34,7 +37,10 @@ def alias_setup(probs):
return J, q

def alias_draw(J, q):
K = len(J)
'''
Draw sample from a non-uniform discrete distribution using alias sampling.
'''
K = len(J)

kk = int(np.floor(np.random.rand()*K))
if np.random.rand() < q[kk]:
Expand Down

0 comments on commit 6b91f8e

Please sign in to comment.