UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Eccentricity Centrality
    • Betweenness Centrality
    • Bridges
    • Articulation Points
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • KNN
    • Vector Similarity
    • Bipartite Graph
    • HyperANF
    • Weakly Connected Components (WCC)
    • Strongly Connected Components (SCC)
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Triangle Count
    • Clique Count
    • k-Core
    • k-Truss
    • p-Cohesion
    • Induced Subgraph
    • Topological Sort
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Dijkstra's Shortest Path
    • A* Shortest Path
    • Yen's K-Shortest Paths
    • Shortest Path (BFS)
    • Delta-Stepping SSSP
    • Shortest Path Faster Algorithm (SPFA)
    • All-Pairs Shortest Path (APSP)
    • Minimum Spanning Tree (MST)
    • K-Spanning Tree
    • Steiner Tree
    • Prize-Collecting Steiner Tree (PCST)
    • Minimum Cost Flow
    • Maximum Flow
    • K-Hop Fast
    • Longest Path (DAG)
    • Random Walk
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Same Community
    • Louvain
    • Leiden
    • Modularity Optimization
    • Label Propagation
    • HANP
    • SLPA
    • k-Means
    • HDBSCAN
    • K-1 Coloring
    • Modularity
    • Conductance
    • Max k-Cut
      • Node2Vec
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Algorithms
  4. /
  5. Centrality

Harmonic Centrality

Overview

Harmonic Centrality is a variant of Closeness Centrality. The average shortest distance measurement proposed by harmonic centrality is compatible with infinite values which would occur in a disconnected graph. Harmonic centrality was first proposed by M. Marchiori and V. Latora in 2000, and then by A. Dekker and Y. Rochat in 2005 and 2009:

  • M. Marchiori, V. Latora, Harmony in the Small-World (2000)
  • A. Dekker, Conceptual Distance in Social Network Analysis (2005)
  • Y. Rochat, Closeness Centrality Extended to Unconnected Graphs: The Harmonic Centrality Index (2009)

Harmonic centrality ranges from 0 to 1; higher scores indicate that a node is closer to other nodes in the graph.

Concepts

Shortest Distance

The shortest distance between two nodes is defined as the number of edges in the shortest path connecting them. Please refer to Closeness Centrality for more details.

Harmonic Mean

The harmonic mean is the reciprocal of the arithmetic mean of the reciprocals of the variables. The formula for calculating the arithmetic mean A and the harmonic mean H is as follows:

A classic application of harmonic mean is to calculate the average speed when traveling back and forth at different speeds. Suppose there is a round trip, the forward and backward speeds are 30 km/h and 10 km/h respectively. What is the average speed for the entire trip?

The arithmetic mean A = (30+10)/2 = 20 km/h is not appropriate in this case. Since the backward journey takes three times as long as the forward, during most time of the entire trip the speed stays at 10 km/h, so we expect the average speed to be closer to 10 km/h.

Assuming the one-way distance is 1, the average speed that takes travel time into consideration is 2/(1/30+1/10) = 15 km/h. This value, the harmonic mean, is adjusted by the time spent during each journey.

Harmonic Centrality

Harmonic centrality score of a node defined by this algorithm is the inverse of the harmonic mean of the shortest distances from the node to all other nodes. The formula is:

where x is the target node, y is any node in the graph other than x, k-1 is the number of y, d(x,y) is the shortest distance between x and y, d(x,y) = +∞ when x and y are not reachable to each other, in this case 1/d(x,y) = 0.

The harmonic centrality of node a in the above graph is (1 + 1/2 + 1/+∞ + 1/+∞) / 4 = 0.375, and the harmonic centrality of node d is (1/+∞ + 1/+∞ + 1/+∞ + 1) / 4 = 0.25.

Considerations

  • The harmonic centrality score of isolated nodes is 0.

Example Graph

GQL
INSERT (A:user {_id: "A"}), (B:user {_id: "B"}),
       (C:user {_id: "C"}), (D:user {_id: "D"}),
       (E:user {_id: "E"}), (F:user {_id: "F"}),
       (G:user {_id: "G"}), (H:user {_id: "H"}),
       (A)-[:vote {score: 2}]->(B), (A)-[:vote {score: 3}]->(E),
       (B)-[:vote {score: 4}]->(B), (B)-[:vote {score: 2}]->(C),
       (C)-[:vote {score: 3}]->(A), (D)-[:vote {score: 1}]->(A),
       (F)-[:vote {score: 1}]->(G)

Parameters

NameTypeDefaultDescription
idsLIST/_ids of nodes to compute (empty = all nodes).
directionSTRINGbothEdge direction: in, out, or both.
weightSTRING or LIST/Numeric edge property for weighted shortest paths.
limitINT-1Limits the number of results returned (-1 = all).
orderSTRING/Sorts the results by score: asc or desc.

Run Mode

Returns:

ColumnTypeDescription
nodeIdSTRINGNode identifier (_id)
scoreFLOATHarmonic centrality score (higher = more central)
rankINTRank position (1 = highest harmonic centrality)

Harmonic centrality for all nodes:

GQL
CALL algo.harmonic({
  order: "desc"
}) YIELD nodeId, score, rank

Result:

nodeIdscorerank
A0.57142857142857141
C0.428571428571428552
B0.428571428571428553
E0.35714285714285714
D0.35714285714285715
G0.142857142857142856
F0.142857142857142857
H08

Weighted harmonic centrality:

GQL
CALL algo.harmonic({
  ids: ["A", "B"],
  weight: ["score"]
}) YIELD nodeId, score, rank

Result:

nodeIdscorerank
A0.30952380952380951
B0.219047619047619022

Stream Mode

Returns the same columns as run mode, streamed for memory efficiency.

GQL
CALL algo.harmonic.stream({
  direction: "in"
}) YIELD nodeId, score
FILTER score = 0
RETURN nodeId, score

Result:

nodeIdscore
D0
F0
H0

Stats Mode

Returns:

ColumnTypeDescription
nodeCountINTTotal number of nodes
minScoreFLOATMinimum harmonic centrality score
maxScoreFLOATMaximum harmonic centrality score
avgScoreFLOATAverage harmonic centrality score
GQL
CALL algo.harmonic.stats() YIELD nodeCount, minScore, maxScore, avgScore

Result:

nodeCountminScoremaxScoreavgScore
800.57142857142857140.3035714285714286

Write Mode

Computes results and writes them back to node properties. The write configuration is passed as a second argument map.

Write parameters:

NameTypeDescription
db.propertySTRING or MAPNode property to write results to. String: writes the score column in results to a property. Map: explicit column-to-property mapping (e.g., {score: 'hc_score', rank: 'hc_rank'}).

Writable columns:

ColumnTypeDescription
scoreFLOATHarmonic centrality score
rankINTRank position

Returns:

ColumnTypeDescription
task_idSTRINGTask identifier for tracking via SHOW TASKS
nodesWrittenINTNumber of nodes with properties written
computeTimeMsINTTime spent computing the algorithm (milliseconds)
writeTimeMsINTTime spent writing properties to storage (milliseconds)
GQL
CALL algo.harmonic.write({}, {
  db: {
    property: "hc_score"
  }
}) YIELD task_id, nodesWritten, computeTimeMs, writeTimeMs