UltipaDocs
Try Playground
  • Introduction
  • Managing HDC Graphs
  • Managing Distributed Projections
  • Installing Algorithms
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Graph Centrality
    • Betweenness Centrality
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • 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
      • 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

HDC

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.

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.

Example Graph

Run the following statements on an empty graph to define its structure and insert data:

ALTER GRAPH CURRENT_GRAPH ADD NODE {
  user ()
};
ALTER GRAPH CURRENT_GRAPH ADD EDGE {
  vote ()-[{score uint32}]->()
};
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);

Creating HDC Graph

To load the entire graph to the HDC server hdc-server-1 as my_hdc_graph:

CREATE HDC GRAPH my_hdc_graph ON "hdc-server-1" OPTIONS {
  nodes: {"*": ["*"]},
  edges: {"*": ["*"]},
  direction: "undirected",
  load_id: true,
  update: "static"
}

Parameters

Algorithm name: harmonic_centrality

Name
Type
Spec
Default
Optional
Description
ids[]_id//YesSpecifies nodes for computation by their _id. If unset, computation includes all nodes.
uuids[]_uuid//YesSpecifies nodes for computation by their _uuid. If unset, computation includes all nodes.
directionStringin, out/YesSpecifies that all edges in the shortest paths must be either incoming (in) or outgoing (out).
edge_schema_property[]"<@schema.?><property>"//YesSpecifies numeric edge properties used as weights by summing their values. Only properties of numeric type are considered, and edges without these properties are ignored.
impl_typeStringdijkstra, delta_stepping, spfa, betabetaYesSpecifies the algorithm used to compute weighted shortest paths: Dijkstra, Delta-Stepping, SPFA or the default (beta) Ultipa algorithm. Valid only when edge_schema_property is specified.
sample_sizeInteger-1, -2, [1, |V|]-2YesSpecifies the sampling strategy for computation:
  • -1: Sample log(|V|) nodes
  • [1, |V|]: Sample a specific number of nodes (|V| is the total number of nodes in the graph)
  • -2: Disable sampling
Valid only when all nodes are involved in the computation.
return_id_uuidStringuuid, id, bothuuidYesIncludes _uuid, _id, or both in the results to represent nodes.
limitInteger≥-1-1YesLimits the number of results returned. Set to -1 to include all results.
orderStringasc, desc/YesSorts the results by harmonic_centrality.

File Writeback

CALL algo.harmonic_centrality.write("my_hdc_graph", {
  return_id_uuid: "id",
  order: "desc"
}, {
  file: {
    filename: "harmonic"
  }
})

Result:

File: harmonic
_id,harmonic_centrality
A,0.571429
B,0.428571
C,0.428571
D,0.357143
E,0.357143
F,0.142857
G,0.142857
H,0

DB Writeback

Writes the harmonic_centrality values from the results to the specified node property. The property type is float.

CALL algo.harmonic_centrality.write("my_hdc_graph", {}, 
{
  db: {
    property: "hc"
  }
})

Full Return

CALL algo.harmonic_centrality.run("my_hdc_graph", {
  return_id_uuid: "id",
  ids: ["A", "B"],
  edge_schema_property: "score"
}) YIELD hc
RETURN hc

Result:

_idharmonic_centrality
A0.309523
B0.219048

Stream Return

CALL algo.harmonic_centrality.stream("my_hdc_graph", {
  direction: "in",
  return_id_uuid: "id"
}) YIELD hc
FILTER hc.harmonic_centrality = 0
RETURN hc

Result:

_idharmonic_centrality
D0
F0
H0