Skip to content

Commit

Permalink
Merge pull request #33 from /pull/32
Browse files Browse the repository at this point in the history
Pull/32
  • Loading branch information
eliorc authored Feb 8, 2020
2 parents 0f7275b + a01e08a commit db45ac6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
Python3 implementation of the node2vec algorithm Aditya Grover, Jure Leskovec and Vid Kocijan.
[node2vec: Scalable Feature Learning for Networks. A. Grover, J. Leskovec. ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD), 2016.](https://snap.stanford.edu/node2vec/)

## Changes:

New in `0.3.0` (right now on version `0.3.1`):

Added support for big graphs which cannot be fit into memory during algorithm execution (causing OOM errors).

Thanks [`@pg2455`](https://github.com/pg2455) for the contribution of this feature.


## Installation

`pip install node2vec`
Expand Down
2 changes: 1 addition & 1 deletion node2vec/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .node2vec import Node2Vec
from . import edges

__version__ = '0.3.1'
__version__ = '0.3.2'
18 changes: 9 additions & 9 deletions node2vec/node2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def _precompute_probabilities(self):
"""

d_graph = self.d_graph
first_travel_done = set()

nodes_generator = self.graph.nodes() if self.quiet \
else tqdm(self.graph.nodes(), desc='Computing transition probabilities')
Expand All @@ -90,7 +89,6 @@ def _precompute_probabilities(self):
d_graph[current_node][self.PROBABILITIES_KEY] = dict()

unnormalized_weights = list()
first_travel_weights = list()
d_neighbors = list()

# Calculate unnormalized weights
Expand All @@ -110,23 +108,25 @@ def _precompute_probabilities(self):

# Assign the unnormalized sampling strategy weight, normalize during random walk
unnormalized_weights.append(ss_weight)
if current_node not in first_travel_done:
first_travel_weights.append(self.graph[current_node][destination].get(self.weight_key, 1))
d_neighbors.append(destination)

# Normalize
unnormalized_weights = np.array(unnormalized_weights)
d_graph[current_node][self.PROBABILITIES_KEY][
source] = unnormalized_weights / unnormalized_weights.sum()

if current_node not in first_travel_done:
unnormalized_weights = np.array(first_travel_weights)
d_graph[current_node][self.FIRST_TRAVEL_KEY] = unnormalized_weights / unnormalized_weights.sum()
first_travel_done.add(current_node)

# Save neighbors
d_graph[current_node][self.NEIGHBORS_KEY] = d_neighbors

# Calculate first_travel weights for source
first_travel_weights = []

for destination in self.graph.neighbors(source):
first_travel_weights.append(self.graph[source][destination].get(self.weight_key, 1))

first_travel_weights = np.array(first_travel_weights)
d_graph[source][self.FIRST_TRAVEL_KEY] = first_travel_weights / first_travel_weights.sum()

def _generate_walks(self) -> list:
"""
Generates the random walks which will be used as the skip-gram input.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
name='node2vec',
packages=['node2vec'],
version='0.3.1',
version='0.3.2',
description='Implementation of the node2vec algorithm.',
author='Elior Cohen',
author_email='[email protected]',
Expand Down

0 comments on commit db45ac6

Please sign in to comment.