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)
Metadata
Release files for complex-network-tools 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| complex-network-tools-0.2.4.tar.gz | 40.3 kB | Without provenance | Details for complex-network-tools-0.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| complex_network_tools-0.2.4-py3-none-any.whl | Python 3 | none | any | Details for complex_network_tools-0.2.4-py3-none-any.whl |
Total release size: 96.8 kB
Release files / complex-network-tools-0.2.4.tar.gz
| Download URL | complex-network-tools-0.2.4.tar.gz |
|---|---|
| Size | 40.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01fc7e9055222c45e70c29f7ca5af6be4ea70e7a001656c0a5c649e44d4b826b
|
|
BLAKE2b-256 checksum How to use checksums |
46bc9ea6fa48f5d1b0938087fbc5d3f60123e1d93b1e9f1dfd675e0afc292eac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Release files / complex_network_tools-0.2.4-py3-none-any.whl
| Download URL | complex_network_tools-0.2.4-py3-none-any.whl |
|---|---|
| Size | 56.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f736b31dab9f3f7d28a83b4f5435889f6927ab7a2bd32df4e0fe003a768c51e7
|
|
BLAKE2b-256 checksum How to use checksums |
65ebe3f68ba6696f9788582c63f5f6e7070f3fea253908cdf447fdaaff27a033
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.9.18
|
Security for complex-network-tools 0.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.