Implementation of the disparity filter from Serrano et al. to extract the backbone of a weighted graph.
The original graph must be a Graph
or DiGraph
object from NetworkX .
The optimal value for alpha
corresponds to the threshold that minimizes the number of edges while maximizing the number of vertices. Use plot_optimal_alpha()
to obtain an illustration.
import disparity_filter_weighted_graphs as dfil
import networkx as nx
# Load the graph from a weighted edgelist.
graph = nx.read_weighted_edgelist('path_to_file', create_using=nx.Graph())
# Compute the 'alpha' value for each edge.
dfil.compute_alpha(graph)
# Find the optimal value for alpha. The dataframe used to find the optimal
# value for alpha is saved to `finding_optimal_alpha.csv.zip`.
dfil.find_optimal_alpha(graph, save_optimal_alpha_data=True, method='elbow')
# Plot the position of the optimal value for alpha.
dfil.plot_optimal_alpha(graph)
# Create a filtered version of the original graph using the optimal value for alpha.
backbone = dfil.filter_graph(graph)
Extracting the multiscale backbone of complex weighted networks
M. Á. Serrano, M. Boguñá and A. Vespignani
Proc. Natl. Acad. Sci. U.S.A. 106, 6483-6488 (2009)