dynamicalab.algorithms.clustering_spectrum¶
-
dynamicalab.algorithms.
clustering_spectrum
(g)[source]¶ This function extracts the clustering spectrum of a simple undirected graph.
Parameters
- g : nx.Graph
- A simple undirected graph without self-loops.
Warning
The graph must be simple (no multiedges), undirected and without self-loops.
Returns
- clust_spect : dict
- Dictionary mapping each degree class (integers) to the corresponding average local clustering coefficient (float).
Example
import numpy as np import networkx as nx import matplotlib.pyplot as plt import dynamicalab.algorithms as algo # Gets a network and extracts its clustering spectrum. G = nx.karate_club_graph() clust_spect = algo.clustering_spectrum(G) # Plots the clustering spectrum. fig, ax = plt.subplots() plt.bar(clust_spect.keys(), clust_spect.values(), width=0.50, color='g') plt.title("Clustering spectrum") ax.set_ylabel("Average local clustering") ax.set_xlabel("Degree") ax.set_ylim(bottom=0, top=1) ax.set_xticks(np.arange(max(clust_spect.keys()) + 1)) plt.show()