- Notifications
You must be signed in to change notification settings - Fork 44
feat: add degree centrality #77
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
Conversation
.../src/main/java/com/baidu/hugegraph/computer/algorithm/degreecentrality/DegreeCentrality.java Show resolved Hide resolved
.../src/main/java/com/baidu/hugegraph/computer/algorithm/degreecentrality/DegreeCentrality.java Show resolved Hide resolved
.../src/main/java/com/baidu/hugegraph/computer/algorithm/degreecentrality/DegreeCentrality.java Show resolved Hide resolved
.../src/main/java/com/baidu/hugegraph/computer/algorithm/degreecentrality/DegreeCentrality.java Show resolved Hide resolved
.../src/main/java/com/baidu/hugegraph/computer/algorithm/degreecentrality/DegreeCentrality.java Show resolved Hide resolved
.../src/main/java/com/baidu/hugegraph/computer/algorithm/degreecentrality/DegreeCentrality.java Outdated Show resolved Hide resolved
b67e173
to cf3cdc1
Compare Codecov Report
@@ Coverage Diff @@ ## master #77 +/- ## ========================================= Coverage ? 87.95% Complexity ? 2618 ========================================= Files ? 271 Lines ? 9874 Branches ? 829 ========================================= Hits ? 8685 Misses ? 785 Partials ? 404
Continue to review full report at Codecov.
|
.../src/main/java/com/baidu/hugegraph/computer/algorithm/degreecentrality/DegreeCentrality.java Show resolved Hide resolved
@Override | ||
public void init(Config config) { | ||
// pass | ||
} | ||
| ||
@Override | ||
public void close(Config config) { | ||
// pass | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these empty methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class inherits Computer interface, must override these methods
public void beforeSuperstep(WorkerContext context) { | ||
// pass | ||
} | ||
| ||
@Override | ||
public void afterSuperstep(WorkerContext context) { | ||
// pass | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these empty methods
@Override | ||
public void compute0(ComputationContext context, Vertex vertex) { | ||
long normalization = context.totalVertexCount() - 1; | ||
if (normalization <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0L
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, this version we don't use normalization
.../src/main/java/com/baidu/hugegraph/computer/algorithm/degreecentrality/DegreeCentrality.java Show resolved Hide resolved
if (normalization <= 0) { | ||
vertex.value(new DoubleValue(1.0)); | ||
} else { | ||
vertex.value(new DoubleValue(vertex.numEdges() / normalization)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need to this version, since context.totalVertexCount() - 1
is not the max degree in hugegraph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
82344ff
to 3b52c65
Compare ...src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentrality.java Show resolved Hide resolved
...main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityTest.java Outdated Show resolved Hide resolved
06de4da
to ee3a3ee
Compare ...in/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityParams.java Show resolved Hide resolved
computer-test/src/main/java/com/baidu/hugegraph/computer/algorithm/AlgorithmTestBase.java Outdated Show resolved Hide resolved
...main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityTest.java Show resolved Hide resolved
...er-test/src/main/java/com/baidu/hugegraph/computer/algorithm/rank/pagerank/PageRankTest.java Outdated Show resolved Hide resolved
while (edges.hasNext()) { | ||
edge = edges.next(); | ||
DoubleValue value = edge.properties().get(this.weight); | ||
E.checkArgumentNotNull(value, "The edge's '%s' weight " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set 0 if not exist weight property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
graph server weightShortestPath default value is 1.0 if not exist, so here we also set 1.0 if not exist
bfff46a
to 008c0d2
Compare ...src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentrality.java Outdated Show resolved Hide resolved
@Override | ||
public void write(Vertex vertex) { | ||
super.write(vertex); | ||
isRun = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to counter++
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
algorithm verify logic lie on write code block, isRun only mark the algorithm is running, so use boolean maybe is enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if use counter, can assert write times is expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact, assert logic is different on different algorithm, degree centrality don't need verify write times, so maybe other algorithm can use counter
008c0d2
to 7d59cbb
Compare ...src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentrality.java Outdated Show resolved Hide resolved
...src/main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentrality.java Outdated Show resolved Hide resolved
vertex.value(new DoubleValue(vertex.numEdges())); | ||
} else { | ||
Edge edge = null; | ||
BigDecimal totalWeight = BigDecimal.valueOf(0.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems double value is ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==, here consider super vertex, and maybe overflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling totalWeight.doubleValue() with BigDecimal may also overflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, BigDecimal can handle overflow, but BigDecimal.doubleValue() can overflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we consider implement "BigDecimalValue" earliest, so use these, but now no time to do it, so maybe here we change to double ,and annotation to use BigDecimalValue in the future
@Override | ||
public void write(Vertex vertex) { | ||
super.write(vertex); | ||
isRun = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if use counter, can assert write times is expected.
6cebe71
to 546966b
Compare ...main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityTest.java Outdated Show resolved Hide resolved
...main/java/com/baidu/hugegraph/computer/algorithm/centrality/degree/DegreeCentralityTest.java Show resolved Hide resolved
vertex.value(new DoubleValue(vertex.numEdges())); | ||
} else { | ||
Edge edge = null; | ||
BigDecimal totalWeight = BigDecimal.valueOf(0.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling totalWeight.doubleValue() with BigDecimal may also overflow
246a39e
to e8f1fe1
Compare ci blocked: 2021-08-11 03:26:20 1422628 [pool-59-thread-3] [INFO ] com.baidu.hugegraph.computer.core.bsp.EtcdClient [] - Wait for keys with prefix 'BSP_WORKER_OUTPUT_DONE' and timeout 86400000ms, expect 2 keys but actual got 1 keys 2021-08-11 03:26:30 1432628 [pool-59-thread-3] [INFO ] com.baidu.hugegraph.computer.core.bsp.EtcdClient [] - Wait for keys with prefix 'BSP_WORKER_OUTPUT_DONE' and timeout 86400000ms, expect 2 keys but actual got 1 keys 2021-08-11 03:26:40 1442629 [pool-59-thread-3] [INFO ] com.baidu.hugegraph.computer.core.bsp.EtcdClient [] - Wait for keys with prefix 'BSP_WORKER_OUTPUT_DONE' and timeout 86400000ms, expect 2 keys but actual got 1 keys |
(Value) edge.properties() | ||
.get(this.weightProperty)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add edge.property(key) method
*/ | ||
public class MockWorkerService extends WorkerService { | ||
| ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused empty line
params.put(RpcOptions.RPC_SERVER_HOST.name(), "localhost"); | ||
params.put(RpcOptions.RPC_SERVER_PORT.name(), "8090"); | ||
params.put(ComputerOptions.JOB_ID.name(), "local_002"); | ||
params.put(ComputerOptions.JOB_WORKERS_COUNT.name(), "1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems not effect in ci tests
3a1745c
to b65be6c
Compare b2622d5
to 9408263
Compare
No description provided.