Skip to content

Commit 2185cee

Browse files
vnickolovjjaderberg
andcommitted
Add examples for mutate and write intermediate communities in Louvain
Co-authored-by: Jonatan Jäderberg <[email protected]>
1 parent 7e17c4f commit 2185cee

File tree

2 files changed

+121
-2
lines changed

2 files changed

+121
-2
lines changed

doc-test/src/test/java/org/neo4j/gds/doc/LouvainDocTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.neo4j.gds.doc;
2121

2222
import org.neo4j.gds.catalog.GraphProjectProc;
23+
import org.neo4j.gds.catalog.GraphStreamNodePropertiesProc;
2324
import org.neo4j.gds.functions.AsNodeFunc;
2425
import org.neo4j.gds.louvain.LouvainMutateProc;
2526
import org.neo4j.gds.louvain.LouvainStatsProc;
@@ -42,6 +43,7 @@ protected List<Class<?>> procedures() {
4243
LouvainWriteProc.class,
4344
LouvainStatsProc.class,
4445
LouvainMutateProc.class,
46+
GraphStreamNodePropertiesProc.class,
4547
GraphProjectProc.class
4648
);
4749
}

doc/modules/ROOT/pages/algorithms/louvain.adoc

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,7 @@ The other community is assigned a new community ID, which is guaranteed to be la
495495
Note that the `consecutiveIds` configuration option cannot be used in combination with seeding in order to retain the seeding values.
496496

497497

498-
[[algorithms-louvain-examples-stream-intermediate]]
499-
=== Stream intermediate communities
498+
=== Using intermediate communities
500499

501500
As described before, Louvain is a hierarchical clustering algorithm.
502501
That means that after every clustering step all nodes that belong to the same cluster are reduced to a single node.
@@ -569,6 +568,10 @@ CALL gds.graph.project(
569568
)
570569
----
571570

571+
572+
[[algorithms-louvain-examples-stream-intermediate]]
573+
==== Stream intermediate communities
574+
572575
[role=query-example]
573576
--
574577
.The following run the algorithm and stream results including the intermediate communities:
@@ -603,3 +606,117 @@ ORDER BY name ASC
603606
--
604607

605608
In this example graph, after the first iteration we see 4 clusters, which in the second iteration are reduced to three.
609+
610+
611+
[[algorithms-louvain-examples-mutate-intermediate]]
612+
==== Mutate intermediate communities
613+
614+
[role=query-example, group=mutateIntermediateCommunities]
615+
--
616+
.The following run the algorithm and mutate the in-memory graph:
617+
[source, cypher, role=noplay]
618+
----
619+
CALL gds.louvain.mutate('myGraph2', {
620+
mutateProperty: 'intermediateCommunities',
621+
includeIntermediateCommunities: true
622+
})
623+
YIELD communityCount, modularity, modularities
624+
----
625+
626+
.Results
627+
[opts="header"]
628+
|===
629+
| communityCount | modularity | modularities
630+
| 3 | 0.3816 | [0.37599999999999995, 0.3816]
631+
|===
632+
--
633+
634+
[role=query-example, group=mutateIntermediateCommunities]
635+
--
636+
.The following stream the mutated property from the in-memory graph:
637+
[source, cypher, role=noplay]
638+
----
639+
CALL gds.graph.streamNodeProperty('myGraph2', 'intermediateCommunities')
640+
YIELD nodeId, propertyValue
641+
RETURN
642+
gds.util.asNode(nodeId).name AS name,
643+
toIntegerList(propertyValue) AS intermediateCommunities
644+
ORDER BY name ASC
645+
----
646+
647+
.Results
648+
[opts="header"]
649+
|===
650+
| name | intermediateCommunities
651+
| "a" | [3, 14]
652+
| "b" | [3, 14]
653+
| "c" | [14, 14]
654+
| "d" | [3, 14]
655+
| "e" | [14, 14]
656+
| "f" | [14, 14]
657+
| "g" | [7, 7]
658+
| "h" | [7, 7]
659+
| "i" | [7, 7]
660+
| "j" | [12, 12]
661+
| "k" | [12, 12]
662+
| "l" | [12, 12]
663+
| "m" | [12, 12]
664+
| "n" | [12, 12]
665+
| "x" | [14, 14]
666+
|===
667+
--
668+
669+
670+
[[algorithms-louvain-examples-write-intermediate]]
671+
==== Write intermediate communities
672+
673+
[role=query-example, group=writeIntermediateCommunities]
674+
--
675+
.The following run the algorithm and write to the Neo4j database:
676+
[source, cypher, role=noplay]
677+
----
678+
CALL gds.louvain.write('myGraph2', {
679+
writeProperty: 'intermediateCommunities',
680+
includeIntermediateCommunities: true
681+
})
682+
YIELD communityCount, modularity, modularities
683+
----
684+
685+
.Results
686+
[opts="header"]
687+
|===
688+
| communityCount | modularity | modularities
689+
| 3 | 0.3816 | [0.37599999999999995, 0.3816]
690+
|===
691+
--
692+
693+
[role=query-example, group=writeIntermediateCommunities]
694+
--
695+
.The following stream the written property from the Neo4j database:
696+
[source, cypher, role=noplay]
697+
----
698+
MATCH (n:Node) RETURN n.name AS name, toIntegerList(n.intermediateCommunities) AS intermediateCommunities
699+
ORDER BY name ASC
700+
----
701+
702+
.Results
703+
[opts="header"]
704+
|===
705+
| name | intermediateCommunities
706+
| "a" | [3, 14]
707+
| "b" | [3, 14]
708+
| "c" | [14, 14]
709+
| "d" | [3, 14]
710+
| "e" | [14, 14]
711+
| "f" | [14, 14]
712+
| "g" | [7, 7]
713+
| "h" | [7, 7]
714+
| "i" | [7, 7]
715+
| "j" | [12, 12]
716+
| "k" | [12, 12]
717+
| "l" | [12, 12]
718+
| "m" | [12, 12]
719+
| "n" | [12, 12]
720+
| "x" | [14, 14]
721+
|===
722+
--

0 commit comments

Comments
 (0)