Sampling#

template<typename vertex_t, typename edge_t, typename weight_t, bool multi_gpu>
std::tuple<rmm::device_uvector<vertex_t>, std::optional<rmm::device_uvector<weight_t>>> uniform_random_walks(raft::handle_t const &handle, raft::random::RngState &rng_state, graph_view_t<vertex_t, edge_t, false, multi_gpu> const &graph_view, std::optional<edge_property_view_t<edge_t, weight_t const*>> edge_weight_view, raft::device_span<vertex_t const> start_vertices, size_t max_length)#

returns uniform random walks from starting sources, where each path is of given maximum length.

.*

start_vertices can contain duplicates, in which case different random walks will be generated for each instance.

If edge_weight_view.has_value() is true, the return contains edge weights. If edge_weight_view.has_value() is false, the returned value will be std::nullopt.

Template Parameters:
  • vertex_t – Type of vertex identifiers. Needs to be an integral type.

  • edge_t – Type of edge identifiers. Needs to be an integral type.

  • weight_t – Type of edge weights. Needs to be a floating point type.

  • multi_gpu – Flag indicating whether template instantiation should target single-GPU (false)

Parameters:
  • handle – RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and handles to various CUDA libraries) to run graph algorithms.

  • graph_view – graph view to operate on

  • edge_weight_view – Optional view object holding edge weights for graph_view.

  • start_vertices – Device span defining the starting vertices

  • max_length – maximum length of random walk

  • seed – (optional, defaults to system time), seed for random number generation

Returns:

tuple containing device vectors of vertices and the edge weights (if edge_weight_view.has_value()

is true)

For each input selector there will be (max_length+1) elements in the vertex vector with the starting vertex followed by the subsequent vertices in the random walk. If a path terminates before max_length, the vertices will be populated with

invalid_vertex_id

(-1 for signed vertex_t, std::numeric_limits<vertex_t>::max() for an unsigned vertex_t type)

For each input selector there will be max_length elements in the weights vector with the edge weight for the edge in the path. If a path terminates before max_length the subsequent edge weights will be set to weight_t{0}.

template<typename vertex_t, typename edge_t, typename weight_t, bool multi_gpu>
std::tuple<rmm::device_uvector<vertex_t>, std::optional<rmm::device_uvector<weight_t>>> biased_random_walks(raft::handle_t const &handle, raft::random::RngState &rng_state, graph_view_t<vertex_t, edge_t, false, multi_gpu> const &graph_view, edge_property_view_t<edge_t, weight_t const*> edge_weight_view, raft::device_span<vertex_t const> start_vertices, size_t max_length)#

returns biased random walks from starting sources, where each path is of given maximum length.

.*

The next vertex is biased based on the edge weights. The probability of traversing a departing edge will be the edge weight divided by the sum of the departing edge weights.

start_vertices can contain duplicates, in which case different random walks will be generated for each instance.

Throws:

cugraph::logic_error – if the graph is unweighted

Template Parameters:
  • vertex_t – Type of vertex identifiers. Needs to be an integral type.

  • edge_t – Type of edge identifiers. Needs to be an integral type.

  • weight_t – Type of edge weights. Needs to be a floating point type.

  • multi_gpu – Flag indicating whether template instantiation should target single-GPU (false)

Parameters:
  • handle – RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and handles to various CUDA libraries) to run graph algorithms.

  • graph_view – graph view to operate on

  • edge_weight_view – View object holding edge weights for graph_view.

  • start_vertices – Device span defining the starting vertices

  • max_length – maximum length of random walk

  • seed – (optional, defaults to system time), seed for random number generation

Returns:

tuple containing device vectors of vertices and the edge weights

For each input selector there will be (max_length+1) elements in the vertex vector with the starting vertex followed by the subsequent vertices in the random walk. If a path terminates before max_length, the vertices will be populated with

invalid_vertex_id

(-1 for signed vertex_t, std::numeric_limits<vertex_t>::max() for an unsigned vertex_t type)

For each input selector there will be max_length elements in the weights vector with the edge weight for the edge in the path. If a path terminates before max_length the subsequent edge weights will be set to weight_t{0}.

template<typename vertex_t, typename edge_t, typename weight_t, bool multi_gpu>
std::tuple<rmm::device_uvector<vertex_t>, std::optional<rmm::device_uvector<weight_t>>> node2vec_random_walks(raft::handle_t const &handle, raft::random::RngState &rng_state, graph_view_t<vertex_t, edge_t, false, multi_gpu> const &graph_view, std::optional<edge_property_view_t<edge_t, weight_t const*>> edge_weight_view, raft::device_span<vertex_t const> start_vertices, size_t max_length, weight_t p, weight_t q)#

returns biased random walks with node2vec biases from starting sources, where each path is of given maximum length.

.*

start_vertices can contain duplicates, in which case different random walks will be generated for each instance.

If the edge_weight_view.has_value() = true, the return contains edge weights and the node2vec computation will utilize the edge weights. If edge_weight_view.has_value() == false, then the return will not contain edge weights and the node2vec computation will assume an edge weight of 1 for all edges.

Template Parameters:
  • vertex_t – Type of vertex identifiers. Needs to be an integral type.

  • edge_t – Type of edge identifiers. Needs to be an integral type.

  • weight_t – Type of edge weights. Needs to be a floating point type.

  • multi_gpu – Flag indicating whether template instantiation should target single-GPU (false)

Parameters:
  • handle – RAFT handle object to encapsulate resources (e.g. CUDA stream, communicator, and handles to various CUDA libraries) to run graph algorithms.

  • graph_view – graph view to operate on

  • edge_weight_view – Optional view object holding edge weights for graph_view. If edge_weight_view.has_value() == false, edge weights are assumed to be 1.0.

  • start_vertices – Device span defining the starting vertices

  • max_length – maximum length of random walk

  • p – node2vec return parameter

  • q – node2vec in-out parameter

  • seed – (optional, defaults to system time), seed for random number generation

Returns:

tuple containing device vectors of vertices and the edge weights

For each input selector there will be (max_length+1) elements in the vertex vector with the starting vertex followed by the subsequent vertices in the random walk. If a path terminates before max_length, the vertices will be populated with

invalid_vertex_id

(-1 for signed vertex_t, std::numeric_limits<vertex_t>::max() for an unsigned vertex_t type)

For each input selector there will be max_length elements in the weights vector with the edge weight for the edge in the path. If a path terminates before max_length the subsequent edge weights will be set to weight_t{0}.