cugraph.biased_random_walks#

cugraph.biased_random_walks(G: Graph, start_vertices: int | list | Series | DataFrame = None, max_depth: int = None, random_state: int = None) Tuple[Series, Series, None | int | Series][source]#

Compute biased random walks for each nodes in ‘start_vertices’. Vertices with no outgoing edges will be padded with -1 and the corresponding edge weights with 0.0.

Parameters:
GcuGraph.Graph

The graph can be either directed or undirected.

start_verticesint or list or cudf.Series or cudf.DataFrame

A single node or a list or a cudf.Series of nodes from which to run the random walks. In case of multi-column vertices it should be a cudf.DataFrame

max_depthint

The maximum depth of the random walks

The max depth is relative to the number of edges hence the vertex_paths size is max_depth + 1. For instance, a ‘max_depth’ of 2 with only one seed will result in a vertex_path of size 3.

random_state: int, optional

Random seed to use when making sampling calls.

Returns:
vertex_pathscudf.Series or cudf.DataFrame

Series containing the vertices of edges/paths in the random walk.

edge_weight_paths: cudf.Series

Series containing the edge weights of edges represented by the returned vertex_paths

and
max_path_lengthint

The maximum path length.

Examples

>>> from cugraph.datasets import karate
>>> M = karate.get_edgelist(download=True)
>>> G = karate.get_graph()
>>> start_vertices = [0, 1]
>>> paths, weights, max_length = cugraph.biased_random_walks(
...            G, start_vertices, 3, random_state=2)
>>> paths.to_cupy()
array([ 0,  2,  8, 32,  1, 17,  0,  2], dtype=int32)
>>> weights.to_cupy()
array([1., 1., 1., 1., 1., 1.], dtype=float32)
>>> max_length
3