采样#

均匀随机游走#

cugraph_error_code_t cugraph_uniform_random_walks(const cugraph_resource_handle_t *handle, cugraph_rng_state_t *rng_state, cugraph_graph_t *graph, const cugraph_type_erased_device_array_view_t *start_vertices, size_t max_length, cugraph_random_walk_result_t **result, cugraph_error_t **error)#

计算均匀随机游走。

参数:
  • handle[in] 访问资源的句柄

  • rng_state[inout] 随机数生成器状态,每次调用都会更新

  • graph[in] 图的指针。注意:如果需要转置存储,图可能会被修改

  • start_vertices[in] 源顶点数组

  • max_length[in] 生成路径的最大长度

  • result[out] node2vec 调用输出结果

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码

偏向随机游走#

cugraph_error_code_t cugraph_biased_random_walks(const cugraph_resource_handle_t *handle, cugraph_rng_state_t *rng_state, cugraph_graph_t *graph, const cugraph_type_erased_device_array_view_t *start_vertices, size_t max_length, cugraph_random_walk_result_t **result, cugraph_error_t **error)#

计算偏向随机游走。

参数:
  • handle[in] 访问资源的句柄

  • rng_state[inout] 随机数生成器状态,每次调用都会更新

  • graph[in] 图的指针。注意:如果需要转置存储,图可能会被修改

  • start_vertices[in] 源顶点数组

  • max_length[in] 生成路径的最大长度

  • result[out] node2vec 调用输出结果

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码

通过 Node2Vec 进行随机游走#

cugraph_error_code_t cugraph_node2vec_random_walks(const cugraph_resource_handle_t *handle, cugraph_rng_state_t *rng_state, cugraph_graph_t *graph, const cugraph_type_erased_device_array_view_t *start_vertices, size_t max_length, double p, double q, cugraph_random_walk_result_t **result, cugraph_error_t **error)#

使用 node2vec 框架计算随机游走。

参数:
  • handle[in] 访问资源的句柄

  • rng_state[inout] 随机数生成器状态,每次调用都会更新

  • graph[in] 图的指针。注意:如果需要转置存储,图可能会被修改

  • start_vertices[in] 源顶点数组

  • max_length[in] 生成路径的最大长度

  • compress_result[in] 如果为 true,将路径以压缩稀疏行矩阵形式返回,否则以密集矩阵形式返回

  • p[in] 返回参数

  • q[in] 入/出参数

  • result[out] node2vec 调用输出结果

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码

Node2Vec#

cugraph_error_code_t cugraph_node2vec(const cugraph_resource_handle_t *handle, cugraph_graph_t *graph, const cugraph_type_erased_device_array_view_t *sources, size_t max_depth, bool_t compress_result, double p, double q, cugraph_random_walk_result_t **result, cugraph_error_t **error)#

使用 node2vec 框架计算随机游走。

已弃用

此调用应替换为 cugraph_node2vec_random_walks

参数:
  • handle[in] 访问资源的句柄

  • graph[in] 图的指针。注意:如果需要转置存储,图可能会被修改

  • sources[in] 源顶点数组

  • max_depth[in] 生成路径的最大长度

  • compress_result[in] 如果为 true,将路径以压缩稀疏行矩阵形式返回,否则以密集矩阵形式返回

  • p[in] 返回参数

  • q[in] 入/出参数

  • result[out] node2vec 调用输出结果

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码

均匀邻居采样#

cugraph_error_code_t cugraph_uniform_neighbor_sample(const cugraph_resource_handle_t *handle, cugraph_graph_t *graph, const cugraph_type_erased_device_array_view_t *start_vertices, const cugraph_type_erased_device_array_view_t *start_vertex_labels, const cugraph_type_erased_device_array_view_t *label_list, const cugraph_type_erased_device_array_view_t *label_to_comm_rank, const cugraph_type_erased_device_array_view_t *label_offsets, const cugraph_type_erased_host_array_view_t *fan_out, cugraph_rng_state_t *rng_state, const cugraph_sampling_options_t *options, bool_t do_expensive_check, cugraph_sample_result_t **result, cugraph_error_t **error)#

均匀邻居采样。

已弃用

此 API 将被删除,请使用 cugraph_homogeneous_uniform_neighbor_sample

返回指定起始顶点周围邻居的样本。可选地,每个起始顶点可以与一个标签关联,允许调用者在同一函数调用中指定多个采样请求批次 - 这应该能提高 GPU 利用率。

如果 label 为 NULL,则所有起始顶点将被视为同一批次的一部分,返回结果将不包含标签列。

