NETWORK.COMPARE OpenBI
How alike two partitions of the same nodes into communities are, such as two snapshots' (NMI, VI, adjusted Rand and more), over the nodes in both.
Group: Networks. OpenBI’s own: DAX has no function of this name.
Syntax
NETWORK.COMPARE ( <first>, <node>, <community>, <second>, <second node>, <second community> )
| Parameter | Type | Description |
|---|---|---|
first | Table | One way the nodes fall into communities, a row a node: a table of the model, or what NETWORK.COMMUNITIES or NETWORK.NODES returns. |
node | Expression evaluated for each row | The node of each row of first. |
community | Expression evaluated for each row | Its community: a number, a text or any value; only which nodes share one counts. |
second | Table | The other way, such as the same network's a month later, or another method's. |
second node | Expression evaluated for each row | The node of each row of second. |
second community | Expression evaluated for each row | Its community. |
Returns
Table. One row. Its columns: Nodes, Only in first and Only in second; Communities in first and Communities in second; NMI, VI, ARI, Rand and Split-join.
Remarks
- The measures are taken over the nodes in both tables (Nodes); Only in first and Only in second count the others, such as customers who left or came. Communities in first and in second count the communities among the nodes in both.
- NMI, the normalized mutual information, is 1 when the two are the same and 0 when one says nothing about the other. VI, the variation of information, is 0 when they are the same and grows as they differ (in natural logarithms).
- Rand is the share of the pairs of nodes the two agree on: together in both, or apart in both. ARI, the adjusted Rand index, is 1 when the two are the same and about 0 when they agree no more than chance would; it can be below 0.
- Split-join counts nodes: for each community of either table, its nodes outside the community of the other table it shares the most with, all added up. 0 when the two are the same.
- Only which nodes are together counts, not the communities' numbers: 1 and 2 in one table, 7 and 5 in the other can be the same.
- With fewer than two nodes in both, Rand and ARI are blank; with none, every measure is.
- A row whose node or community is blank is left out. A node in two communities of one table is an error; the same row twice is not. Nodes are matched the way OAX compares values: text without regard to case, and 1 and 1.0 the same.
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
Last month's communities and this month's
Gus has left and Hal is new; of the six in both, Cy has moved to the other community. Split-join counts him once from each side.
EVALUATE
VAR LastMonth =
DATATABLE (
"Node", STRING, "Community", INTEGER,
{
{ "Ann", 1 }, { "Bo", 1 }, { "Cy", 1 }, { "Di", 2 }, { "Ed", 2 }, { "Fay", 2 }, { "Gus", 2 }
}
)
VAR ThisMonth =
DATATABLE (
"Node", STRING, "Community", INTEGER,
{
{ "Ann", 2 }, { "Bo", 2 }, { "Cy", 1 }, { "Di", 1 }, { "Ed", 1 }, { "Fay", 1 }, { "Hal", 3 }
}
)
RETURN
SELECTCOLUMNS (
NETWORK.COMPARE ( ThisMonth, [Node], [Community], LastMonth, [Node], [Community] ),
"Nodes", [Nodes],
"Only in first", [Only in first],
"Only in second", [Only in second],
"NMI", [NMI],
"ARI", [ARI],
"Rand", [Rand],
"Split-join", [Split-join]
)
| Nodes | Only in first | Only in second | NMI | ARI | Rand | Split-join |
|---|---|---|---|---|---|---|
| 6 | 1 | 1 | 0.47870397138568 | 0.324324324324324 | 0.666666666666666 | 2 |
Two methods, the same split
Louvain and Walktrap split the seven friends the same way.
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
SELECTCOLUMNS (
NETWORK.COMPARE (
NETWORK.COMMUNITIES ( Links, [From], [To] ), [Node], [Community],
NETWORK.COMMUNITIES ( Links, [From], [To], , "walktrap" ), [Node], [Community]
),
"NMI", [NMI],
"VI", [VI],
"ARI", [ARI],
"Rand", [Rand],
"Split-join", [Split-join]
)
| NMI | VI | ARI | Rand | Split-join |
|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 |
A higher resolution
At resolution 3, Louvain cuts the two groups into five: the two splits agree on two pairs of nodes in three.
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
SELECTCOLUMNS (
NETWORK.COMPARE (
NETWORK.COMMUNITIES ( Links, [From], [To] ), [Node], [Community],
NETWORK.COMMUNITIES ( Links, [From], [To], , "louvain", 3 ), [Node], [Community]
),
"Communities in second", [Communities in second],
"NMI", [NMI],
"Rand", [Rand]
)
| Communities in second | NMI | Rand |
|---|---|---|
| 5 | 0.611723616556389 | 0.666666666666667 |
Related functions
NETWORK.MATCH, NETWORK.COMMUNITIES, NETWORK.NODES.
Open Graph, OpenBI's graph library, does the work: compare_communities. See the OAX network functions and Open Graph.