Skip to content

Commit 67ece64

Browse files
authored
fix(analytical): Fix Louvain algorithm's implementation as the quality bigger than 1.0 (#4426)
## What do these changes do? When I test Louvain with the [DBLP dataset](https://snap.stanford.edu/data/com-DBLP.html), I found the QUALITY is bigger than 1.0 (which is 1.13) in the first iteration, which is not correct, see [here](https://en.wikipedia.org/wiki/Louvain_method#:~:text=Modularity%20is%20a%20scale%20value,nodes%20of%20a%20given%20network.) QUALITY is in [-1, 1]. <img width="1028" alt="f1" src="https://github.com/user-attachments/assets/aa10112e-2168-49a3-b0bd-1cd83ea06646" /> Then I found the Louvain's implementation has some problems, as the Louvain only supports undirected graph now, the current edge weight in each edge has calculated one more time as using both outgoing_edges() and incoming_edges(), fix it , we only need use outgoing_edges() in undirected graph.
1 parent fbbbd93 commit 67ece64

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

analytical_engine/apps/pregel/louvain/louvain_app_base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class LouvainAppBase
223223
auto actual_quality =
224224
ctx.compute_context().template get_aggregated_value<double>(
225225
actual_quality_aggregator);
226+
assert(actual_quality <= 1.0);
226227
// after one pass if already decided halt, that means the pass yield no
227228
// changes, so we halt computation.
228229
if (current_super_step <= 14 ||

analytical_engine/apps/pregel/louvain/louvain_vertex.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class LouvainVertex : public PregelVertex<FRAG_T, VD_T, MD_T> {
6868

6969
size_t edge_size() {
7070
if (!this->use_fake_edges()) {
71-
return this->incoming_edges().Size() + this->outgoing_edges().Size();
71+
return this->outgoing_edges().Size();
7272
} else {
7373
return this->fake_edges().size();
7474
}
@@ -88,11 +88,6 @@ class LouvainVertex : public PregelVertex<FRAG_T, VD_T, MD_T> {
8888

8989
edata_t get_edge_value(const vid_t& dst_id) {
9090
if (!this->use_fake_edges()) {
91-
for (auto& edge : this->incoming_edges()) {
92-
if (this->fragment_->Vertex2Gid(edge.get_neighbor()) == dst_id) {
93-
return static_cast<edata_t>(edge.get_data());
94-
}
95-
}
9691
for (auto& edge : this->outgoing_edges()) {
9792
if (this->fragment_->Vertex2Gid(edge.get_neighbor()) == dst_id) {
9893
return static_cast<edata_t>(edge.get_data());
@@ -117,12 +112,6 @@ class LouvainVertex : public PregelVertex<FRAG_T, VD_T, MD_T> {
117112
edata_t get_edge_values(const std::set<vid_t>& dst_ids) {
118113
edata_t ret = 0;
119114
if (!this->use_fake_edges()) {
120-
for (auto& edge : this->incoming_edges()) {
121-
auto gid = this->fragment_->Vertex2Gid(edge.get_neighbor());
122-
if (dst_ids.find(gid) != dst_ids.end()) {
123-
ret += static_cast<edata_t>(edge.get_data());
124-
}
125-
}
126115
for (auto& edge : this->outgoing_edges()) {
127116
auto gid = this->fragment_->Vertex2Gid(edge.get_neighbor());
128117
if (dst_ids.find(gid) != dst_ids.end()) {

0 commit comments

Comments
 (0)