You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hugegraph.apache.org by GitBox <gi...@apache.org> on 2022/06/04 05:19:58 UTC
[GitHub] [incubator-hugegraph-computer] imbajin opened a new pull request, #108: feat: support cluster coefficient algorithm
imbajin opened a new pull request, #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108
better add more test case (multi increase graph) & refactor later, the doc for it will attach in wiki first
Not redy for review: wait test stable & refact it later
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] coderzc commented on a diff in pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#discussion_r1029414343
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficientOutput.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+import com.baidu.hugegraph.computer.algorithm.community.trianglecount.TriangleCountValue;
+import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;
+import com.baidu.hugegraph.computer.core.output.hg.HugeGraphOutput;
+
+import org.apache.hugegraph.structure.constant.WriteType;
+
+/**
+ * Offer 2 ways to output: write-back + hdfs-file(TODO)
+ */
+public class ClusteringCoefficientOutput extends HugeGraphOutput<Float> {
+
+ @Override
+ public String name() {
+ return "clustering_coefficient";
+ }
+
+ @Override
+ public void prepareSchema() {
+ this.client().schema().propertyKey(this.name())
+ .asFloat()
+ .writeType(WriteType.OLAP_RANGE)
+ .ifNotExist()
+ .create();
+ }
+
+ @Override
+ protected org.apache.hugegraph.structure.graph.Vertex constructHugeVertex(Vertex vertex) {
+ org.apache.hugegraph.structure.graph.Vertex hugeVertex =
+ new org.apache.hugegraph.structure.graph.Vertex(null);
+ hugeVertex.id(vertex.id().asObject());
+ float triangle = ((TriangleCountValue) vertex.value()).count();
+ int degree = ((TriangleCountValue) vertex.value()).idList().size();
Review Comment:
```suggestion
long triangle = ((ClusteringCoefficientValue) vertex.value()).count();
int degree = ((ClusteringCoefficientValue) vertex.value()).idList().size();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] imbajin commented on pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
imbajin commented on PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#issuecomment-1323756556
<img width="1145" alt="image" src="https://user-images.githubusercontent.com/17706099/203338204-765b1bc6-ef62-4a44-928d-39773b7256e8.png">
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] javeme commented on a diff in pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
javeme commented on code in PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#discussion_r1011928222
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficient.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+
Review Comment:
2 blank lines
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficient.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import com.baidu.hugegraph.computer.algorithm.community.trianglecount.TriangleCountValue;
+import com.baidu.hugegraph.computer.core.config.Config;
+import com.baidu.hugegraph.computer.core.graph.edge.Edge;
+import com.baidu.hugegraph.computer.core.graph.edge.Edges;
+import com.baidu.hugegraph.computer.core.graph.id.Id;
+import com.baidu.hugegraph.computer.core.graph.value.IdList;
+import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;
+import com.baidu.hugegraph.computer.core.worker.Computation;
+import com.baidu.hugegraph.computer.core.worker.ComputationContext;
+
+/**
+ * ClusteringCoefficient(CC) algorithm could calculate local & the whole graph:
+ * 1. local cc: get triangles & degree for current vertex, calculate them
+ * 2. whole cc have 2 ways to get the result: (NOT SUPPORTED NOW)
+ * - sum all open & closed triangles in graph, and calculate the result
+ * - sum all local cc for each vertex, and use avg as the whole graph result
+ * <p>
+ * And we have 2 ways to count local cc:
+ * 1. if we already saved the triangles in each vertex, we can calculate only
+ * in superstep0/compute0 to get the result
+ * 2. if we want recount the triangles result, we can choose:
+ * - copy code from TriangleCount, then add extra logic
+ * - reuse code in TriangleCount (need solve compatible problem - TODO)
+ * <p>
+ * The formula of local CC is: C(v) = 2T / Dv(Dv - 1)
+ * v represents one vertex, T represents the triangles of current vertex,
+ * D represents the degree of current vertex
+ */
+public class ClusteringCoefficient implements Computation<IdList> {
+
+ @Override
+ public String name() {
+ return "clustering_coefficient";
+ }
+
+ @Override
+ public String category() {
+ return "community";
+ }
+
+ @Override
+ public void init(Config config) {
+ // Reuse triangle count later
+ }
+
+ @Override
+ public void compute0(ComputationContext context, Vertex vertex) {
+ IdList selfId = new IdList();
+ selfId.add(vertex.id());
+
+ context.sendMessageToAllEdgesIf(vertex, selfId, (ids, targetId) -> {
+ return !ids.get(0).equals(targetId);
+ });
+ vertex.value(new TriangleCountValue());
+ }
+
+ @Override
+ public void compute(ComputationContext context, Vertex vertex, Iterator<IdList> messages) {
+ Integer count = this.triangleCount(context, vertex, messages);
+ if (count != null) {
+ ((TriangleCountValue) vertex.value()).count(count);
+ vertex.inactivate();
+ }
+ }
+
+ private Integer triangleCount(ComputationContext context, Vertex vertex,
+ Iterator<IdList> messages) {
+ IdList neighbors = ((TriangleCountValue) vertex.value()).idList();
+
+ if (context.superstep() == 1) {
+ // Collect outgoing neighbors
+ Set<Id> outNeighbors = getOutNeighbors(vertex);
+ neighbors.addAll(outNeighbors);
+
+ // Collect incoming neighbors
+ while (messages.hasNext()) {
+ IdList idList = messages.next();
+ assert idList.size() == 1;
+ Id inId = idList.get(0);
+ if (!outNeighbors.contains(inId)) {
+ neighbors.add(inId);
+ }
+ }
+ // Save degree to vertex value here (optional)
Review Comment:
// TODO: Save xx
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficientValue.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+import java.io.IOException;
+
+import com.baidu.hugegraph.computer.core.graph.value.IdList;
+import com.baidu.hugegraph.computer.core.graph.value.IntValue;
+import com.baidu.hugegraph.computer.core.graph.value.Value;
+import com.baidu.hugegraph.computer.core.io.RandomAccessInput;
+import com.baidu.hugegraph.computer.core.io.RandomAccessOutput;
+
+/**
+ * We should reuse triangle
Review Comment:
can improve the comment?
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficientValue.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+import java.io.IOException;
+
+import com.baidu.hugegraph.computer.core.graph.value.IdList;
+import com.baidu.hugegraph.computer.core.graph.value.IntValue;
+import com.baidu.hugegraph.computer.core.graph.value.Value;
+import com.baidu.hugegraph.computer.core.io.RandomAccessInput;
+import com.baidu.hugegraph.computer.core.io.RandomAccessOutput;
+
+/**
+ * We should reuse triangle
+ */
+public class ClusteringCoefficientValue implements Value.CustomizeValue<Integer> {
+ private IdList idList;
+ private IntValue count;
+ private final IntValue degree;
+
+ public ClusteringCoefficientValue() {
+ this.idList = new IdList();
+ this.count = new IntValue();
+ this.degree = new IntValue();
+ }
+
+ public IdList idList() {
+ return this.idList;
+ }
+
+ public long count() {
+ return this.count.value();
+ }
+
+ public void count(Integer count) {
+ this.count.value(count);
+ }
+
+ public int degree() {
+ return this.degree.value();
+ }
+
+ public void degree(Integer degree) {
+ this.degree.value(degree);
+ }
+
+ @Override
+ public ClusteringCoefficientValue copy() {
+ ClusteringCoefficientValue ccValue = new ClusteringCoefficientValue();
+ ccValue.idList = this.idList.copy();
+ ccValue.count = this.count.copy();
+ return ccValue;
+ }
+
+ @Override
+ public Integer value() {
+ return this.count.value();
+ }
+
+ @Override
+ public void read(RandomAccessInput in) throws IOException {
+ this.idList.read(in);
+ this.count.read(in);
+ }
+
+ @Override
+ public void write(RandomAccessOutput out) throws IOException {
+ this.idList.write(out);
+ this.count.write(out);
+ }
+
+ @Override
+ public String toString() {
+ return "count" + this.count;
Review Comment:
just `return this.count.toString()`?
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficientValue.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+import java.io.IOException;
+
+import com.baidu.hugegraph.computer.core.graph.value.IdList;
+import com.baidu.hugegraph.computer.core.graph.value.IntValue;
+import com.baidu.hugegraph.computer.core.graph.value.Value;
+import com.baidu.hugegraph.computer.core.io.RandomAccessInput;
+import com.baidu.hugegraph.computer.core.io.RandomAccessOutput;
+
+/**
+ * We should reuse triangle
+ */
+public class ClusteringCoefficientValue implements Value.CustomizeValue<Integer> {
+ private IdList idList;
Review Comment:
expect a blank line
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficientOutput.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+import com.baidu.hugegraph.computer.algorithm.community.trianglecount.TriangleCountValue;
+import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;
+import com.baidu.hugegraph.computer.core.output.hg.HugeGraphOutput;
+import com.baidu.hugegraph.structure.constant.WriteType;
+
+/**
+ * Offer 2 ways to output: write-back + hdfs-file(TODO)
+ */
+public class ClusteringCoefficientOutput extends HugeGraphOutput<Float> {
+
+ @Override
+ public String name() {
+ return "clustering_coefficient";
+ }
+
+ @Override
+ public void prepareSchema() {
+ this.client().schema().propertyKey(this.name())
+ .asFloat()
+ .writeType(WriteType.OLAP_RANGE)
+ .ifNotExist()
+ .create();
+ }
+
+ @Override
+ protected com.baidu.hugegraph.structure.graph.Vertex constructHugeVertex(Vertex vertex) {
+ com.baidu.hugegraph.structure.graph.Vertex hugeVertex =
+ new com.baidu.hugegraph.structure.graph.Vertex(null);
+ hugeVertex.id(vertex.id().asObject());
+ float triangle = ((TriangleCountValue) vertex.value()).count();
+ int degree = ((TriangleCountValue) vertex.value()).idList().size();
+ hugeVertex.property(this.name(), 2 * triangle / degree / (degree - 1));
+ return hugeVertex;
+ }
+
+ /* TODO: enhance it
Review Comment:
unused code?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] imbajin commented on a diff in pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
imbajin commented on code in PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#discussion_r1029429132
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficientOutput.java:
##########
@@ -48,7 +48,7 @@ protected org.apache.hugegraph.structure.graph.Vertex constructHugeVertex(Vertex
org.apache.hugegraph.structure.graph.Vertex hugeVertex =
new org.apache.hugegraph.structure.graph.Vertex(null);
hugeVertex.id(vertex.id().asObject());
- float triangle = ((ClusteringCoefficientValue) vertex.value()).count();
+ long triangle = ((ClusteringCoefficientValue) vertex.value()).count();
int degree = ((ClusteringCoefficientValue) vertex.value()).idList().size();
hugeVertex.property(this.name(), 2 * triangle / degree / (degree - 1));
Review Comment:
yep
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] imbajin commented on a diff in pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
imbajin commented on code in PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#discussion_r1013038053
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficientOutput.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+import com.baidu.hugegraph.computer.algorithm.community.trianglecount.TriangleCountValue;
+import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;
+import com.baidu.hugegraph.computer.core.output.hg.HugeGraphOutput;
+import com.baidu.hugegraph.structure.constant.WriteType;
+
+/**
+ * Offer 2 ways to output: write-back + hdfs-file(TODO)
+ */
+public class ClusteringCoefficientOutput extends HugeGraphOutput<Float> {
+
+ @Override
+ public String name() {
+ return "clustering_coefficient";
+ }
+
+ @Override
+ public void prepareSchema() {
+ this.client().schema().propertyKey(this.name())
+ .asFloat()
+ .writeType(WriteType.OLAP_RANGE)
+ .ifNotExist()
+ .create();
+ }
+
+ @Override
+ protected com.baidu.hugegraph.structure.graph.Vertex constructHugeVertex(Vertex vertex) {
+ com.baidu.hugegraph.structure.graph.Vertex hugeVertex =
+ new com.baidu.hugegraph.structure.graph.Vertex(null);
+ hugeVertex.id(vertex.id().asObject());
+ float triangle = ((TriangleCountValue) vertex.value()).count();
+ int degree = ((TriangleCountValue) vertex.value()).idList().size();
+ hugeVertex.property(this.name(), 2 * triangle / degree / (degree - 1));
+ return hugeVertex;
+ }
+
+ /* TODO: enhance it
Review Comment:
useful, maybe use it in next PR (but not this time)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] github-actions[bot] commented on pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#issuecomment-1174355203
Due to the lack of activity, the current pr is marked as stale and will be closed after 180 days, any update will remove the stale label
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] javeme commented on a diff in pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
javeme commented on code in PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#discussion_r1009504462
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficient.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.algorithm.community.cc;
+
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import com.baidu.hugegraph.computer.algorithm.community.trianglecount.TriangleCountValue;
+import com.baidu.hugegraph.computer.core.config.Config;
+import com.baidu.hugegraph.computer.core.graph.edge.Edge;
+import com.baidu.hugegraph.computer.core.graph.edge.Edges;
+import com.baidu.hugegraph.computer.core.graph.id.Id;
+import com.baidu.hugegraph.computer.core.graph.value.IdList;
+import com.baidu.hugegraph.computer.core.graph.vertex.Vertex;
+import com.baidu.hugegraph.computer.core.worker.Computation;
+import com.baidu.hugegraph.computer.core.worker.ComputationContext;
+
+/**
+ * ClusteringCoefficient(CC) algorithm could calculate local & the whole graph:
+ * 1. local cc: get triangles & degree for current vertex, calculate them
+ * 2. whole cc have 2 ways to get the result: (NOT SUPPORTED NOW)
+ * - sum all open & closed triangles in graph, and calculate the result
+ * - sum all local cc for each vertex, and use avg as the whole graph result
+ * <p>
+ * And we have 2 ways to count local cc:
+ * 1. if we already saved the triangles in each vertex, we can calculate only
+ * in superstep0/compute0 to get the result
+ * 2. if we want recount the triangles result, we can choose:
+ * - copy code from TriangleCount, then add extra logic
+ * - reuse code in TriangleCount (need solve compatible problem - TODO)
+ * <p>
+ * The formula of local CC is: C(v) = 2T / Dv(Dv - 1)
+ * v represents one vertex, T represents the triangles of current vertex,
+ * D represents the degree of current vertex
+ */
+public class ClusteringCoefficient implements Computation<IdList> {
+
+ @Override
+ public String name() {
+ return "clustering_coefficient";
+ }
+
+ @Override
+ public String category() {
+ return "community";
+ }
+
+ @Override
+ public void init(Config config) {
+ // Reuse triangle count later
+ }
+
+ @Override
+ public void compute0(ComputationContext context, Vertex vertex) {
+ IdList selfId = new IdList();
+ selfId.add(vertex.id());
+
+ context.sendMessageToAllEdgesIf(vertex, selfId, (ids, targetId) -> {
+ return !ids.get(0).equals(targetId);
+ });
+ vertex.value(new TriangleCountValue());
+ }
+
+ @Override
+ public void compute(ComputationContext context, Vertex vertex,
+ Iterator<IdList> messages) {
+ Integer count = this.triangleCount(context, vertex, messages);
+ if (count != null) {
+ ((TriangleCountValue) vertex.value()).count(count);
+ vertex.inactivate();
+ }
+ }
+
+ private Integer triangleCount(ComputationContext context, Vertex vertex,
+ Iterator<IdList> messages) {
Review Comment:
align with ComputationContext
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] imbajin commented on pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
imbajin commented on PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#issuecomment-1305782060
merge it after #194
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] codecov[bot] commented on pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#issuecomment-1323821834
# [Codecov](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#108](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (fe68e84) into [master](https://codecov.io/gh/apache/incubator-hugegraph-computer/commit/86e548ccaa180397b61e4809dc9be1e0eb910a26?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (86e548c) will **increase** coverage by `0.01%`.
> The diff coverage is `89.42%`.
```diff
@@ Coverage Diff @@
## master #108 +/- ##
============================================
+ Coverage 86.01% 86.03% +0.01%
- Complexity 3207 3237 +30
============================================
Files 341 345 +4
Lines 12197 12292 +95
Branches 1085 1097 +12
============================================
+ Hits 10491 10575 +84
- Misses 1183 1187 +4
- Partials 523 530 +7
```
| [Impacted Files](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...idu/hugegraph/computer/core/graph/value/Value.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItYXBpL3NyYy9tYWluL2phdmEvY29tL2JhaWR1L2h1Z2VncmFwaC9jb21wdXRlci9jb3JlL2dyYXBoL3ZhbHVlL1ZhbHVlLmphdmE=) | `78.57% <ø> (ø)` | |
| [...ugegraph/computer/core/config/ComputerOptions.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItY29yZS9zcmMvbWFpbi9qYXZhL2NvbS9iYWlkdS9odWdlZ3JhcGgvY29tcHV0ZXIvY29yZS9jb25maWcvQ29tcHV0ZXJPcHRpb25zLmphdmE=) | `100.00% <ø> (ø)` | |
| [...puter/core/network/netty/AbstractNettyHandler.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItY29yZS9zcmMvbWFpbi9qYXZhL2NvbS9iYWlkdS9odWdlZ3JhcGgvY29tcHV0ZXIvY29yZS9uZXR3b3JrL25ldHR5L0Fic3RyYWN0TmV0dHlIYW5kbGVyLmphdmE=) | `47.50% <ø> (ø)` | |
| [...idu/hugegraph/computer/core/util/ShutdownHook.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItY29yZS9zcmMvbWFpbi9qYXZhL2NvbS9iYWlkdS9odWdlZ3JhcGgvY29tcHV0ZXIvY29yZS91dGlsL1NodXRkb3duSG9vay5qYXZh) | `44.44% <ø> (ø)` | |
| [.../algorithm/centrality/degree/DegreeCentrality.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItYWxnb3JpdGhtL3NyYy9tYWluL2phdmEvY29tL2JhaWR1L2h1Z2VncmFwaC9jb21wdXRlci9hbGdvcml0aG0vY2VudHJhbGl0eS9kZWdyZWUvRGVncmVlQ2VudHJhbGl0eS5qYXZh) | `65.51% <33.33%> (-2.23%)` | :arrow_down: |
| [...rithm/community/cc/ClusteringCoefficientValue.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItYWxnb3JpdGhtL3NyYy9tYWluL2phdmEvY29tL2JhaWR1L2h1Z2VncmFwaC9jb21wdXRlci9hbGdvcml0aG0vY29tbXVuaXR5L2NjL0NsdXN0ZXJpbmdDb2VmZmljaWVudFZhbHVlLmphdmE=) | `83.33% <83.33%> (ø)` | |
| [.../algorithm/community/cc/ClusteringCoefficient.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItYWxnb3JpdGhtL3NyYy9tYWluL2phdmEvY29tL2JhaWR1L2h1Z2VncmFwaC9jb21wdXRlci9hbGdvcml0aG0vY29tbXVuaXR5L2NjL0NsdXN0ZXJpbmdDb2VmZmljaWVudC5qYXZh) | `89.79% <89.79%> (ø)` | |
| [...ithm/community/cc/ClusteringCoefficientOutput.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItYWxnb3JpdGhtL3NyYy9tYWluL2phdmEvY29tL2JhaWR1L2h1Z2VncmFwaC9jb21wdXRlci9hbGdvcml0aG0vY29tbXVuaXR5L2NjL0NsdXN0ZXJpbmdDb2VmZmljaWVudE91dHB1dC5qYXZh) | `100.00% <100.00%> (ø)` | |
| [...ithm/community/cc/ClusteringCoefficientParams.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItYWxnb3JpdGhtL3NyYy9tYWluL2phdmEvY29tL2JhaWR1L2h1Z2VncmFwaC9jb21wdXRlci9hbGdvcml0aG0vY29tbXVuaXR5L2NjL0NsdXN0ZXJpbmdDb2VmZmljaWVudFBhcmFtcy5qYXZh) | `100.00% <100.00%> (ø)` | |
| [...hm/community/trianglecount/TriangleCountValue.java](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-Y29tcHV0ZXItYWxnb3JpdGhtL3NyYy9tYWluL2phdmEvY29tL2JhaWR1L2h1Z2VncmFwaC9jb21wdXRlci9hbGdvcml0aG0vY29tbXVuaXR5L3RyaWFuZ2xlY291bnQvVHJpYW5nbGVDb3VudFZhbHVlLmphdmE=) | `100.00% <100.00%> (ø)` | |
| ... and [2 more](https://codecov.io/gh/apache/incubator-hugegraph-computer/pull/108/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] coderzc commented on a diff in pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#discussion_r1029426035
##########
computer-algorithm/src/main/java/com/baidu/hugegraph/computer/algorithm/community/cc/ClusteringCoefficientOutput.java:
##########
@@ -48,7 +48,7 @@ protected org.apache.hugegraph.structure.graph.Vertex constructHugeVertex(Vertex
org.apache.hugegraph.structure.graph.Vertex hugeVertex =
new org.apache.hugegraph.structure.graph.Vertex(null);
hugeVertex.id(vertex.id().asObject());
- float triangle = ((ClusteringCoefficientValue) vertex.value()).count();
+ long triangle = ((ClusteringCoefficientValue) vertex.value()).count();
int degree = ((ClusteringCoefficientValue) vertex.value()).idList().size();
hugeVertex.property(this.name(), 2 * triangle / degree / (degree - 1));
Review Comment:
Keep floating point type?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] imbajin commented on pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
imbajin commented on PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#issuecomment-1296949285
some improve code could do it later (this PR only focus the CI pass)
could start rename package & adopt the dependencies soon
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] imbajin commented on pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
imbajin commented on PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108#issuecomment-1286492106
I'll address it soon
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] github-actions[bot] closed pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed pull request #108: feat: support cluster coefficient algorithm
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [incubator-hugegraph-computer] imbajin merged pull request #108: feat: support cluster coefficient algorithm
Posted by GitBox <gi...@apache.org>.
imbajin merged PR #108:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/108
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org