# Harmonic Centrality

This section describes the Harmonic Centrality algorithm

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 algorithm is in the alpha tier. For more information on algorithm tiers, see Algorithms.

## 1. 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.

## 2. Use-cases - 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.

## 3. Syntax

```
CALL gds.alpha.closeness.harmonic.write(configuration: Map)
YIELD nodes, createMillis, 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. |

createMillis |
int |
Milliseconds for loading 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 |

## 4. Harmonic Centrality algorithm sample

```
CREATE (a:Node{id:"A"}),
(b:Node{id:"B"}),
(c:Node{id:"C"}),
(d:Node{id:"D"}),
(e:Node{id:"E"}),
(a)-[:LINK]->(b),
(b)-[:LINK]->(c),
(d)-[:LINK]->(e)
```

```
CALL gds.alpha.closeness.harmonic.stream({
nodeProjection: 'Node',
relationshipProjection: 'LINK'
})
YIELD nodeId, centrality
RETURN gds.util.asNode(nodeId).name AS user, centrality
ORDER BY centrality DESC
```

Name | Centrality weight |
---|---|

B |
0.5 |

A |
0.375 |

c |
0.375 |

D |
0.25 |

E |
0.25 |

```
CALL gds.alpha.closeness.harmonic.write({
nodeProjection: 'Node',
relationshipProjection: 'LINK',
writeProperty: 'centrality'
}) YIELD nodes, writeProperty
```

nodes | writeProperty |
---|---|

5 |
"centrality" |

**Was this page helpful?**