While the DeepWalk algorithm uses fully random walks, the node2vec alternative, proposed in 2016, introduces two new parameters to control whether the random walk will be performed depth-first or breadth-first, traditionally named p and q:
- p or the return parameter: A higher p will force the random walk to return to the previous node more often, thereby creating more localized paths.
- q or the in-out parameter: In contrast to the preceding, q gives the probability that the random walk will visit an unknown node further away, hence increasing the distance covered by each walk.
So, compared to DeepWalk, node2vec offers more control on the local versus global structure of a graph.
You can generate node2vec-like random walks from the GDS using the inOut and return parameters:
MATCH (n:Node {id: 1})
CALL gds.alpha.randomWalk.stream({
nodeProjection: "*",
relationshipProjection: {
LINKED_TO: {
type: "LINK",
...