cugraph.random_walks#

cugraph.random_walks(G: Union[Graph, networkx.Graph], random_walks_type: str = 'uniform', start_vertices: Union[int, list, Series, DataFrame] = None, max_depth: int = None, use_padding: bool = False, legacy_result_type: bool = True) Tuple[Series, Series, Union[None, int, Series]][source]#

Compute random walks for each nodes in ‘start_vertices’ and returns either a padded or a coalesced result. For the padded case, vertices with no outgoing edges will be padded with -1.

When ‘use_padding’ is ‘False’, ‘random_walks’ returns a coalesced result which is a compressed version of the padded one. In the padded form, sources with no out_going edges are padded with -1s in the ‘vertex_paths’ array and their corresponding edges(‘edge_weight_paths’) with 0.0s (when ‘legacy_result_type’ is ‘True’). If ‘legacy_result_type’ is ‘False’, ‘random_walks’ returns padded results (vertex_paths, edge_weight_paths) but instead of ‘sizes = None’, returns the ‘max_path_lengths’. When ‘legacy_result_type’ is ‘False’, the arhument ‘use_padding’ is ignored.

Parameters:
GcuGraph.Graph or networkx.Graph

The graph can be either directed or undirected.

random_walks_typestr, optional (default=’uniform’)

Type of random walks: ‘uniform’, ‘biased’, ‘node2vec’. Only ‘uniform’ random walks is currently supported

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

When ‘legacy_result_type’ is set to False, ‘max_depth’ is relative to the number of edges otherwised, it is relative to the number of vertices.

use_paddingbool, optional (default=False)

If True, padded paths are returned else coalesced paths are returned.

legacy_result_typebool, optional (default=True)

If True, will return a tuple of vertex_paths, edge_weight_paths and sizes. If False, will return a tuple of vertex_paths, vertex_paths and max_path_length

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
sizes: None or cudf.Series

The path sizes in case of ‘coalesced’ paths or None if ‘padded’.

or
max_path_lengthint

The maximum path length if ‘legacy_result_type’ is ‘False’

Examples

>>> from cugraph.datasets import karate
>>> M = karate.get_edgelist(download=True)
>>> G = karate.get_graph()
>>> start_vertices = G.nodes()[:4]
>>> _, _, _ = cugraph.random_walks(G, "uniform", start_vertices, 3)