From 948a5f22e21dfc5b191cd0359a9701ae64ca8ade Mon Sep 17 00:00:00 2001 From: Louis Abraham Date: Mon, 22 Jun 2020 01:56:55 +0200 Subject: [PATCH] fix second node of weighted walk --- fastnode2vec/graph.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastnode2vec/graph.py b/fastnode2vec/graph.py index 3bb3d8b..1cbd03f 100644 --- a/fastnode2vec/graph.py +++ b/fastnode2vec/graph.py @@ -69,7 +69,9 @@ def _random_walk_weighted(indptr, indices, data, walk_length, p, q, t): walk = np.empty(walk_length, dtype=indices.dtype) walk[0] = t - walk[1] = np.random.choice(_neighbors(indptr, indices, t)) + walk[1] = _neighbors(indptr, indices, t)[ + np.searchsorted(_neighbors(indptr, data, t), np.random.rand()) + ] for j in range(2, walk_length): neighbors = _neighbors(indptr, indices, walk[j - 1]) neighbors_p = _neighbors(indptr, data, walk[j - 1])