graph

Toolbox module for working with networkx graphs.

Module contains functions for calculating graph centrality, visualizing graphs and finding various network properties, in addition to various other useful functions.

Graph centralities are accessed using the centralities() function, which takes as arguments a graph and the metric to use as a constant of the GraphMetrics class.

Author:Kjetil Valle <kjetilva@stud.ntnu.no>
class graph.GraphMetrics
Class holding constants for the different graph centrality metrics
graph.add_edges_from_matrix(graph, matrix, nodes, rel_weight=1.0)

Add edges to graph based on adjacency matrix.

The nodes list corresponds to each row/column in matrix. The rel_weight scales the edge weights.

graph.betweenness(G)
Betweenness centrality
graph.centralities(graph, method)
Return centralities for nodes in graph using the given centrality method
graph.closeness(G)
Closeness centrality
graph.clustering_degree(G)

Clustering degree ‘’centrality’‘

Measure of centrality based on the clustering coefficient of a node multiplied with its weighted degree centrality.

graph.current_flow_betweenness(G)
Current-flow betweenness centrality
graph.current_flow_closeness(G)
Current-flow closeness centrality
graph.draw(graph)
Draw the graph
graph.draw_with_centrality(G, sizeV=None, min_size=500, max_size=4000, default_size=500, layout=None)
Visualizes a graph preserving edge length and demonstrating centralities as node sizes.
graph.equal(g1, g2)

Check if two graphs are identical.

The graphs are considered equal if they contain the same set of nodes and edges. Edge weights are not considered.

graph.get_hubs(graph, n=10)
Return the n most important hubs from the graph
graph.hits_authorities(G)
The HITS authorities centralities
graph.hits_hubs(G)
The HITS hubs centralities
graph.invert_edge_weights(G)
Returns a graph with all edge weights inverted
graph.load(G)
Load centrality
graph.network_properties(graph, plot_distribution=False, verbose=False)
Returns information about the graph.
graph.node_set(graphs)
Return list of unique nodes from list of graphs
graph.normalize(A)
Normalize a numpy nd-array
graph.pagerank(G)
PageRank values for nodes in graph G
graph.reduce_edge_set(graph, remove_label)

Return new graph with some edges removed.

Those edges that have the remove_label, and no other labels, are removed.

graph.weighted_betweenness(G)
Weighted version of the betweenness centrality
graph.weighted_closeness(G)
Weighted version of the closeness centrality
graph.weighted_degree(G, normalize=True)

Weighted degree centralities.

Counts both incomming and outgoing links. This is the same as the sum of the weighted in-degree and weighted out-degree. Assumes digraph.

graph.weighted_in_degree(G, normalize=True)
Weighted in-degree centralities
graph.weighted_load(G)
Weighted version of the load centrality
graph.weighted_out_degree(G, normalize=True)
Weighted out-degree centralities

Previous topic

graph_representation

Next topic

classify

This Page