NETWORK.COMMUNITIES OpenBI
Communities of nodes (Louvain, Leiden, Walktrap and others), with their modularity.
Group: Networks. OpenBI’s own: DAX has no function of this name.
Syntax
NETWORK.COMMUNITIES ( <links>, <from>, <to> [, <weight>] [, <method>] [, <resolution>] )
| Parameter | Type | Description |
|---|---|---|
links | Table | The rows that make the network, one link a row: a table of the model or a table expression, as the filters leave it. |
from | Expression evaluated for each row | One end of each row's link, such as a payer, a customer or a place. |
to | Expression evaluated for each row | The other end of each row's link. |
weight | Expression optional, evaluated for each row | How heavy each row's link is, such as an amount or a count; never negative. Left out, or given as the constant BLANK (), every row weighs 1. |
method | Text optional | How the communities are found: "louvain" (when left out), "leiden", "infomap", "walktrap", "fastgreedy", "edgebetweenness" or "labelprop". |
resolution | Number optional | For Louvain and Leiden: above 1 for more, smaller communities, below 1 for fewer, larger ones. 1 when left out. |
Returns
Table. A row a node, with the columns Node, Community, Size (the nodes in its community) and Modularity.
Remarks
- The links are taken both ways, with their weights.
- Communities are numbered from 1, the largest; between two of the same size, the one with the node that comes first in the nodes' order.
- Modularity measures how much more the nodes link inside their communities than chance would have them, for the whole split (at resolution 1), so it is the same on every row: above 0.3 is a clear structure.
- The same rows always give the same communities: the random choices some methods make are fixed.
- The rows come out in the order of the nodes' values: numbers from the smallest, then text by character code with capitals read as small letters (A and a together, Ä after z), then dates, then FALSE and TRUE. Rows that come in another order give the same result, communities and ties included; up to 0.3.76 the order the rows came in could change them.
- Edge betweenness is slow: it takes networks of up to 5,000 links. Louvain and Leiden suit large networks.
- A network without links gives every node a community of its own.
- Rows where an end is blank, or where both ends are the same node, add no link; the end that is there still counts as a node.
Compared with DAX
An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.
Examples
Two groups of friends
The four around Di and Fay, and the triangle of Ann, Bo and Cy.
EVALUATE
VAR Links =
DATATABLE (
"From", STRING, "To", STRING,
{
{ "Ann", "Bo" }, { "Ann", "Cy" }, { "Bo", "Cy" }, { "Cy", "Di" },
{ "Di", "Ed" }, { "Ed", "Fay" }, { "Di", "Fay" }, { "Fay", "Gus" }
}
)
RETURN
NETWORK.COMMUNITIES ( Links, [From], [To] )
| Node | Community | Size | Modularity |
|---|---|---|---|
| Ann | 2 | 3 | 0.3671875 |
| Bo | 2 | 3 | 0.3671875 |
| Cy | 2 | 3 | 0.3671875 |
| Di | 1 | 4 | 0.3671875 |
| Ed | 1 | 4 | 0.3671875 |
| Fay | 1 | 4 | 0.3671875 |
| Gus | 1 | 4 | 0.3671875 |
A higher resolution
At resolution 3, Louvain cuts the network into smaller pieces, at a lower modularity.
EVALUATE
VAR Links =
DATATABLE (
"From", STRING, "To", STRING,
{
{ "Ann", "Bo" }, { "Ann", "Cy" }, { "Bo", "Cy" }, { "Cy", "Di" },
{ "Di", "Ed" }, { "Ed", "Fay" }, { "Di", "Fay" }, { "Fay", "Gus" }
}
)
RETURN
NETWORK.COMMUNITIES ( Links, [From], [To], , "louvain", 3 )
| Node | Community | Size | Modularity |
|---|---|---|---|
| Ann | 1 | 2 | 0.0390625 |
| Bo | 1 | 2 | 0.0390625 |
| Cy | 3 | 1 | 0.0390625 |
| Di | 4 | 1 | 0.0390625 |
| Ed | 5 | 1 | 0.0390625 |
| Fay | 2 | 2 | 0.0390625 |
| Gus | 2 | 2 | 0.0390625 |
Neighbourhoods of the town
The places linked by a drive of eight minutes or less fall into three neighbourhoods.
EVALUATE
NETWORK.COMMUNITIES ( FILTER ( Distances, Distances[Minutes] <= 8 ), Distances[From], Distances[To] )
ORDER BY [Community], [Node]
| Node | Community | Size | Modularity |
|---|---|---|---|
| Depot Alnabru | 1 | 7 | 0.416428571428571 |
| Shop Bjørvika | 1 | 7 | 0.416428571428571 |
| Shop Grønland | 1 | 7 | 0.416428571428571 |
| Shop Grünerløkka | 1 | 7 | 0.416428571428571 |
| Shop Kampen | 1 | 7 | 0.416428571428571 |
| Shop Tøyen | 1 | 7 | 0.416428571428571 |
| Shop Vålerenga | 1 | 7 | 0.416428571428571 |
| Shop Nydalen | 2 | 6 | 0.416428571428571 |
| Shop Sagene | 2 | 6 | 0.416428571428571 |
| Shop St. Hanshaugen | 2 | 6 | 0.416428571428571 |
| Shop Storo | 2 | 6 | 0.416428571428571 |
| Shop Torshov | 2 | 6 | 0.416428571428571 |
| Shop Ullevål | 2 | 6 | 0.416428571428571 |
| Shop Frogner | 3 | 3 | 0.416428571428571 |
| Shop Majorstuen | 3 | 3 | 0.416428571428571 |
| Shop Skøyen | 3 | 3 | 0.416428571428571 |
Related functions
NETWORK.NODES, NETWORK.GRAPH, NETWORK.CLIQUES, NETWORK.EMBED.
Open Graph, OpenBI's graph library, does the work: community_multilevel, strength, community_leiden, community_walktrap, community_fastgreedy, community_label_propagation, community_infomap, community_edge_betweenness, modularity. See the OAX network functions and Open Graph.