中心性算法#
cuGraph PageRank 是使用我们的图元语库实现的
PageRank#
单元测试代码是寻找调用 PageRank 示例的最佳位置。
简单 PageRank#
此示例假设您已以某种方式创建了 SG 或 MG 图。调用者必须在设备内存中创建 PageRank 向量,并将该向量的原始指针传递给 PageRank 函数。
#include <cugraph/algorithms.hpp>
...
using vertex_t = int32_t; // or int64_t, whichever is appropriate
using weight_t = float; // or double, whichever is appropriate
using result_t = weight_t; // could specify float or double also
raft::handle_t handle; // Must be configured if MG
auto graph_view = graph.view(); // assumes you have created a graph somehow
result_t constexpr alpha{0.85};
result_t constexpr epsilon{1e-6};
rmm::device_uvector<result_t> pageranks_v(graph_view.number_of_vertices(), handle.get_stream());
// pagerank optionally supports three additional parameters:
// max_iterations - maximum number of iterations, if pagerank doesn't coverge by
// then we abort
// has_initial_guess - if true, values in the pagerank array when the call is initiated
// will be used as the initial pagerank values. These values will
// be normalized before use. If false (the default), the values
// in the pagerank array will be set to 1/num_vertices before
// starting the computation.
// do_expensive_check - perform extensive validation of the input data before
// executing algorithm. Off by default. Note: turning this on
// is expensive
cugraph::pagerank(handle, graph_view, nullptr, nullptr, nullptr, vertex_t{0},
pageranks_v.data(), alpha, epsilon);
个性化 PageRank#
此示例假设您已以某种方式创建了 SG 或 MG 图。调用者必须在设备内存中创建 PageRank 向量,并将该向量的原始指针传递给 PageRank 函数。此外,调用者还必须在设备内存中创建 personalization_vertices 和 personalized_values 向量,填充它们,并传递这些向量的原始指针。
#include <cugraph/algorithms.hpp>
...
using vertex_t = int32_t; // or int64_t, whichever is appropriate
using weight_t = float; // or double, whichever is appropriate
using result_t = weight_t; // could specify float or double also
raft::handle_t handle; // Must be configured if MG
auto graph_view = graph.view(); // assumes you have created a graph somehow
vertex_t number_of_personalization_vertices; // Provided by caller
result_t constexpr alpha{0.85};
result_t constexpr epsilon{1e-6};
rmm::device_uvector<result_t> pageranks_v(graph_view.number_of_vertices(), handle.get_stream());
rmm::device_uvector<vertex_t> personalization_vertices(number_of_personalization_vertices, handle.get_stream());
rmm::device_uvector<result_t> personalization_values(number_of_personalization_vertices, handle.get_stream());
// Populate personalization_vertices, personalization_values with user provided data
// pagerank optionally supports three additional parameters:
// max_iterations - maximum number of iterations, if pagerank doesn't coverge by
// then we abort
// has_initial_guess - if true, values in the pagerank array when the call is initiated
// will be used as the initial pagerank values. These values will
// be normalized before use. If false (the default), the values
// in the pagerank array will be set to 1/num_vertices before
// starting the computation.
// do_expensive_check - perform extensive validation of the input data before
// executing algorithm. Off by default. Note: turning this on
// is expensive
cugraph::pagerank(handle, graph_view, nullptr, personalization_vertices.data(),
personalization_values.data(), number_of_personalization_vertices,
pageranks_v.data(), alpha, epsilon);
版权所有 (c) 2019 - 2025, NVIDIA CORPORATION。
根据 Apache 许可证 2.0 版(“许可证”)获得许可;除非遵守许可证,否则不得使用此文件。您可以在 https://apache.ac.cn/licenses/LICENSE-2.0 获取许可证副本。
除非适用法律要求或书面同意,否则根据本许可证分发的软件按“原样”分发,不附带任何明示或暗示的保证或条件。请参阅许可证以了解有关权限和限制的特定语言。