Skip to content

Commit

Permalink
louvain: add modularity parameter and fix isolated community lost (#14)
Browse files Browse the repository at this point in the history
* add modularity parameter for louvain
* fix: louvain lost isolated community from one to next pass

Change-Id: I6a7dadc80635429aa2898939aa337aae01bc8d12
  • Loading branch information
javeme authored and imbajin committed Nov 7, 2022
1 parent 263b14e commit 7151c80
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
public abstract class AbstractAlgorithm implements Algorithm {

public static final long MAX_RESULT_SIZE = 100L * Bytes.MB;
public static final long MAX_QUERY_LIMIT = 10000000L; // about 10GB
public static final long MAX_QUERY_LIMIT = 100000000L; // about 100GB
public static final int BATCH = 500;

public static final String CATEGORY_AGGR = "aggregate";
Expand All @@ -81,6 +81,7 @@ public abstract class AbstractAlgorithm implements Algorithm {
public static final String KEY_TIMES = "times";
public static final String KEY_STABLE_TIMES = "stable_times";
public static final String KEY_PRECISION = "precision";
public static final String KEY_SHOW_MOD= "show_modularity";
public static final String KEY_SHOW_COMM = "show_community";
public static final String KEY_CLEAR = "clear";
public static final String KEY_CAPACITY = "capacity";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Map;

import com.baidu.hugegraph.job.Job;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.traversal.algorithm.HugeTraverser;

public class LouvainAlgorithm extends AbstractCommAlgorithm {

Expand All @@ -39,6 +39,7 @@ public void checkParameters(Map<String, Object> parameters) {
degree(parameters);
sourceLabel(parameters);
sourceCLabel(parameters);
showModularity(parameters);
showCommunity(parameters);
clearPass(parameters);
}
Expand All @@ -52,10 +53,13 @@ public Object call(Job<Object> job, Map<String, Object> parameters) {
LouvainTraverser traverser = new LouvainTraverser(job, degree,
label, clabel);
Long clearPass = clearPass(parameters);
Long modPass = showModularity(parameters);
String showComm = showCommunity(parameters);
try {
if (clearPass != null) {
return traverser.clearPass(clearPass.intValue());
} else if (modPass != null) {
return traverser.modularity(modPass.intValue());
} else if (showComm != null) {
return traverser.showCommunity(showComm);
} else {
Expand All @@ -74,10 +78,16 @@ protected static Long clearPass(Map<String, Object> parameters) {
return null;
}
long pass = parameterLong(parameters, KEY_CLEAR);
// TODO: change to checkNonNegative()
E.checkArgument(pass >= 0 || pass == -1,
"The %s parameter must be >= 0 or == -1, but got %s",
KEY_CLEAR, pass);
HugeTraverser.checkNonNegativeOrNoLimit(pass, KEY_CLEAR);
return pass;
}

protected static Long showModularity(Map<String, Object> parameters) {
if (!parameters.containsKey(KEY_SHOW_MOD)) {
return null;
}
long pass = parameterLong(parameters, KEY_SHOW_MOD);
HugeTraverser.checkNonNegative(pass, KEY_SHOW_MOD);
return pass;
}
}
Loading

0 comments on commit 7151c80

Please sign in to comment.