UltipaDocs
Try Playground
  • Introduction
    • Show Algorithms
    • Install and Uninstall
    • Run Algorithms
    • Algorithm Results and Statistics
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Graph Centrality
    • Betweenness Centrality
    • Eigenvector Centrality
    • CELF
    • PageRank
    • ArticleRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • K-Hop All
    • Bipartite Graph
    • HyperANF
    • Connected Component
    • Triangle Counting
    • Induced Subgraph
    • k-Core
    • k-Truss
    • p-Cohesion
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Topological Sort
    • Schema Overview
    • Dijkstra's Single-Source Shortest Path
    • Delta-Stepping Single-Source Shortest Path
    • Shortest Path Faster Algorithm (SPFA)
    • Minimum Spanning Tree
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Louvain
    • Leiden
    • Label Propagation
    • HANP
    • k-Means
    • kNN (k-Nearest Neighbors)
    • K-1 Coloring
    • Conductance
      • Random Walk
      • Node2Vec Walk
      • Node2Vec
      • Struc2Vec Walk
      • Struc2Vec
      • GraphSAGE
      • GraphSAGE Train
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Analytics & Algorithms
  4. /
  5. Centrality

Harmonic Centrality

✓ File Writeback ✓ Property Writeback ✓ Direct Return ✓ Stream Return ✕ Stats

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 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 takes on values between 0 to 1, nodes with higher scores have shorter distances to all other nodes.

Concepts

Shortest Distance

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

Harmonic Mean

Harmonic mean is the inverse of the arithmetic mean of the inverses 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 does not seem reasonable 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 that one-way distance is 1, then the average speed that takes travel time into consideration is 2/(1/30+1/10) = 15 km/h, and this is the harmonic mean, it 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.

NOTE

Harmonic Centrality algorithm consumes considerable computing resources. For a graph with V nodes, it is recommended to perform (uniform) sampling when V > 10,000, and the suggested number of samples is the base-10 logarithm of the number of nodes (log(V)).

For each execution of the algorithm, sampling is performed only once, centrality score of each node is computed based on the shortest distance between the node and all sample nodes.

Considerations

  • The harmonic centrality score of isolated nodes is 0.

Syntax

  • Command: algo(harmonic_centrality)
  • Parameters:
Name
Type
Spec
Default
Optional
Description
ids / uuids[]_id / []_uuid//YesID/UUID of the nodes to calculate, calculate for all nodes if not set
directionstringin, out/YesDirection of all edges in each shortest path, in for incoming direction, out for outgoing direction
sample_sizeint-1, -2, [1, V]-2YesNumber of samples to compute centrality scores; -1 means to sample log(V) nodes; -2 means not to perform sampling; a number within [1, V] means to sample the set number of nodes; sample_size is only valid when ids (uuids) is ignored or when it specifies all nodes
limitint≥-1-1YesNumber of results to return, -1 to return all results
orderstringasc, desc/YesSort nodes by the centrality score

Examples

The example graph is as follows:

File Writeback

SpecContent
filename_id,centrality
UQL
algo(harmonic_centrality).params().write({
  file:{ 
    filename: 'centrality'
  }
})

Results: File centrality

File
LH,0
LG,0.142857
LF,0.142857
LE,0.357143
LD,0.357143
LC,0.428571
LB,0.428571
LA,0.571429

Property Writeback

SpecContentWrite toData Type
propertycentralityNode propertyfloat
UQL
algo(harmonic_centrality).params().write({
  db:{ 
    property: 'hc'
  }
})

Results: Centrality score for each node is written to a new property named hc

Direct Return

Alias OrdinalType
Description
Columns
0[]perNodeNode and its centrality_uuid, centrality
UQL
algo(harmonic_centrality).params({
  direction: 'out',
  order: 'desc',
  limit: 3
}) as hc
return hc

Results: hc

_uuidcentrality
10.35714301
40.33333299
30.28571400

Stream Return

Alias OrdinalType
Description
Columns
0[]perNodeNode and its centrality_uuid, centrality
UQL
algo(harmonic_centrality).params({
  direction: 'in'
}).stream() as hc
where hc.centrality == 0
return hc

Results: hc

_uuidcentrality
80.0000000
60.0000000
40.0000000