Triangle Counting / Clustering Coefficient

The alpha procedures from the namespace algo.triangleCount are being replaced by a pair of procedure namespaces:

Everything relating to clustering coefficients has been extracted into a separate algorithm backing gds.localClusteringCoefficient procedures. To compute both triangle count and local clustering coefficient values multiple procedures will be necessary.

The triangle enumeration procedure algo.triangles.stream() has been renamed to gds.alpha.triangles().

Table 1. Common changes in Configuration
Graph Algorithms v3.5 Graph Data Science v1.2

direction

-

concurrency

concurrency

readConcurrency

readConcurrency [1]

writeConcurrency

writeConcurrency [2]

writeProperty

writeProperty [2]

write

-

graph

-

1. Only when using anonymous graph

2. Only for write mode

Table 2. Changes in YIELD fields of algo.triangleCount
Graph Algorithms v3.5 Graph Data Science v1.2

nodeId

nodeId [3]

triangles

triangleCount [3]

triangleCount

globalTriangleCount [4]

nodeCount

nodeCount [4]

averageClusteringCoefficient [5]

-

clusteringCoefficientProperty [6]

-

loadMillis

createMillis

computeMillis

computeMillis

writeMillis

writeMillis

write

-

-

configuration [7]

writeProperty [8]

-

min, max, mean, p50, p75, p90, p95, p99, p999

-

3. Only for stream mode

4. Not present in stream mode

5. Moved to gds.localClusteringCoefficient

6. Moved as writeProperty to gds.localClusteringCoefficient

7. The configuration used to run the algorithm

8. Inlined into configuration

Table 3. TriangleCount Stream Mode
Graph Algorithms v3.5 Graph Data Science v1.2

Streaming triangle counts over named graph:

CALL algo.triangleCount.stream(null, null, {graph: 'myGraph'})
YIELD nodeId, triangles
CALL gds.triangleCount.stream('myGraph')
YIELD nodeId, triangleCount

Streaming local clustering coefficients over named graph:

CALL algo.triangleCount.stream(null, null, {graph: 'myGraph'})
YIELD nodeId, coefficient
CALL gds.localClusteringCoefficient.stream('myGraph')
YIELD nodeId, localClusteringCoefficient

Streaming both triangle counts and local clustering coefficients:

CALL algo.triangleCount.stream(null, null, {graph: 'myGraph'})
YIELD nodeId, triangles, coefficient
CALL gds.triangleCount.mutate('myGraph', {mutateProperty: 'tc'})
YIELD globalTriangleCount
CALL gds.localClusteringCoefficient.stream(
  'myGraph', {
    triangleCountProperty: 'tc'
}) YIELD nodeId, localClusteringCoefficient
WITH
  nodeId,
  localClusteringCoefficient,
  gds.util.nodeProperty('myGraph', nodeId, 'tc') AS triangleCount
RETURN nodeId, triangleCount, localClusteringCoefficient

Streaming triangle counts over anonymous graph:

CALL algo.triangleCount.stream(
  'MyLabel',
  'MY_RELATIONSHIP_TYPE'
)
CALL gds.triangleCount.stream({
  nodeProjection: 'MyLabel',
  relationshipProjection: {
    MY_RELATIONSHIP_TYPE: {
      orientation: 'UNDIRECTED'
    }
  }
})
Table 4. TriangleCount Write Mode
Graph Algorithms v3.5 Graph Data Science v1.2

Writing triangle counts from named graph:

CALL algo.triangleCount(null, null, {
  graph: 'myGraph',
  write: true,
  writeProperty: 'tc'
}) YIELD nodeCount, triangleCount
CALL gds.triangleCount.write('myGraph', {
  writeProperty: 'tc'
}) YIELD nodeCount, globalTriangleCount

Writing local clustering coefficients from named graph:

CALL algo.triangleCount(null, null, {
  graph: 'myGraph',
  write: true,
  clusteringCoefficientProperty: 'lcc'
}) YIELD nodeCount, averageClusteringCoefficient
CALL gds.localClusteringCoefficient.write('myGraph', {
  writeProperty: 'lcc'
}) YIELD nodeCount, averageClusteringCoefficient

Writing both triangle counts and local clustering coefficients:

CALL algo.triangleCount(null, null, {
  graph: 'myGraph',
  write: true,
  writeProperty: 'tc',
  clusteringCoefficientProperty: 'lcc'
}) YIELD nodeCount, triangleCount, averageClusteringCoefficient
CALL gds.triangleCount.mutate('myGraph', {
  mutateProperty: 'tc'
}) YIELD globalTriangleCount
CALL gds.localClusteringCoefficient.write('myGraph', {
  triangleCountProperty: 'tc',
  writeProperty: 'lcc'
}) YIELD nodeCount, averageClusteringCoefficient
CALL gds.graph.writeNodeProperties('myGraph', ['tc'])
YIELD propertiesWritten
RETURN nodeCount, globalTriangleCount, averageClusteringCoefficient