Leiden

Glossary

Directed

Directed trait. The algorithm is well-defined on a directed graph.

Directed

Directed trait. The algorithm ignores the direction of the graph.

Directed

Directed trait. The algorithm does not run on a directed graph.

Undirected

Undirected trait. The algorithm is well-defined on an undirected graph.

Undirected

Undirected trait. The algorithm ignores the undirectedness of the graph.

Heterogeneous nodes

Heterogeneous nodes fully supported. The algorithm has the ability to distinguish between nodes of different types.

Heterogeneous nodes

Heterogeneous nodes allowed. The algorithm treats all selected nodes similarly regardless of their label.

Heterogeneous relationships

Heterogeneous relationships fully supported. The algorithm has the ability to distinguish between relationships of different types.

Heterogeneous relationships

Heterogeneous relationships allowed. The algorithm treats all selected relationships similarly regardless of their type.

Weighted relationships

Weighted trait. The algorithm supports a relationship property to be used as weight, specified via the relationshipWeightProperty configuration parameter.

Weighted relationships

Weighted trait. The algorithm treats each relationship as equally important, discarding the value of any relationship weight.

Introduction

The Leiden algorithm is an algorithm for detecting communities in large networks. The algorithm separates nodes into disjoint communities so as to maximize a modularity score for each community. Modularity quantifies the quality of an assignment of nodes to communities, that is how densely connected nodes in a community are, compared to how connected they would be in a random network.

The Leiden algorithm is a hierarchical clustering algorithm, that recursively merges communities into single nodes by greedily optimizing the modularity and the process repeats in the condensed graph. It modifies the Louvain algorithm to address some of its shortcomings, namely the case where some of the communities found by Louvain are not well-connected. This is achieved by periodically randomly breaking down communities into smaller well-connected ones.

For more information on this algorithm, see:

Running this algorithm requires sufficient memory availability. Before running this algorithm, we recommend that you read Memory Estimation.

Syntax

This section covers the syntax used to execute the Leiden algorithm in each of its execution modes. We are describing the named graph variant of the syntax. To learn more about general syntax variants, see Syntax overview.

Leiden syntax per mode
Run Leiden in stream mode on a named graph.
CALL gds.leiden.stream(
  graphName: String,
  configuration: Map
)
YIELD
  nodeId: Integer,
  communityId: Integer,
  intermediateCommunityIds: List of Integer
Table 1. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 2. Configuration
Name Type Default Optional Description

nodeLabels

List of String

['*']

yes

Filter the named graph using the given node labels. Nodes with any of the given labels will be included.

relationshipTypes

List of String

['*']

yes

Filter the named graph using the given relationship types. Relationships with any of the given types will be included.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm.

jobId

String

Generated internally

yes

An ID that can be provided to more easily track the algorithm’s progress.

logProgress

Boolean

true

yes

If disabled the progress percentage will not be logged.

relationshipWeightProperty

String

null

yes

Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted.

maxLevels

Integer

10

yes

The maximum number of levels in which the graph is clustered and then condensed.

gamma

Float

1.0

yes

Resolution parameter used when computing the modularity. Internally the value is divided by the number of relationships for an unweighted graph, or the sum of weights of all relationships otherwise. [1]

theta

Float

0.01

yes

Controls the randomness while breaking a community into smaller ones.

tolerance

Float

0.0001

yes

Minimum change in modularity between iterations. If the modularity changes less than the tolerance value, the result is considered stable and the algorithm returns.

includeIntermediateCommunities

Boolean

false

yes

Indicates whether to write intermediate communities. If set to false, only the final community is persisted.

seedProperty

String

n/a

yes

Used to set the initial community for a node. The property value needs to be a non-negative number.

minCommunitySize

Integer

0

yes

Only nodes inside communities larger or equal the given value are returned.

1. Higher resolutions lead to more communities, while lower resolutions lead to fewer communities.

Table 3. Results
Name Type Description

nodeId

Integer

Node ID.

communityId

Integer

The community ID of the final level.

intermediateCommunityIds

List of Integer

Community IDs for each level. Null if includeIntermediateCommunities is set to false.

Run Leiden in stats mode on a named graph.
CALL gds.leiden.stats(
  graphName: String,
  configuration: Map
)
YIELD
  preProcessingMillis: Integer,
  computeMillis: Integer,
  postProcessingMillis: Integer,
  communityCount: Integer,
  ranLevels: Integer,
  modularity: Float,
  modularities: List of Float,
  nodeCount: Integer,
  didConverge: Boolean,
  communityDistribution: Map,
  configuration: Map