参数:
  • handle[in] 访问资源的句柄

  • graph[in] 图的指针。注意:如果需要转置存储,图可能会被修改

  • start_vertices[in] 用于采样的起始顶点的设备数组

  • start_vertex_labels[in] 用于采样的起始顶点标签的设备数组。与每个起始顶点关联的标签将包含在源自该起始顶点的结果输出中。我们仅支持 INT32 类型的标签。如果 label 为 NULL,则返回数据将不带标签。

  • label_list[in] 包含在 start_vertex_labels 中的标签的设备数组。如果 label_to_comm_rank 未指定,则忽略此参数。如果指定,label_list 必须按升序排序。

  • label_to_comm_rank[in] 设备数组,标识特定标签的输出应在输出中混洗到哪个通信排名。如果未指定,数据在输出中不进行组织。如果指定,则来自 label_list[i] 的所有数据将混洗到排名 中。除非 start_vertex_labels 也被指定为 label_to_comm_rank[i],否则不能指定此参数。如果未指定,则输出数据不会在排名之间混洗。

  • label_offsets[in] 种子列表中每个标签偏移量的设备数组。此参数仅与 retain_seeds 选项一起使用。

  • fan_out[in] 定义采样算法中每一步扇出的主机数组。我们仅支持 INT32 类型的 fan_out 值

  • rng_state[inout] 随机数生成器状态,每次调用都会更新

  • sampling_options[in] 定义采样选项的不透明指针。

  • do_expensive_check[in] 一个标志,用于对输入参数运行昂贵的检查(如果设置为 true)

  • result[out] uniform_neighbor_sample 调用输出结果

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码

采样支持函数#

cugraph_type_erased_device_array_view_t *cugraph_lookup_result_get_srcs(const cugraph_lookup_result_t *result)#

从查找结果中获取边源。

参数:

result[in] 使用边 ID 和类型进行源-目标查找的结果

返回:

指向边源的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_lookup_result_get_dsts(const cugraph_lookup_result_t *result)#

从查找结果中获取边目标。

参数:

result[in] 使用边 ID 和类型进行源-目标查找的结果

返回:

指向边目标的类型擦除数组

void cugraph_lookup_result_free(cugraph_lookup_result_t *result)#

释放源-目标查找结果。

参数:

result[in] 使用边 ID 和类型进行源-目标查找的结果

void cugraph_lookup_container_free(cugraph_lookup_container_t *container)#

释放采样查找映射。

参数:

container[in] 采样查找映射(也称为容器)。

size_t cugraph_random_walk_result_get_max_path_length(cugraph_random_walk_result_t *result)#

从随机游走结果中获取最大路径长度。

参数:

result[in] 随机游走结果

返回:

最大路径长度

cugraph_type_erased_device_array_view_t *cugraph_random_walk_result_get_paths(cugraph_random_walk_result_t *result)#

获取路径中顶点的矩阵(行主序)。

参数:

result[in] 随机游走算法结果

返回:

指向设备内存中路径矩阵的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_random_walk_result_get_weights(cugraph_random_walk_result_t *result)#

获取路径中边权重的矩阵(行主序)。

参数:

result[in] 随机游走算法结果

返回:

指向设备内存中路径边权重的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_random_walk_result_get_path_sizes(cugraph_random_walk_result_t *result)#

如果随机游走结果已压缩,则获取路径大小。

已弃用

调用新的 node2vec 后,此调用将不再相关

参数:

result[in] 随机游走算法结果

返回:

指向设备内存中路径大小的类型擦除数组

void cugraph_random_walk_result_free(cugraph_random_walk_result_t *result)#

释放随机游走结果。

参数:

result[in] 随机游走结果

cugraph_error_code_t cugraph_sampling_options_create(cugraph_sampling_options_t **options, cugraph_error_t **error)#

创建采样选项对象。

所有采样选项设置为 FALSE

参数:
  • options[out] 指向采样选项的不透明指针

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

void cugraph_sampling_set_retain_seeds(cugraph_sampling_options_t *options, bool_t value)#

设置标志以保留种子(原始源)

参数:
  • options – - 指向采样选项的不透明指针

  • value – - 赋给选项的布尔值

void cugraph_sampling_set_renumber_results(cugraph_sampling_options_t *options, bool_t value)#

设置标志以重新编号结果。

参数:
  • options – - 指向采样选项的不透明指针

  • value – - 赋给选项的布尔值

void cugraph_sampling_set_compress_per_hop(cugraph_sampling_options_t *options, bool_t value)#

设置是按跳压缩(True)还是全局压缩(False)

参数:
  • options – - 指向采样选项的不透明指针

  • value – - 赋给选项的布尔值

void cugraph_sampling_set_with_replacement(cugraph_sampling_options_t *options, bool_t value)#

设置标志以进行有放回采样。

参数:
  • options – - 指向采样选项的不透明指针

  • value – - 赋给选项的布尔值

