From 516885eb9309c41993195580a9948cccb84eaeba Mon Sep 17 00:00:00 2001 From: Aleksandar Despotovski Date: Fri, 7 Feb 2020 15:50:29 +0100 Subject: [PATCH 1/3] Fix computing first-travel weights for nodes without incoming edges in directed graphs --- node2vec/node2vec.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/node2vec/node2vec.py b/node2vec/node2vec.py index 7ad6d20..e2d611e 100644 --- a/node2vec/node2vec.py +++ b/node2vec/node2vec.py @@ -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') @@ -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 @@ -110,8 +108,6 @@ 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 @@ -119,14 +115,18 @@ def _precompute_probabilities(self): 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. From d4fe5b996561219f01bf536c4351009ef82a4327 Mon Sep 17 00:00:00 2001 From: Elior Cohen Date: Sat, 8 Feb 2020 16:58:04 +0200 Subject: [PATCH 2/3] Update version and accept @despotovski01 fix --- README.md | 9 --------- node2vec/__init__.py | 2 +- setup.py | 3 +-- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index dee6cc4..67ae9fa 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/node2vec/__init__.py b/node2vec/__init__.py index 73b6163..4c4f3a5 100644 --- a/node2vec/__init__.py +++ b/node2vec/__init__.py @@ -1,4 +1,4 @@ from .node2vec import Node2Vec from . import edges -__version__ = '0.3.1' \ No newline at end of file +__version__ = '0.3.2' \ No newline at end of file diff --git a/setup.py b/setup.py index e54883b..1e5f26a 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,9 @@ from distutils.core import setup -import setuptools setup( name='node2vec', packages=['node2vec'], - version='0.3.1', + version='0.3.2', description='Implementation of the node2vec algorithm.', author='Elior Cohen', author_email='elior.cohen.p@gmail.com', From a01e08aca85adc87195989765fcd2e1de2654fc5 Mon Sep 17 00:00:00 2001 From: Elior Cohen Date: Sat, 8 Feb 2020 17:00:17 +0200 Subject: [PATCH 3/3] Add setuptools --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 1e5f26a..c3fa2b6 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ from distutils.core import setup +import setuptools setup( name='node2vec',