algebraic_connectivity

algebraic_connectivity#

graph_tool.spectral.algebraic_connectivity(g, weight=None, norm=False, vector=False)[git][source]#

Return the algebraic connectivity of the graph, i.e. the second smallest eigenvalue of its Laplacian.

Parameters:
gGraph

Graph to be used (the edge directions are ignored).

weightEdgePropertyMap (optional, default: None)

Edge weights.

normbool (optional, default: False)

If True, the normalized Laplacian is used.

vectorbool (optional, default: False)

If True, the corresponding eigenvector (the Fiedler vector) is also returned.

Returns:
afloat

The algebraic connectivity, which is zero if and only if the graph is disconnected.

fiedlerVertexPropertyMap

The Fiedler vector, whose signs give a spectral bisection of the graph. Only returned if vector == True.

See also

laplacian

Laplacian matrix

spectral_clustering

Spectral clustering

graph_tool.flow.vertex_connectivity

Vertex connectivity

graph_tool.flow.edge_connectivity

Edge connectivity

Notes

The algebraic connectivity [fiedler-algebraic-1973] is the second smallest eigenvalue \(\lambda_2\) of the Laplacian matrix

\[L = D - A,\]

where \(A_{ij}\) is the sum of the weights of the edges between \(i\) and \(j\), with their directions ignored (with unit weights if weight is not given), and with the self-loops ignored, i.e. \(A_{ii} = 0\), and \(D\) is the diagonal matrix of the weighted degrees \(d_i = \sum_jA_{ij}\) (as in laplacian(), except that the latter counts the self-loops in the degrees). If norm == True, the normalized Laplacian \(I - D^{-1/2}AD^{-1/2}\) is used instead, whose diagonal entries are zero for isolated vertices. Since \(L\) is positive semidefinite and the multiplicity of its zero eigenvalue is the number of connected components, \(\lambda_2 > 0\) if and only if the graph is connected. The Fiedler vector is the corresponding eigenvector, with unit norm and arbitrary sign. For graphs with fewer than two vertices, zero is returned, and small negative values due to rounding are replaced by zero.

The eigenvalue is computed with a dense eigensolver for small graphs, and with the shift-invert mode of ARPACK (scipy.sparse.linalg.eigsh()) otherwise, which needs a sparse factorization of the Laplacian.

References

[fiedler-algebraic-1973]

Miroslav Fiedler, “Algebraic connectivity of graphs”, Czechoslovak Mathematical Journal 23, 298-305 (1973), DOI: 10.21136/CMJ.1973.101168 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> a, f = gt.algebraic_connectivity(g, vector=True)
>>> print(a, (f.a > 0).sum())
0.4685252... 19

The signs of the entries of the Fiedler vector give a bisection of the network, which can be shown in a drawing:

>>> vcolor = g.new_vp("string", vals=np.where(f.a > 0, "#f28c8e",
...                                           "#9bbedc"))
>>> size = g.new_vp("double", vals=abs(f.a))
>>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=vcolor,
...               vertex_size=gt.prop_to_size(size, mi=5, ma=15),
...               output="algebraic_connectivity-karate.pdf")
<...>
../_images/algebraic_connectivity-karate.png

Fiedler vector of Zachary’s karate club network. The vertices with positive entries are shown in red, those with negative entries in blue, and the vertex sizes increase with the magnitudes of the entries.#