Search code examples
neo4jgraph-theory

Calculating betweenness returns negative values


When calculating the betweenness centrality of my graph, some nodes receive negative values when using 'Undirected' as relationship orientation. Happens in Neo4j 4.0.6 with gds 1.2.2. but also in older versions. The graph itself should be alright, exporting it to Gephi and then calculating the betweenness factor returns all positive values.

Here is the Query:

CALL gds.alpha.betweenness.stream({
    nodeProjection: 'poi',
    relationshipProjection: {
        similar: {
            type: 'similar',
            orientation: 'UNDIRECTED'
        }
    }
}) 
YIELD nodeId, centrality
RETURN gds.util.asNode(nodeId).OsmID AS id, centrality
ORDER BY centrality ASC

The result is negative values after the betweenness calculation:

Used Graph: graphml file (4MB)


Solution

  • Betweenness centrality has been just recently promoted out of the alpha tier to production quality in Graph Data Science version 1.3. At this moment only the preview version of the 1.3. GDS is available on GitHub. I have tested your dataset and it looks like with the new version the issue does not persist. So for now, you can either use the preview version of the GDS 1.3 version or wait a couple of days until the GA version will be available. The only thing changed is the output syntax, where centrality has been renamed to score.

    CALL gds.betweenness.stream({
        nodeProjection: '*',
        relationshipProjection: {
            similar: {
                type: 'similar',
                orientation: 'UNDIRECTED'
            }
        }
    }) 
    YIELD nodeId, score
    RETURN gds.util.asNode(nodeId).OsmID AS id, score
    ORDER BY score ASC