Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(analytical): fix the louvain algorithm that the result is not consistent with #183 #3472

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions analytical_engine/apps/pregel/louvain/auxiliary.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ constexpr int phase_one_minor_step_0 = 0;
constexpr int phase_one_minor_step_1 = 1;
constexpr int phase_one_minor_step_2 = 2;

constexpr double min_quality_improvement = 0.001;

/**
* The state of a vertex.
*/
Expand Down
14 changes: 5 additions & 9 deletions analytical_engine/apps/pregel/louvain/louvain_app_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.
#ifndef ANALYTICAL_ENGINE_APPS_PREGEL_LOUVAIN_LOUVAIN_APP_BASE_H_
#define ANALYTICAL_ENGINE_APPS_PREGEL_LOUVAIN_LOUVAIN_APP_BASE_H_

#include <cmath>
#include <memory>
#include <string>
#include <utility>
Expand Down Expand Up @@ -224,7 +225,9 @@ class LouvainAppBase
actual_quality_aggregator);
// after one pass if already decided halt, that means the pass yield no
// changes, so we halt computation.
if (current_super_step <= 14 || actual_quality <= ctx.prev_quality()) {
if (current_super_step <= 14 ||
std::fabs(actual_quality - ctx.prev_quality()) <
min_quality_improvement) {
// turn to sync community result
ctx.compute_context().set_superstep(sync_result_step);
syncCommunity(frag, ctx, messages);
Expand Down Expand Up @@ -273,13 +276,6 @@ class LouvainAppBase
} else if (ctx.compute_context().superstep() == compress_community_step) {
ctx.GetVertexState(v).is_alived_community = false;
}

if (!ctx.compute_context().active(v)) {
std::vector<std::pair<vid_t, edata_t>> tmp_edges;
ctx.GetVertexState(v).fake_edges.swap(tmp_edges);
std::vector<vid_t> tmp_nodes;
ctx.GetVertexState(v).nodes_in_community.swap(tmp_nodes);
}
});

{
Expand Down Expand Up @@ -321,7 +317,7 @@ class LouvainAppBase
int tid, vertex_t v) {
const auto& member_list = ctx.vertex_state()[v].nodes_in_community;
if (!member_list.empty()) {
auto community_id = frag.Gid2Oid(member_list.front());
auto community_id = frag.Gid2Oid(ctx.vertex_state()[v].community);
// send community id to members
for (const auto& member_gid : member_list) {
auto fid = vid_parser.GetFid(member_gid);
Expand Down
5 changes: 4 additions & 1 deletion python/graphscope/tests/unittest/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ def test_other_app_on_undirected_graph(

# louvain
ctx = louvain(p2p_project_undirected_graph, min_progress=50, progress_tries=2)
assert ctx is not None
df = ctx.to_dataframe({"node": "v.id", "r": "r"})
community_num = len(df["r"].unique())
print("community_num: ", community_num) # it's not a fixed number

# simple_path
ctx = is_simple_path(p2p_project_undirected_graph, [1, 10])
assert ctx is not None
Expand Down
Loading