void cugraph_sampling_set_return_hops(cugraph_sampling_options_t *options, bool_t value)#

设置标志以采样返回跳数。

参数:
  • options – - 指向采样选项的不透明指针

  • value – - 赋给选项的布尔值

void cugraph_sampling_set_compression_type(cugraph_sampling_options_t *options, cugraph_compression_type_t value)#

设置压缩类型。

参数:
  • options – - 指向采样选项的不透明指针

  • value – - 定义压缩类型的枚举

void cugraph_sampling_set_prior_sources_behavior(cugraph_sampling_options_t *options, cugraph_prior_sources_behavior_t value)#

设置先验源行为。

参数:
  • options – - 指向采样选项的不透明指针

  • value – - 定义先验源行为的枚举

void cugraph_sampling_set_dedupe_sources(cugraph_sampling_options_t *options, bool_t value)#

设置标志以在采样前对 dedupe_sources 进行采样。

参数:
  • options – - 指向采样选项的不透明指针

  • value – - 赋给选项的布尔值

void cugraph_sampling_options_free(cugraph_sampling_options_t *options)#

释放采样选项对象。

参数:

options[in] 指向采样对象的不透明指针

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_majors(const cugraph_sample_result_t *result)#

从采样算法结果中获取主顶点。

参数:

result[in] 采样算法结果

返回:

指向设备内存中主顶点的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_minors(const cugraph_sample_result_t *result)#

从采样算法结果中获取次顶点。

参数:

result[in] 采样算法结果

返回:

指向设备内存中次顶点的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_major_offsets(const cugraph_sample_result_t *result)#

从采样算法结果中获取主偏移量。

参数:

result[in] 采样算法结果

返回:

指向设备内存中主偏移量的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_start_labels(const cugraph_sample_result_t *result)#

从采样算法结果中获取起始标签。

参数:

result[in] 采样算法结果

返回:

指向起始标签的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_edge_id(const cugraph_sample_result_t *result)#

从采样算法结果中获取 edge_id。

参数:

result[in] 采样算法结果

返回:

指向 edge_id 的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_edge_type(const cugraph_sample_result_t *result)#

从采样算法结果中获取 edge_type。

参数:

result[in] 采样算法结果

返回:

指向 edge_type 的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_edge_weight(const cugraph_sample_result_t *result)#

从采样算法结果中获取 edge_weight。

参数:

result[in] 采样算法结果

返回:

指向 edge_weight 的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_hop(const cugraph_sample_result_t *result)#

从采样算法结果中获取 hop。

参数:

result[in] 采样算法结果

返回:

指向 hop 的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_label_hop_offsets(const cugraph_sample_result_t *result)#

从采样算法结果中获取 label-hop 偏移量。

参数:

result[in] 采样算法结果

返回:

指向 label-hop 偏移量的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_label_type_hop_offsets(const cugraph_sample_result_t *result)#

从采样算法结果中获取 label-type-hop 偏移量。

参数:

result[in] 采样算法结果

返回:

指向 label-type-hop 偏移量的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_index(const cugraph_sample_result_t *result)#

从采样算法结果中获取 index。

参数:

result[in] 采样算法结果

返回:

指向 index 的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_renumber_map(const cugraph_sample_result_t *result)#

获取 renumber map。

参数:

result[in] 采样算法结果

返回:

指向 renumber map 的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_renumber_map_offsets(const cugraph_sample_result_t *result)#

获取 renumber map 偏移量。

参数:

result[in] 采样算法结果

返回:

指向 renumber map 偏移量的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_edge_renumber_map(const cugraph_sample_result_t *result)#

获取 edge renumber map。

参数:

result[in] 采样算法结果

返回:

指向 renumber map 的类型擦除数组

cugraph_type_erased_device_array_view_t *cugraph_sample_result_get_edge_renumber_map_offsets(const cugraph_sample_result_t *result)#

获取 edge renumber map 偏移量。

参数:

result[in] 采样算法结果

返回:

指向 renumber map 的类型擦除数组

void cugraph_sample_result_free(cugraph_sample_result_t *result)#

释放采样结果。

参数:

result[in] 采样算法结果

cugraph_error_code_t cugraph_test_sample_result_create(const cugraph_resource_handle_t *handle, const cugraph_type_erased_device_array_view_t *srcs, const cugraph_type_erased_device_array_view_t *dsts, const cugraph_type_erased_device_array_view_t *edge_id, const cugraph_type_erased_device_array_view_t *edge_type, const cugraph_type_erased_device_array_view_t *wgt, const cugraph_type_erased_device_array_view_t *hop, const cugraph_type_erased_device_array_view_t *label, cugraph_sample_result_t **result, cugraph_error_t **error)#

创建采样结果(测试 API)