Table 4. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 5. Configuration
Name Type Default Optional Description

nodeLabels

List of String

['*']

yes

Filter the named graph using the given node labels. Nodes with any of the given labels will be included.

relationshipTypes

List of String

['*']

yes

Filter the named graph using the given relationship types. Relationships with any of the given types will be included.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm.

jobId

String

Generated internally

yes

An ID that can be provided to more easily track the algorithm’s progress.

logProgress

Boolean

true

yes

If disabled the progress percentage will not be logged.

relationshipWeightProperty

String

null

yes

Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted.

maxLevels

Integer

10

yes

The maximum number of levels in which the graph is clustered and then condensed.

gamma

Float

1.0

yes

Resolution parameter used when computing the modularity. Internally the value is divided by the number of relationships for an unweighted graph, or the sum of weights of all relationships otherwise. [2]

theta

Float

0.01

yes

Controls the randomness while breaking a community into smaller ones.

tolerance

Float

0.0001

yes

Minimum change in modularity between iterations. If the modularity changes less than the tolerance value, the result is considered stable and the algorithm returns.

includeIntermediateCommunities

Boolean

false

yes

Indicates whether to write intermediate communities. If set to false, only the final community is persisted.

seedProperty

String

n/a

yes

Used to set the initial community for a node. The property value needs to be a non-negative number.

2. Higher resolutions lead to more communities, while lower resolutions lead to fewer communities.

Table 6. Results
Name Type Description

preProcessingMillis

Integer

Milliseconds for preprocessing the data.

computeMillis

Integer

Milliseconds for running the algorithm.

postProcessingMillis

Integer

Milliseconds for computing percentiles and community count.

communityCount

Integer

The number of communities found.

ranLevels

Integer

The number of levels the algorithm actually ran.

modularity

Float

The final modularity score.

modularities

List of Float

The modularity scores for each level.

nodeCount

Integer

The number of nodes in the graph.

didConverge

Boolean

Indicates if the algorithm converged.

communityDistribution

Map

Map containing min, max, mean as well as p1, p5, p10, p25, p50, p75, p90, p95, p99 and p999 percentile values of community size for the last level.

configuration

Map

The configuration used for running the algorithm.

Run Leiden in mutate mode on a named graph.
CALL gds.leiden.mutate(
  graphName: String,
  configuration: Map
)
YIELD
  preProcessingMillis: Integer,
  computeMillis: Integer,
  mutateMillis: Integer,
  postProcessingMillis: Integer,
  communityCount: Integer,
  ranLevels: Integer,
  modularity: Float,
  modularities: List of Float,
  nodeCount: Integer,
  didConverge: Boolean,
  nodePropertiesWritten: Integer,
  communityDistribution: Map,
  configuration: Map
Table 7. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 8. Configuration
Name Type Default Optional Description

mutateProperty

String

n/a

no

The node property in the GDS graph to which the community ID is written.

nodeLabels

List of String

['*']

yes

Filter the named graph using the given node labels.

relationshipTypes

List of String

['*']

yes

Filter the named graph using the given relationship types.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm.

jobId

String

Generated internally

yes

An ID that can be provided to more easily track the algorithm’s progress.

relationshipWeightProperty

String

null

yes

Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted.

maxLevels

Integer

10

yes

The maximum number of levels in which the graph is clustered and then condensed.

gamma

Float

1.0

yes

Resolution parameter used when computing the modularity. Internally the value is divided by the number of relationships for an unweighted graph, or the sum of weights of all relationships otherwise. [3]

theta

Float

0.01

yes

Controls the randomness while breaking a community into smaller ones.

tolerance

Float

0.0001

yes

Minimum change in modularity between iterations. If the modularity changes less than the tolerance value, the result is considered stable and the algorithm returns.

includeIntermediateCommunities

Boolean

false

yes

Indicates whether to write intermediate communities. If set to false, only the final community is persisted.

seedProperty

String

n/a

yes

Used to set the initial community for a node. The property value needs to be a non-negative number.

3. Higher resolutions lead to more communities, while lower resolutions lead to fewer communities.

Table 9. Results
Name Type Description

preProcessingMillis

Integer

