A Python package for generating, learning, and analysis of complex networks.
Project description
complex-network-tools
complex-network-tools is a Python package for generating, learning, and analysis of complex networks.
Install
pip install complex-network-tools
Examples
Synthetic network generating
import cnt
# generate a Erdos Renyi(ER) random graph
er_graph = cnt.erdos_renyi_graph(num_nodes=100, num_edges=400, is_directed=False, is_weighted=False)
# generate a Barabasi Albert(BA) scale-free graph
ba_graph = cnt.barabasi_albert_graph(num_nodes=100, num_edges=400, is_directed=False, is_weighted=False)
Network attack
import cnt
# get attack sequence of nodes
G = cnt.erdos_renyi_graph(num_nodes=100, num_edges=400, is_directed=False, is_weighted=False)
# node-removal based network attacks, use the targeted-degree based node-removal strategy
attack_node_sequence = cnt.network_attack(graph=G, attack='node', strategy='degree')
Spectral measure
import cnt
G = cnt.erdos_renyi_graph(num_nodes=100, num_edges=400, is_directed=False, is_weighted=False)
# calculate spectral gap
spectral_gap = cnt.spectral_gap(G)
# calculate spectral radius
spectral_radius = cnt.spectral_radius(G)
# calculate natural_connectivity
natural_connectivity = cnt.natural_connectivity(G)
# calculate algebraic_connectivity
algebraic_connectivity = cnt.algebraic_connectivity(G)
Network dataset of network robustness simulation
import cnt
# generating and saving dataset of networks with their robustness
dataset = cnt.save_simulated_network_dataset(
topology_types=['er', 'ba'],
is_directed=False,
is_weighted=False,
num_instance=100,
network_size=(300, 500),
average_degree=(5, 10),
save_robustness=['connectivity', 'controllability', 'communicability'],
attack='node',
strategy='degree',
save_path='./dataset/file_name'
)
# loading dataset
dataset = cnt.load_simulated_network_dataset(load_path='./dataset/file_name')
# get graphs
graphs = dataset['graphs']
# get labels
connectivity_robustness = dataset['connectivity_curves']
Training deep models for network robustness prediction
import networkx as nx
import cnt
# loading dataset
dataset = cnt.load_simulated_network_dataset(load_path='./dataset/file_name')
# get graphs
graphs = dataset['graphs']
# get labels
connectivity_robustness = dataset['connectivity_curves']
# init CNN-RP
# cnn_rp = cnt.keras_models.CNN_RP(
# input_size=500
# )
# init CNN-SPP
cnn_spp = cnt.keras_models.CNN_SPP()
# training
cnn_spp.fit(
x=[nx.adj_matrix(g) for g in graphs],
y=[cnt.uniform_sampling(curve, 5) for curve in connectivity_robustness],
model_path='./checkpiont/model'
)
Network robustness optimization using a simple GA
import cnt
# create initial graph
init_graph = cnt.erdos_renyi_graph(num_nodes=100, num_edges=400, is_directed=False, is_weighted=False)
# create initial population
Pop = cnt.GA.Population(init_graph=init_graph, init_size=10, max_size=25)
# optimization
all_best_ind = None
for gen in range(100):
Pop.crossover()
Pop.mutate()
Pop.selection()
best_ind = Pop.find_best()
if gen == 0:
all_best_ind = best_ind
else:
if best_ind.R > all_best_ind.R:
all_best_ind = best_ind
useful functions
import networkx as nx
import cnt
G = cnt.erdos_renyi_graph(100, 400)
# sort adjacency matrix
cnt.adj_sort(adj=nx.adj_matrix(G))
# shuffle adjacency matrix
cnt.adj_shuffle(adj=nx.adj_matrix(G))
# random sampling for adjacency matrix
cnt.random_sampling(adj=nx.adj_matrix(G), fixed_size=500)
# Bilinear interpolation for adjacency matrix
cnt.bi_linear_sampling(adj=nx.adj_matrix(G), fixed_size=500)
# nodes noises
cnt.missing_nodes(adj=nx.adj_matrix(G), strategy='random', rate=0.1)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for complex-network-tools-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82ee76e9227a15ebac0a14ce6a72f6d477faaeabeb35759fbc00802fa661e4e7 |
|
MD5 | abe8dae575e0d0e0f0bd85dfeeeae830 |
|
BLAKE2b-256 | 89ec2f932703654f1a1a889449bde18595cb39f30298c8ad267893041c6abe7f |
Close
Hashes for complex_network_tools-0.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52f16fb94823d4c38864e33c85e5fabc6bf773a309441b648b0bbc860e155e1f |
|
MD5 | 85d30ede4031b09fa280d10860de3c4b |
|
BLAKE2b-256 | 6dd79690e3d72513378ca24a16df781e93261a7dca09efad7d59e11d92d2a906 |