Fiedler’s spectral bipartition of a “barbell” graph#

Two dense clusters joined by a single bridge edge – a case where the Fiedler vector’s sign cleanly recovers the two clusters, and the small algebraic connectivity reflects how easily the graph is disconnected (by removing just the bridge).

from mathematicskit.graph_theory import Graph, spectral_analysis
from mathematicskit.graph_theory.utils.generators import complete_graph
from mathematicskit.graph_theory.visualizers.plots import plot_spectral_bipartition

Build the barbell graph: two K5 cliques joined by one edge#

Spectral analysis#

result = spectral_analysis(g)
print(f"algebraic connectivity: {result.algebraic_connectivity:.4f}")
print(f"spectral bipartition: {result.bipartition.astype(int)}")

plot_spectral_bipartition(g, result)
Spectral bipartition (algebraic connectivity = 0.298)
algebraic connectivity: 0.2984
spectral bipartition: [1 1 1 1 1 0 0 0 0 0]

<Axes: title={'center': 'Spectral bipartition (algebraic connectivity = 0.298)'}>

Total running time of the script: (0 minutes 0.018 seconds)

Gallery generated by Sphinx-Gallery