Milliseconds for preprocessing the data.

computeMillis

Integer

Milliseconds for running the algorithm.

mutateMillis

Integer

Milliseconds for adding properties to the projected graph.

postProcessingMillis

Integer

Milliseconds for computing percentiles and community count.

communityCount

Integer

The number of communities found.

ranLevels

Integer

The number of levels the algorithm actually ran.

modularity

Float

The final modularity score.

modularities

List of Float

The modularity scores for each level.

nodeCount

Integer

Number of nodes in the graph.

didConverge

Boolean

Indicates if the algorithm converged.

nodePropertiesWritten

Integer

Number of properties added to the projected graph.

communityDistribution

Map

Map containing min, max, mean as well as p1, p5, p10, p25, p50, p75, p90, p95, p99 and p999 percentile values of community size for the last level.

configuration

Map

The configuration used for running the algorithm.

Run Leiden in write mode on a named graph.
CALL gds.leiden.write(
  graphName: String,
  configuration: Map
)
YIELD
  preProcessingMillis: Integer,
  computeMillis: Integer,
  writeMillis: Integer,
  postProcessingMillis: Integer,
  communityCount: Integer,
  ranLevels: Integer,
  modularity: Float,
  modularities: List of Float,
  nodeCount: Integer,
  didConverge: Boolean,
  nodePropertiesWritten: Integer,
  communityDistribution: Map,
  configuration: Map
Table 10. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 11. Configuration
Name Type Default Optional Description

nodeLabels

List of String

['*']

yes

Filter the named graph using the given node labels. Nodes with any of the given labels will be included.

relationshipTypes

List of String

['*']

yes

Filter the named graph using the given relationship types. Relationships with any of the given types will be included.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm.

jobId

String

Generated internally

yes

An ID that can be provided to more easily track the algorithm’s progress.

logProgress

Boolean

true

yes

If disabled the progress percentage will not be logged.

writeConcurrency

Integer

value of 'concurrency'

yes

The number of concurrent threads used for writing the result to Neo4j.

writeProperty

String

n/a

no

The node property in the Neo4j database to which the community ID is written.

relationshipWeightProperty

String

null

yes

Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted.

maxLevels

Integer

10

yes

The maximum number of levels in which the graph is clustered and then condensed.

gamma

Float

1.0

yes

Resolution parameter used when computing the modularity. Internally the value is divided by the number of relationships for an unweighted graph, or the sum of weights of all relationships otherwise. [4]

theta

Float

0.01

yes

Controls the randomness while breaking a community into smaller ones.

tolerance

Float

0.0001

yes

Minimum change in modularity between iterations. If the modularity changes less than the tolerance value, the result is considered stable and the algorithm returns.

includeIntermediateCommunities

Boolean

false

yes

Indicates whether to write intermediate communities. If set to false, only the final community is persisted.

seedProperty

String

n/a

yes

Used to set the initial community for a node. The property value needs to be a non-negative number.

minCommunitySize

Integer

0

yes

Only community ids of communities with a size greater than or equal to the given value are written to Neo4j.

4. Higher resolutions lead to more communities, while lower resolutions lead to fewer communities.

Table 12. Results
Name Type Description

preProcessingMillis

Integer

Milliseconds for preprocessing the data.

computeMillis

Integer

Milliseconds for running the algorithm.

writeMillis

Integer

Milliseconds for adding properties to the projected graph.

postProcessingMillis

Integer

Milliseconds for computing percentiles and community count.

communityCount

Integer

The number of communities found.

ranLevels

Integer

The number of levels the algorithm actually ran.

modularity

Float

The final modularity score.

modularities

List of Float

The modularity scores for each level.

nodeCount

Integer

Number of nodes in the graph.

didConverge

Boolean

Indicates if the algorithm converged.

nodePropertiesWritten

Integer

Number of properties added to the Neo4j database.

communityDistribution

Map

Map containing min, max, mean as well as p1, p5, p10, p25, p50, p75, p90, p95, p99 and p999 percentile values of community size for the last level.

configuration

Map

The configuration used for running the algorithm.

Examples

All the examples below should be run in an empty database.

The examples use Cypher projections as the norm. Native projections will be deprecated in a future release.

In this section we will show examples of running the Leiden community detection algorithm on a concrete graph. The intention is to illustrate what the results look like and to provide a guide in how to make use of the algorithm in a real setting. We will do this on a small social network graph of a handful nodes connected in a particular pattern. The example graph looks like this:

Visualization of the example graph
The following Cypher statement will create the example graph in the Neo4j database:
CREATE
  (nAlice:User {name: 'Alice', seed: 42}),
  (nBridget:User {name: 'Bridget', seed: 42}),
  (nCharles:User {name: 'Charles', seed: 42}),
  (nDoug:User {name: 'Doug'}),
  (nMark:User {name: 'Mark'}),
  (nMichael:User {name: 'Michael'}),

  (nAlice)-[:LINK {weight: 1}]->(nBridget),
  (nAlice)-[:LINK {weight: 1}]->(nCharles),
  (nCharles)-[:LINK {weight: 1}]->(nBridget),

  (nAlice)-[:LINK {weight: 5}]->(nDoug),

  (nMark)-[:LINK {weight: 1}]->(nDoug),
  (nMark)-[:LINK {weight: 1}]->(nMichael),
  (nMichael)-[:LINK {weight: 1}]->(nMark);

This graph has two clusters of Users, that are closely connected. These clusters are connected by a single edge. The relationship property weight determines the strength of each respective relationship between nodes.

We can now project the graph and store it in the graph catalog. We load the LINK relationships with orientation set to UNDIRECTED as this works best with the Leiden algorithm.

The following statement will project the graph and store it in the graph catalog.
MATCH (source:User)-[r:LINK]->(target:User)
RETURN gds.graph.project(
  'myGraph',
  source,
  target,
  {
    sourceNodeProperties: source { .seed },
    targetNodeProperties: target { .seed },
    relationshipProperties: r { .weight }
  },
  { undirectedRelationshipTypes: ['*'] }
)

In the following examples we will demonstrate using the Leiden algorithm on this graph.

Memory Estimation

First off, we will estimate the cost of running the algorithm using the estimate procedure. This can be done with any execution mode. We will use the write mode in this example. Estimating the algorithm is useful to understand the memory impact that running the algorithm on your graph will have. When you later actually run the algorithm in one of the execution modes the system will perform an estimation. If the estimation shows that there is a very high probability of the execution going over its memory limitations, the execution is prohibited. To read more about this, see Automatic estimation and execution blocking.

For more details on estimate in general, see Memory Estimation.

The following will estimate the memory requirements for running the algorithm in write mode:
CALL gds.leiden.write.estimate('myGraph', {writeProperty: 'communityId', randomSeed: 19})
YIELD nodeCount, relationshipCount, requiredMemory
Table 13. Results
nodeCount relationshipCount requiredMemory

6

14

"[551 KiB ... 551 KiB]"

Stream

In the stream execution mode, the algorithm returns the community ID for each node. This allows us to inspect the results directly or post-process them in Cypher without any side effects.

For more details on the stream mode in general, see Stream.

The following will run the algorithm and stream results:
CALL gds.leiden.stream('myGraph', { randomSeed: 19 })
YIELD nodeId, communityId
RETURN gds.util.asNode(nodeId).name AS name, communityId
ORDER BY name ASC
Table 14. Results
name communityId

"Alice"

1

"Bridget"

1

"Charles"

1

"Doug"

5

"Mark"

5

"Michael"

5

We use default values for the procedure configuration parameter. The maxLevels is set to 10, and the gamma, theta parameters are set to 1.0 and 0.01 respectively.

Stats

In the stats execution mode, the algorithm returns a single row containing a summary of the algorithm result. This execution mode does not have any side effects. It can be useful for evaluating algorithm performance by inspecting the computeMillis return item. In the examples below we will omit returning the timings. The full signature of the procedure can be found in the syntax section.

For more details on the stats mode in general, see Stats.

The following will run the algorithm and returns the result in form of statistical and measurement values
CALL gds.leiden.stats('myGraph', { randomSeed: 19 })
YIELD communityCount
Table 15. Results
communityCount

2

Mutate

The mutate execution mode extends the stats mode with an important side effect: updating the named graph with a new node property containing the community ID for that node. The name of the new property is specified using the mandatory configuration parameter mutateProperty. The result is a single summary row, similar to stats, but with some additional metrics. The mutate mode is especially useful when multiple algorithms are used in conjunction.

For more details on the mutate mode in general, see Mutate.