参数:
  • handle[in] 访问资源的句柄

  • srcs[in] 用于填充 srcs 的设备数组视图

  • dsts[in] 用于填充 dsts 的设备数组视图

  • edge_id[in] 用于填充 edge_id 的设备数组视图(可为 NULL)

  • edge_type[in] 用于填充 edge_type 的设备数组视图(可为 NULL)

  • wgt[in] 用于填充 wgt 的设备数组视图(可为 NULL)

  • hop[in] 用于填充 hop 的设备数组视图

  • label[in] 用于填充 label 的设备数组视图(可为 NULL)

  • result[out] 指向存储 cugraph_sample_result_t* 的位置的指针

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码

cugraph_error_code_t cugraph_test_uniform_neighborhood_sample_result_create(const cugraph_resource_handle_t *handle, const cugraph_type_erased_device_array_view_t *srcs, const cugraph_type_erased_device_array_view_t *dsts, const cugraph_type_erased_device_array_view_t *edge_id, const cugraph_type_erased_device_array_view_t *edge_type, const cugraph_type_erased_device_array_view_t *weight, const cugraph_type_erased_device_array_view_t *hop, const cugraph_type_erased_device_array_view_t *label, cugraph_sample_result_t **result, cugraph_error_t **error)#

创建采样结果(测试 API)

参数:
  • handle[in] 访问资源的句柄

  • srcs[in] 用于填充 srcs 的设备数组视图

  • dsts[in] 用于填充 dsts 的设备数组视图

  • edge_id[in] 用于填充 edge_id 的设备数组视图

  • edge_type[in] 用于填充 edge_type 的设备数组视图

  • weight[in] 用于填充 weight 的设备数组视图

  • hop[in] 用于填充 hop 的设备数组视图

  • label[in] 用于填充 label 的设备数组视图

  • result[out] 指向存储 cugraph_sample_result_t* 的位置的指针

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码

cugraph_error_code_t cugraph_select_random_vertices(const cugraph_resource_handle_t *handle, const cugraph_graph_t *graph, cugraph_rng_state_t *rng_state, size_t num_vertices, cugraph_type_erased_device_array_t **vertices, cugraph_error_t **error)#

从图中选择随机顶点。

参数:
  • handle[in] 访问资源的句柄

  • graph[in] 图的指针

  • rng_state[inout] 随机数生成器状态,每次调用都会更新

  • num_vertices[in] 要采样的顶点数量

  • vertices[out] 用于填充顶点的设备数组视图

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码

cugraph_error_code_t cugraph_negative_sampling(const cugraph_resource_handle_t *handle, cugraph_rng_state_t *rng_state, cugraph_graph_t *graph, const cugraph_type_erased_device_array_view_t *vertices, const cugraph_type_erased_device_array_view_t *src_biases, const cugraph_type_erased_device_array_view_t *dst_biases, size_t num_samples, bool_t remove_duplicates, bool_t remove_existing_edges, bool_t exact_number_of_samples, bool_t do_expensive_check, cugraph_coo_t **result, cugraph_error_t **error)#

执行负采样。

负采样根据指定的参数生成定义边的 COO 结构

参数:
  • handle[in] 访问资源的句柄

  • rng_state[inout] 随机数生成器状态,每次调用都会更新

  • graph[in] 图的指针

  • vertices[in] 源偏差的顶点 ID。如果 src_biasdst_bias 未指定,则忽略此项。如果 vertices 指定,则 vertices[i] 是 src_biases[i] 和 dst_biases[i] 的顶点 ID。如果 vertices 未指定,则 i 是 src_biases[i] 和 dst_biases[i] 的顶点 ID

  • 源顶点偏置[输入] 用于选择源顶点的偏置。如果为 NULL,则进行均匀采样,如果提供,顶点 i 的概率将是 src_bias[i] / (所有源偏置之和)

  • 目标顶点偏置[输入] 用于选择目标顶点的偏置。如果为 NULL,则进行均匀采样,如果提供,顶点 i 的概率将是 dst_bias[i] / (所有目标偏置之和)

  • 样本数量[输入] 要生成的样本数量

  • 移除重复项[输入] 如果为 true,则从采样的边中移除重复项

  • 移除现有边[输入] 如果为 true,则移除图中实际存在的采样边

  • 精确的样本数量[输入] 如果为 true,结果应精确包含 num_samples。如果为 false,代码将生成 num_samples 然后执行任何指定的过滤

  • do_expensive_check[in] 一个标志,用于对输入参数运行昂贵的检查(如果设置为 true)

  • 结果[输出] 指向生成的 coo 列表的不透明指针

  • error[out] 指向存储任何错误详情的错误对象的指针。如果错误码不是 CUGRAPH_SUCCESS,则会填充此对象

返回:

错误码