Random walk with restarts sampling

Directed Directed trait. The algorithm is well-defined on a directed graph. Directed Directed trait. The algorithm ignores the direction of the graph. Directed Directed trait. The algorithm does not run on a directed graph. Undirected Undirected trait. The algorithm is well-defined on an undirected graph. Undirected Undirected trait. The algorithm ignores the undirectedness of the graph. Heterogeneous nodes Heterogeneous nodes fully supported. The algorithm has the ability to distinguish between nodes of different types. Heterogeneous nodes Heterogeneous nodes allowed. The algorithm treats all selected nodes similarly regardless of their label. Heterogeneous relationships Heterogeneous relationships fully supported. The algorithm has the ability to distinguish between relationships of different types. Heterogeneous relationships Heterogeneous relationships allowed. The algorithm treats all selected relationships similarly regardless of their type. Weighted relationships Weighted trait. The algorithm supports a relationship property to be used as weight, specified via the relationshipWeightProperty configuration parameter. Weighted relationships Weighted trait. The algorithm treats each relationship as equally important, discarding the value of any relationship weight.

Random walk with restarts sampling is featured in the end-to-end example Jupyter notebooks:

Introduction

Sometimes it may be useful to have a smaller but structurally representative sample of a given graph. For instance, such a sample could be used to train an inductive embedding algorithm (such as a graph neural network, like GraphSAGE). The training would then be faster than when training on the entire graph, and then the trained model could still be used to predict embeddings on the entire graph.

Random walk with restarts (RWR) samples the graph by taking random walks from a set of start nodes (see the startNodes parameter below). On each step of a random walk, there is some probability (see the restartProbability parameter below) that the walk stops, and a new walk from one of the start nodes starts instead (i.e. the walk restarts). Each node visited on these walks will be part of the sampled subgraph. The algorithm stops walking when the requested number of nodes have been visited (see the samplingRatio parameter below). The relationships of the sampled subgraph are those induced by the sampled nodes (i.e. the relationships of the original graph that connect nodes that have been sampled).

If at some point it’s very unlikely to visit new nodes by random walking from the current set of start nodes (possibly due to the original graph being disconnected), the algorithm will lazily expand the pool of start nodes one at a time by picking nodes uniformly at random from the original graph.

It was shown by Leskovec et al. in the paper "Sampling from Large Graphs" that RWR is a very good sampling algorithm for preserving structural features of the original graph that was sampled from. Additionally, RWR has been successfully used throughout the literature to sample batches for graph neural network (GNN) training.

Random walk with restarts is sometimes also referred to as rooted or personalized random walk.

Relationship weights

If the graph is weighted and relationshipWeightProperty is specified, the random walks are weighted. This means that the probability of walking along a relationship is the weight of that relationship divided by the sum of weights of outgoing relationships from the current node.

Node label stratification

In some cases it may be desirable for the sampled graph to preserve the distribution of node labels of the original graph. To enable such stratification, one can set nodeLabelStratification to true in the algorithm configuration. The stratified sampling is performed by only adding a node to the sampled graph if more nodes of that node’s particular set of labels are needed to uphold the node label distribution of the original graph.

By default, the algorithm treats all nodes in the same way no matter how they are labeled and makes no special effort to preserve the node label distribution of the original graph. Please note that the stratified sampling might be a bit slower since it has restrictions on the types of nodes it can add to the sampled graph when crawling it.

At this time there is no support for relationship type stratification.