Skip to main content
`Ctrl`+`K`

# harmonic_diameter

harmonic_diameter(G, sp=None)

  Returns the harmonic diameter of the graph G.

  The harmonic diameter of a graph is the harmonic mean of the distances between all pairs of distinct vertices. Graphs that are not strongly connected have infinite diameter and mean distance, making such measures not useful. Restricting the diameter or mean distance to finite distances yields paradoxical values (e.g., a perfect match would have diameter one). The harmonic mean handles gracefully infinite distances (e.g., a perfect match has harmonic diameter equal to the number of vertices minus one), making it possible to assign a meaningful value to all graphs.

  Note that in [1] the harmonic diameter is called “connectivity length”: however, “harmonic diameter” is a more standard name from the theory of metric spaces. The name “harmonic mean distance” is perhaps a more descriptive name, but is not used in the literature, so we use the name “harmonic diameter” here.

  Parameters:
    G NetworkX graph

      A graph

    sp dict of dicts, optional

      All-pairs shortest path lengths as a dictionary of dictionaries

  Returns:
    hd float

      Harmonic diameter of graph

  References

  [1]

  Massimo Marchiori and Vito Latora, “Harmony in the small-world”. Physica A: Statistical Mechanics and Its Applications 285(3-4), pages 539-546, 2000. <https://doi.org/10.1016/S0378-4371(00)00311-3>