Skip to content

Commit 8d70d7f

Browse files
committed
Calculate local clustering coefficient for community detection
1 parent d3da5f5 commit 8d70d7f

7 files changed

+112
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Community Detection - Local Clustering Coefficient - Estimate
2+
3+
CALL gds.localClusteringCoefficient.write.estimate(
4+
$dependencies_projection + '-cleaned', {
5+
writeProperty: $dependencies_projection_write_property
6+
})
7+
YIELD requiredMemory
8+
,nodeCount
9+
,relationshipCount
10+
,bytesMin
11+
,bytesMax
12+
,heapPercentageMin
13+
,heapPercentageMax
14+
,treeView
15+
,mapView
16+
RETURN requiredMemory
17+
,nodeCount
18+
,relationshipCount
19+
,bytesMin
20+
,bytesMax
21+
,heapPercentageMin
22+
,heapPercentageMax
23+
,treeView
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Community Detection - Local Clustering Coefficient - Statistics
2+
3+
CALL gds.localClusteringCoefficient.stats(
4+
$dependencies_projection + '-cleaned', {
5+
})
6+
YIELD averageClusteringCoefficient, nodeCount, preProcessingMillis, computeMillis, postProcessingMillis
7+
RETURN averageClusteringCoefficient, nodeCount, preProcessingMillis, computeMillis, postProcessingMillis
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Community Detection - Local Clustering Coefficient - Mutate
2+
3+
CALL gds.localClusteringCoefficient.mutate(
4+
$dependencies_projection + '-cleaned', {
5+
mutateProperty: $dependencies_projection_write_property
6+
})
7+
YIELD averageClusteringCoefficient, nodeCount, nodePropertiesWritten, preProcessingMillis, computeMillis, postProcessingMillis, mutateMillis
8+
RETURN averageClusteringCoefficient, nodeCount, nodePropertiesWritten, preProcessingMillis, computeMillis, postProcessingMillis, mutateMillis
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Community Detection - Local Clustering Coefficient - Stream
2+
3+
CALL gds.localClusteringCoefficient.stream(
4+
$dependencies_projection + '-cleaned', {
5+
})
6+
YIELD nodeId, localClusteringCoefficient
7+
WITH gds.util.asNode(nodeId) AS member
8+
,localClusteringCoefficient
9+
WITH coalesce(member.fqn, member.fileName, member.name) AS memberName
10+
,localClusteringCoefficient
11+
RETURN localClusteringCoefficient
12+
,memberName
13+
ORDER BY localClusteringCoefficient DESC, memberName ASC
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Community Detection - Local Clustering Coefficient - Stream Aggregated
2+
3+
CALL gds.localClusteringCoefficient.stream(
4+
$dependencies_projection + '-cleaned', {
5+
})
6+
YIELD nodeId, localClusteringCoefficient
7+
WITH gds.util.asNode(nodeId) AS member
8+
,localClusteringCoefficient
9+
WITH coalesce(member.fqn, member.fileName, member.name) AS memberName
10+
,localClusteringCoefficient
11+
WITH round(localClusteringCoefficient, 2) AS localClusteringCoefficient
12+
,collect(DISTINCT memberName)[0..9] AS memberNameExamples
13+
,count(DISTINCT memberName) AS memberCount
14+
RETURN localClusteringCoefficient
15+
,memberCount
16+
,memberNameExamples
17+
ORDER BY localClusteringCoefficient DESC, memberCount DESC
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Community Detection - Local Clustering Coefficient - Write
2+
3+
CALL gds.localClusteringCoefficient.write(
4+
$dependencies_projection + '-cleaned', {
5+
writeProperty: $dependencies_projection_write_property
6+
})
7+
YIELD averageClusteringCoefficient, nodeCount, nodePropertiesWritten, preProcessingMillis, computeMillis, postProcessingMillis, writeMillis
8+
RETURN averageClusteringCoefficient, nodeCount, nodePropertiesWritten, preProcessingMillis, computeMillis, postProcessingMillis, writeMillis

scripts/reports/CommunityCsv.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,41 @@ calculateCommunityMetrics() {
322322
# gds.modularity.stream ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 100
323323
}
324324

325+
# Calculates the Local Clustering Coefficient for each node in the projected graph.
326+
# It describes the likelihood that the neighbors of a node are also connected.
327+
#
328+
# Required Parameters:
329+
# - dependencies_projection=...
330+
# Name prefix for the in-memory projection name for dependencies. Example: "package"
331+
# - dependencies_projection_node=...
332+
# Label of the nodes that will be used for the projection. Example: "Package"
333+
# - dependencies_projection_weight_property=...
334+
# Name of the node property that contains the dependency weight. Example: "weight"
335+
calculateLocalClusteringCoefficient() {
336+
local COMMUNITY_DETECTION_CYPHER_DIR="${CYPHER_DIR}/Community_Detection"
337+
local PROJECTION_CYPHER_DIR="${CYPHER_DIR}/Dependencies_Projection"
338+
339+
local writePropertyName="dependencies_projection_write_property=communityLocalClusteringCoefficient"
340+
local writeLabelName="dependencies_projection_write_label=MaximumKCut"
341+
342+
# Statistics
343+
execute_cypher "${COMMUNITY_DETECTION_CYPHER_DIR}/Community_Detection_10a_LocalClusteringCoefficient_Estimate.cypher" "${@}" "${writePropertyName}"
344+
345+
# Run the algorithm and write the result into the in-memory projection ("mutate")
346+
execute_cypher "${COMMUNITY_DETECTION_CYPHER_DIR}/Community_Detection_10c_LocalClusteringCoefficient_Mutate.cypher" "${@}" "${writePropertyName}"
347+
348+
# Stream to CSV
349+
local nodeLabel
350+
nodeLabel=$( extractQueryParameter "dependencies_projection_node" "${@}")
351+
execute_cypher "${COMMUNITY_DETECTION_CYPHER_DIR}/Community_Detection_10d_LocalClusteringCoefficient_Stream_Aggregated.cypher" "${@}" "${writePropertyName}" > "${FULL_REPORT_DIRECTORY}/${nodeLabel}_Communities_Local_Clustering_Coefficient_Aggregated.csv"
352+
#execute_cypher "${PROJECTION_CYPHER_DIR}/Community_Detection_10d_LocalClusteringCoefficient_Stream.cypher" "${@}" > "${FULL_REPORT_DIRECTORY}/${nodeLabel}_Communities_Local_Clustering_Coefficient.csv"
353+
354+
# Update Graph (node properties and labels) using the already mutated property projection
355+
execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_9_Write_Mutated.cypher" "${@}" "${writePropertyName}"
356+
execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_10_Delete_Label.cypher" "${@}" "${writePropertyName}" "${writeLabelName}"
357+
execute_cypher "${PROJECTION_CYPHER_DIR}/Dependencies_11_Add_Label.cypher" "${@}" "${writePropertyName}" "${writeLabelName}"
358+
}
359+
325360
# Write modularity for Leiden communities
326361
#
327362
# Required Parameters:
@@ -366,6 +401,7 @@ detectCommunities() {
366401
time detectCommunitiesWithLeiden "${@}"
367402
time detectCommunitiesWithKCoreDecomposition "${@}"
368403
time detectCommunitiesWithApproximateMaximumKCut "${@}"
404+
time calculateLocalClusteringCoefficient "${@}"
369405
compareCommunityDetectionResults "${@}"
370406
listAllResults "${@}"
371407
}

0 commit comments

Comments
 (0)