The following will run the algorithm and store the results in myGraph:
CALL gds.leiden.mutate('myGraph', { mutateProperty: 'communityId', randomSeed: 19 })
YIELD communityCount
Table 16. Results
communityCount

2

In mutate mode, only a single row is returned by the procedure. The result contains meta information, like the number of identified communities. The result is written to the GDS in-memory graph instead of the Neo4j database.

Write

The write execution mode extends the stats mode with an important side effect: writing the community ID for each node as a property to the Neo4j database. The name of the new property is specified using the mandatory configuration parameter writeProperty. The result is a single summary row, similar to stats, but with some additional metrics. The write mode enables directly persisting the results to the database.

For more details on the write mode in general, see Write.

The following will run the algorithm and store the results in the Neo4j database:
CALL gds.leiden.write('myGraph', { writeProperty: 'communityId', randomSeed: 19 })
YIELD communityCount, nodePropertiesWritten
Table 17. Results
communityCount nodePropertiesWritten

2

6

In write mode, only a single row is returned by the procedure. The result contains meta information, like the number of identified communities. The result is written to the Neo4j database instead of the GDS in-memory graph.

Weighted

The Leiden algorithm can also run on weighted graphs, taking the given relationship weights into concern when calculating the modularity.

The following will run the algorithm on a weighted graph and stream results:
CALL gds.leiden.stream('myGraph', { relationshipWeightProperty: 'weight', randomSeed: 19 })
YIELD nodeId, communityId
RETURN gds.util.asNode(nodeId).name AS name, communityId
ORDER BY name ASC
Table 18. Results
name communityId

"Alice"

4

"Bridget"

1

"Charles"

1

"Doug"

4

"Mark"

5

"Michael"

5

Using the weighted relationships, we see that Alice and Doug have formed their own community, as their link is much stronger than all the others.

Using intermediate communities

As described before, Leiden is a hierarchical clustering algorithm. That means that after every clustering step all nodes that belong to the same cluster are reduced to a single node. Relationships between nodes of the same cluster become self-relationships, relationships to nodes of other clusters connect to the clusters representative. This condensed graph is then used to run the next level of clustering. The process is repeated until the clusters are stable.

In order to demonstrate this iterative behavior, we need to construct a more complex graph.

CREATE (a:Node {name: 'a'})
CREATE (b:Node {name: 'b'})
CREATE (c:Node {name: 'c'})
CREATE (d:Node {name: 'd'})
CREATE (e:Node {name: 'e'})
CREATE (f:Node {name: 'f'})
CREATE (g:Node {name: 'g'})
CREATE (h:Node {name: 'h'})
CREATE (i:Node {name: 'i'})
CREATE (j:Node {name: 'j'})
CREATE (k:Node {name: 'k'})
CREATE (l:Node {name: 'l'})
CREATE (m:Node {name: 'm'})
CREATE (n:Node {name: 'n'})
CREATE (x:Node {name: 'x'})

CREATE (a)-[:TYPE]->(b)
CREATE (a)-[:TYPE]->(d)
CREATE (a)-[:TYPE]->(f)
CREATE (b)-[:TYPE]->(d)
CREATE (b)-[:TYPE]->(x)
CREATE (b)-[:TYPE]->(g)
CREATE (b)-[:TYPE]->(e)
CREATE (c)-[:TYPE]->(x)
CREATE (c)-[:TYPE]->(f)
CREATE (d)-[:TYPE]->(k)
CREATE (e)-[:TYPE]->(x)
CREATE (e)-[:TYPE]->(f)
CREATE (e)-[:TYPE]->(h)
CREATE (f)-[:TYPE]->(g)
CREATE (g)-[:TYPE]->(h)
CREATE (h)-[:TYPE]->(i)
CREATE (h)-[:TYPE]->(j)
CREATE (i)-[:TYPE]->(k)
CREATE (j)-[:TYPE]->(k)
CREATE (j)-[:TYPE]->(m)
CREATE (j)-[:TYPE]->(n)
CREATE (k)-[:TYPE]->(m)
CREATE (k)-[:TYPE]->(l)
CREATE (l)-[:TYPE]->(n)
CREATE (m)-[:TYPE]->(n);
The following statement will project the graph and store it in the graph catalog.
MATCH (source:Node)
OPTIONAL MATCH (source)-[r:TYPE]->(target:Node)
RETURN gds.graph.project(
  'myGraph2',
  source,
  target,
  {},
  { undirectedRelationshipTypes: ['*'] }
)

