Skip to content

Commit db45ac6

Browse files
authored
Merge pull request #33 from /pull/32
Pull/32
2 parents 0f7275b + a01e08a commit db45ac6

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@
44
Python3 implementation of the node2vec algorithm Aditya Grover, Jure Leskovec and Vid Kocijan.
55
[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/)
66

7-
## Changes:
8-
9-
New in `0.3.0` (right now on version `0.3.1`):
10-
11-
Added support for big graphs which cannot be fit into memory during algorithm execution (causing OOM errors).
12-
13-
Thanks [`@pg2455`](https://github.com/pg2455) for the contribution of this feature.
14-
15-
167
## Installation
178

189
`pip install node2vec`

node2vec/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .node2vec import Node2Vec
22
from . import edges
33

4-
__version__ = '0.3.1'
4+
__version__ = '0.3.2'

node2vec/node2vec.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def _precompute_probabilities(self):
7272
"""
7373

7474
d_graph = self.d_graph
75-
first_travel_done = set()
7675

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

9291
unnormalized_weights = list()
93-
first_travel_weights = list()
9492
d_neighbors = list()
9593

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

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

117113
# Normalize
118114
unnormalized_weights = np.array(unnormalized_weights)
119115
d_graph[current_node][self.PROBABILITIES_KEY][
120116
source] = unnormalized_weights / unnormalized_weights.sum()
121117

122-
if current_node not in first_travel_done:
123-
unnormalized_weights = np.array(first_travel_weights)
124-
d_graph[current_node][self.FIRST_TRAVEL_KEY] = unnormalized_weights / unnormalized_weights.sum()
125-
first_travel_done.add(current_node)
126-
127118
# Save neighbors
128119
d_graph[current_node][self.NEIGHBORS_KEY] = d_neighbors
129120

121+
# Calculate first_travel weights for source
122+
first_travel_weights = []
123+
124+
for destination in self.graph.neighbors(source):
125+
first_travel_weights.append(self.graph[source][destination].get(self.weight_key, 1))
126+
127+
first_travel_weights = np.array(first_travel_weights)
128+
d_graph[source][self.FIRST_TRAVEL_KEY] = first_travel_weights / first_travel_weights.sum()
129+
130130
def _generate_walks(self) -> list:
131131
"""
132132
Generates the random walks which will be used as the skip-gram input.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
setup(
55
name='node2vec',
66
packages=['node2vec'],
7-
version='0.3.1',
7+
version='0.3.2',
88
description='Implementation of the node2vec algorithm.',
99
author='Elior Cohen',
1010
author_email='[email protected]',

0 commit comments

Comments
 (0)