OpenBI Docs Buy

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> )
ParameterTypeDescription
firstTableOne way the nodes fall into communities, a row a node: a table of the model, or what NETWORK.COMMUNITIES or NETWORK.NODES returns.
nodeExpression
evaluated for each row
The node of each row of first.
communityExpression
evaluated for each row
Its community: a number, a text or any value; only which nodes share one counts.
secondTableThe other way, such as the same network's a month later, or another method's.
second nodeExpression
evaluated for each row
The node of each row of second.
second communityExpression
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]
    )
NodesOnly in firstOnly in secondNMIARIRandSplit-join
6110.478703971385680.3243243243243240.6666666666666662

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]
    )
NMIVIARIRandSplit-join
10110

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 secondNMIRand
50.6117236165563890.666666666666667

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.

Last updated · OpenBI Studio 0.3.78