Skip to content

Commit

Permalink
update PageRank and Katz Centrality's interpretation on input paramet…
Browse files Browse the repository at this point in the history
…er tolerance
  • Loading branch information
seunghwak committed Oct 26, 2020
1 parent 1e3601f commit 0cfbd95
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cpp/src/experimental/katz_centrality.cu
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void katz_centrality(raft::handle_t &handle,

iter++;

if (diff_sum < static_cast<result_t>(num_vertices) * epsilon) {
if (diff_sum < epsilon) {
break;
} else if (iter >= max_iterations) {
CUGRAPH_FAIL("Katz Centrality failed to converge.");
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/experimental/pagerank.cu
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void pagerank(raft::handle_t const& handle,

iter++;

if (diff_sum < static_cast<result_t>(num_vertices) * epsilon) {
if (diff_sum < epsilon) {
break;
} else if (iter >= max_iterations) {
CUGRAPH_FAIL("PageRank failed to converge.");
Expand Down
14 changes: 8 additions & 6 deletions cpp/tests/experimental/katz_centrality_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void katz_centrality_reference(edge_t* offsets,
for (vertex_t i = 0; i < num_vertices; ++i) {
diff_sum += std::abs(katz_centralities[i] - old_katz_centralities[i]);
}
if (diff_sum < static_cast<result_t>(num_vertices) * epsilon) { break; }
if (diff_sum < epsilon) { break; }
iter++;
ASSERT_TRUE(iter < max_iterations);
}
Expand Down Expand Up @@ -150,9 +150,7 @@ class Tests_KatzCentrality : public ::testing::TestWithParam<KatzCentrality_Usec

result_t const alpha = result_t{1.0} / static_cast<result_t>(*max_it + 1);
result_t constexpr beta{1.0};
auto epsilon = graph_view.get_number_of_vertices() > 0
? result_t{1e-3} / static_cast<result_t>(graph_view.get_number_of_vertices())
: result_t{1e-3};
result_t constexpr epsilon{1e-6};

katz_centrality_reference(
h_offsets.data(),
Expand Down Expand Up @@ -195,8 +193,12 @@ class Tests_KatzCentrality : public ::testing::TestWithParam<KatzCentrality_Usec
handle.get_stream());
CUDA_TRY(cudaStreamSynchronize(handle.get_stream()));

auto nearly_equal = [epsilon](auto lhs, auto rhs) {
return std::abs(lhs - rhs) < std::max(std::max(lhs, rhs), epsilon) * 1e-3;
auto threshold_ratio = 1e-3;
auto threshold_magnitude =
(epsilon / static_cast<result_t>(graph_view.get_number_of_vertices())) * threshold_ratio;
auto nearly_equal = [threshold_ratio, threshold_magnitude](auto lhs, auto rhs) {
auto diff = std::abs(lhs - rhs);
return (diff < std::max(lhs, rhs) * threshold_ratio) || (diff < threshold_magnitude);
};

ASSERT_TRUE(std::equal(h_reference_katz_centralities.begin(),
Expand Down
14 changes: 8 additions & 6 deletions cpp/tests/experimental/pagerank_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void pagerank_reference(edge_t* offsets,
for (vertex_t i = 0; i < num_vertices; ++i) {
diff_sum += std::abs(pageranks[i] - old_pageranks[i]);
}
if (diff_sum < static_cast<result_t>(num_vertices) * epsilon) { break; }
if (diff_sum < epsilon) { break; }
iter++;
ASSERT_TRUE(iter < max_iterations);
}
Expand Down Expand Up @@ -220,9 +220,7 @@ class Tests_PageRank : public ::testing::TestWithParam<PageRank_Usecase> {
std::vector<result_t> h_reference_pageranks(graph_view.get_number_of_vertices());

result_t constexpr alpha{0.85};
auto epsilon = graph_view.get_number_of_vertices() > 0
? result_t{1e-3} / static_cast<result_t>(graph_view.get_number_of_vertices())
: result_t{1e-3};
result_t constexpr epsilon{1e-6};

pagerank_reference(h_offsets.data(),
h_indices.data(),
Expand Down Expand Up @@ -263,8 +261,12 @@ class Tests_PageRank : public ::testing::TestWithParam<PageRank_Usecase> {
h_cugraph_pageranks.data(), d_pageranks.data(), d_pageranks.size(), handle.get_stream());
CUDA_TRY(cudaStreamSynchronize(handle.get_stream()));

auto nearly_equal = [epsilon](auto lhs, auto rhs) {
return std::abs(lhs - rhs) < std::max(std::max(lhs, rhs), epsilon) * 1e-3;
auto threshold_ratio = 1e-3;
auto threshold_magnitude =
(epsilon / static_cast<result_t>(graph_view.get_number_of_vertices())) * threshold_ratio;
auto nearly_equal = [threshold_ratio, threshold_magnitude](auto lhs, auto rhs) {
auto diff = std::abs(lhs - rhs);
return (diff < std::max(lhs, rhs) * threshold_ratio) || (diff < threshold_magnitude);
};

ASSERT_TRUE(std::equal(h_reference_pageranks.begin(),
Expand Down

0 comments on commit 0cfbd95

Please sign in to comment.