eccentricity

Contents

eccentricity#

graph_tool.structure.eccentricity(g, weights=None, epsilon=1e-08)[git][source]#

Compute the eccentricity of every vertex.

Parameters:
gGraph

Graph to be used.

weightsEdgePropertyMap (optional, default: None)

Non-negative edge weights. If not supplied, every edge has unit length.

epsilonfloat (optional, default: 1e-8)

Relative tolerance with which lower and upper bounds of the eccentricity are considered equal, if the weights are floating-point numbers.

Returns:
eccVertexPropertyMap

Vertex property map with the eccentricities. Its value type is int32_t if weights is None, int64_t for integer weights, and the type of the weights otherwise.

See also

diameter

Maximum eccentricity

radius

Minimum eccentricity

center

Vertices of minimum eccentricity

periphery

Vertices of maximum eccentricity

shortest_distance

Distances between vertices

Notes

The eccentricity of a vertex \(v\) is the largest shortest-path distance from \(v\) to any other vertex,

\[\epsilon(v) = \max_{u} d(v, u),\]

where the maximum is taken only over the vertices reachable from \(v\). Hence, isolated vertices have eccentricity zero, and in a disconnected graph the eccentricities are those within each component. For directed graphs, \(d(v, u)\) is the length of the shortest directed path from \(v\) to \(u\).

The minimum and maximum eccentricities are the radius and the diameter, which are computed directly, with fewer searches, by radius() and diameter(). The center and the periphery of the graph are the vertices whose eccentricity equals the radius and the diameter, respectively.

For undirected graphs, the eccentricity bounding algorithm of [takes-computing-2013] is used: a search from a vertex \(v\) yields the bounds \(\max(\epsilon(v)-d(v,u), d(v,u)) \le \epsilon(u) \le \epsilon(v) + d(v, u)\) for every other vertex \(u\), and the searches continue only from vertices whose bounds do not yet coincide. In large sparse networks, the number of searches needed is typically a small fraction of the number of vertices, although in the worst case it is \(V\), giving \(O(V(V+E))\) time, or \(O(V(V+E)\log V)\) with weights. For directed graphs, the bounds do not apply, and a search is made from every vertex.

The searches are breadth-first, or use Dijkstra’s algorithm if weights are given.

Parallel implementation.

If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.

With \(T\) threads, the algorithm uses \(O(TV)\) memory.

References

[takes-computing-2013]

Frank W. Takes and Walter A. Kosters, “Computing the eccentricity distribution of large graphs”, Algorithms 6, 100-118 (2013), DOI: 10.3390/a6010100 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["polblogs"]
>>> g = gt.extract_largest_component(g, directed=False, prune=True)
>>> g.set_directed(False)
>>> ecc = gt.eccentricity(g)
>>> print(ecc.fa.min(), ecc.fa.max())
4 8

For a smaller network, the eccentricities can be visualized by coloring the vertices:

>>> from matplotlib.colors import LinearSegmentedColormap
>>> g = gt.collection.data["karate"]
>>> ecc = gt.eccentricity(g)
>>> print(ecc.fa.min(), ecc.fa.max())
3 5
>>> cmap = LinearSegmentedColormap.from_list("ecc", ["#d9d9d9",
...                                                  "#7dabd1"])
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=ecc.copy("double"),
...               vcmap=cmap,
...               vertex_text=ecc, edge_color="#999999",
...               output="eccentricity-karate.pdf")
<...>
../_images/eccentricity-karate.png

Eccentricities of the vertices of Zachary’s karate club network, given by the labels and by the colors, which range from gray (eccentricity 3) to blue (eccentricity 5).#