Stream intermediate communities

The following will run the algorithm and stream results including intermediate communities:
CALL gds.leiden.stream('myGraph2', {
  randomSeed: 23,
  includeIntermediateCommunities: true,
  concurrency: 1
})
YIELD nodeId, communityId, intermediateCommunityIds
RETURN gds.util.asNode(nodeId).name AS name, communityId, intermediateCommunityIds
ORDER BY name ASC
Table 19. Results
name communityId intermediateCommunityIds

"a"

4

[2, 4]

"b"

4

[2, 4]

"c"

5

[7, 5]

"d"

4

[2, 4]

"e"

5

[6, 5]

"f"

5

[7, 5]

"g"

5

[7, 5]

"h"

5

[11, 5]

"i"

5

[11, 5]

"j"

1

[12, 1]

"k"

1

[12, 1]

"l"

1

[12, 1]

"m"

1

[12, 1]

"n"

1

[12, 1]

"x"

5

[6, 5]

Seeded

It is possible to run the Louvain algorithm incrementally, by providing a seed property. If specified, the seed property provides an initial community mapping for a subset of the loaded nodes. The algorithm will try to keep the seeded community IDs.

The following will run the algorithm and stream results for a seeded graph:
CALL gds.leiden.stream('myGraph', { seedProperty: 'seed' })
YIELD nodeId, communityId, intermediateCommunityIds
RETURN gds.util.asNode(nodeId).name AS name, communityId, intermediateCommunityIds
ORDER BY name ASC
Table 20. Results
name communityId intermediateCommunityIds

"Alice"

42

null

"Bridget"

42

null

"Charles"

42

null

"Doug"

45

null

"Mark"

45

null

"Michael"

45

null

As can be seen, using the seeded graph, node Alice keeps its initial community ID of 42. The other community has been assigned a new community ID which is guaranteed to be larger than the largest seeded community ID. Note that the consecutiveIds configuration option cannot be used in combination with seeding in order to retain the seeding values

Mutate intermediate communities

The following will run the algorithm and mutate the in-memory-graph using the intermediate communities:
CALL gds.leiden.mutate('myGraph2', {
  mutateProperty: 'intermediateCommunities',
  randomSeed: 23,
  includeIntermediateCommunities: true,
  concurrency: 1
})
YIELD communityCount, modularity, modularities
Table 21. Results
communityCount modularity modularities

3

0.3624

[0.3296, 0.3624]

The following stream the mutated property from the in-memory graph:
CALL gds.graph.nodeProperty.stream('myGraph2', 'intermediateCommunities')
YIELD nodeId, propertyValue
RETURN
  gds.util.asNode(nodeId).name AS name,
  toIntegerList(propertyValue) AS intermediateCommunities
ORDER BY name ASC
Table 22. Results
name intermediateCommunities

"a"

[2, 4]

"b"

[2, 4]

"c"

[7, 5]

"d"

[2, 4]

"e"

[6, 5]

"f"

[7, 5]

"g"

[7, 5]

"h"

[11, 5]

"i"

[11, 5]

"j"

[12, 1]

"k"

[12, 1]

"l"

[12, 1]

"m"

[12, 1]

"n"

[12, 1]

"x"

[6, 5]

Write intermediate communities

The following will run the algorithm and write the intermediate communities to the Neo4j database:
CALL gds.leiden.write('myGraph2', {
  writeProperty: 'intermediateCommunities',
  randomSeed: 19,
  includeIntermediateCommunities: true,
  concurrency: 1
})
YIELD communityCount, modularity, modularities
Table 23. Results
communityCount modularity modularities

3

0.3624

[0.3296, 0.3624]

The following stream the written property from the Neo4j database:
MATCH (n:Node) RETURN n.name AS name, toIntegerList(n.intermediateCommunities) AS intermediateCommunities
ORDER BY name ASC
Table 24. Results
name intermediateCommunities

"a"

[2, 4]

"b"

[2, 4]

"c"

[7, 5]

"d"

[2, 4]

"e"

[6, 5]

"f"

[7, 5]

"g"

[7, 5]

"h"

[11, 5]

"i"

[11, 5]

"j"

[12, 1]

"k"

[12, 1]

"l"

[12, 1]

"m"

[12, 1]

"n"

[12, 1]

"x"

[6, 5]