Harmonic Centrality
Glossary
 Directed

Directed trait. The algorithm is welldefined on a directed graph.
 Directed

Directed trait. The algorithm ignores the direction of the graph.
 Directed

Directed trait. The algorithm does not run on a directed graph.
 Undirected

Undirected trait. The algorithm is welldefined on an undirected graph.
 Undirected

Undirected trait. The algorithm ignores the undirectedness of the graph.
 Heterogeneous nodes

Heterogeneous nodes fully supported. The algorithm has the ability to distinguish between nodes of different types.
 Heterogeneous nodes

Heterogeneous nodes allowed. The algorithm treats all selected nodes similarly regardless of their label.
 Heterogeneous relationships

Heterogeneous relationships fully supported. The algorithm has the ability to distinguish between relationships of different types.
 Heterogeneous relationships

Heterogeneous relationships allowed. The algorithm treats all selected relationships similarly regardless of their type.
 Weighted relationships

Weighted trait. The algorithm supports a relationship property to be used as weight, specified via the relationshipWeightProperty configuration parameter.
 Weighted relationships

Weighted trait. The algorithm treats each relationship as equally important, discarding the value of any relationship weight.
Harmonic centrality (also known as valued centrality) is a variant of closeness centrality, that was invented to solve the problem the original formula had when dealing with unconnected graphs. As with many of the centrality algorithms, it originates from the field of social network analysis.
This feature is in the alpha tier. For more information on feature tiers, see API Tiers.
History and explanation
Harmonic centrality was proposed by Marchiori and Latora in Harmony in the Small World while trying to come up with a sensible notion of "average shortest path".
They suggested a different way of calculating the average distance to that used in the Closeness Centrality algorithm. Rather than summing the distances of a node to all other nodes, the harmonic centrality algorithm sums the inverse of those distances. This enables it deal with infinite values.
The raw harmonic centrality for a node is calculated using the following formula:
raw harmonic centrality(node) = sum(1 / distance from node to every other node excluding itself)
As with closeness centrality, we can also calculate a normalized harmonic centrality with the following formula:
normalized harmonic centrality(node) = sum(1 / distance from node to every other node excluding itself) / (number of nodes  1)
In this formula, ∞ values are handled cleanly.
Usecases  when to use the Harmonic Centrality algorithm
Harmonic centrality was proposed as an alternative to closeness centrality, and therefore has similar use cases.
For example, we might use it if we’re trying to identify where in the city to place a new public service so that it’s easily accessible for residents. If we’re trying to spread a message on social media we could use the algorithm to find the key influencers that can help us achieve our goal.
Syntax
This section covers the syntax used to execute the Harmonic Centrality algorithm in each of its execution modes. We are describing the named graph variant of the syntax. To learn more about general syntax variants, see Syntax overview.
CALL gds.closeness.harmonic.write(
graphName: String,
configuration: Map
)
YIELD
centralityDistribution: Map,
preProcessingMillis: Integer,
computeMillis: Integer,
postProcessingMillis: Integer,
writeMillis: Integer,
nodePropertiesWritten: Integer,
configuration: Map
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

concurrency 
int 
4 
yes 
The number of concurrent threads used for running the algorithm. Also provides the default value for 'readConcurrency' and 'writeConcurrency'. 
readConcurrency 
int 
value of 'concurrency' 
yes 
The number of concurrent threads used for reading the graph. 
writeConcurrency 
int 
value of 'concurrency' 
yes 
The number of concurrent threads used for writing the result. 
writeProperty 
string 
N/A 
no 
The node property in the Neo4j database to which the centrality score is written. 
Name  Type  Description 

centralityDistribution 
Map 
Map containing min, max, mean as well as p50, p75, p90, p95, p99 and p999 percentile values of centrality values. 
preProcessingMillis 
Integer 
Milliseconds for preprocessing the graph. 
computeMillis 
Integer 
Milliseconds for running the algorithm. 
postProcessingMillis 
Integer 
Milliseconds for computing the statistics. 
writeMillis 
Integer 
Milliseconds for writing result data back. 
nodePropertiesWritten 
Integer 
Number of properties written to Neo4j. 
configuration 
Map 
The configuration used for running the algorithm. 
CALL gds.closeness.harmonic.stream(
graphName: String,
configuration: Map
)
YIELD
nodeId: Integer,
score: Float
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

List of String 
['*'] 
yes 
Filter the named graph using the given node labels. Nodes with any of the given labels will be included. 

List of String 
['*'] 
yes 
Filter the named graph using the given relationship types. Relationships with any of the given types will be included. 

Integer 
4 
yes 
The number of concurrent threads used for running the algorithm. 

String 
Generated internally 
yes 
An ID that can be provided to more easily track the algorithm’s progress. 

Boolean 
true 
yes 
If disabled the progress percentage will not be logged. 
Name  Type  Description 

nodeId 
Integer 
Node ID. 
score 
Float 
Harmonic centrality score. 
Alpha syntax
CALL gds.alpha.closeness.harmonic.write(configuration: Map)
YIELD nodes, preProcessingMillis, computeMillis, writeMillis, centralityDistribution
Name  Type  Default  Optional  Description 

concurrency 
int 
4 
yes 
The number of concurrent threads used for running the algorithm. Also provides the default value for 'readConcurrency' and 'writeConcurrency'. 
readConcurrency 
int 
value of 'concurrency' 
yes 
The number of concurrent threads used for reading the graph. 
writeConcurrency 
int 
value of 'concurrency' 
yes 
The number of concurrent threads used for writing the result. 
writeProperty 
string 
'centrality' 
yes 
The property name written back to. 
Name  Type  Description 

nodes 
int 
The number of nodes considered. 
preProcessingMillis 
int 
Milliseconds for preprocessing the data. 
computeMillis 
int 
Milliseconds for running the algorithm. 
writeMillis 
int 
Milliseconds for writing result data back. 
writeProperty 
string 
The property name written back to. 
centralityDistribution 
Map 
Map containing min, max, mean as well as p50, p75, p90, p95, p99 and p999 percentile values of centrality values. 
CALL gds.alpha.closeness.harmonic.stream(configuration: Map)
YIELD nodeId, centrality
Name  Type  Default  Optional  Description 

concurrency 
int 
4 
yes 
The number of concurrent threads used for running the algorithm. Also provides the default value for 'readConcurrency' and 'writeConcurrency'. 
readConcurrency 
int 
value of 'concurrency' 
yes 
The number of concurrent threads used for reading the graph. 
Name  Type  Description 

node 
long 
Node ID 
centrality 
float 
Harmonic centrality score 
Harmonic Centrality algorithm example
CREATE (a:User {name: "Alice"}),
(b:User {name: "Bob"}),
(c:User {name: "Charles"}),
(d:User {name: "Doug"}),
(e:User {name: "Ethan"}),
(a)[:LINK]>(b),
(b)[:LINK]>(c),
(d)[:LINK]>(e)
CALL gds.graph.project(
'graph',
'User',
{ LINK: {orientation: 'UNDIRECTED'} }
)
CALL gds.closeness.harmonic.stream('graph', {})
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS user, score
ORDER BY score DESC
user  score 

"Bob" 
0.5 
"Alice" 
0.375 
"Charles" 
0.375 
"Doug" 
0.25 
"Ethan" 
0.25 
CALL gds.closeness.harmonic.write('graph', {writeProperty: 'score'})
YIELD nodePropertiesWritten
nodePropertiesWritten 

5 