Network centrality library
Project description
NetCenLib
NetCenLib (Network centrality library) is a tool to compute a wide range of centrality measures for a given network. The library is designed to work with Python Networkx library.
Overview
The goal of NetCenLib is to offer a comprehensive repository for implementing a broad spectrum of centrality measures. Each year, new measures are introduced through scientific papers, often with only pseudo-code descriptions, making it difficult for researchers to evaluate and compare them with existing methods. While implementations of well-known centrality measures exist, recent innovations are frequently absent. NetCenLib strives to bridge this gap. It references the renowned CentiServer portal for well-known centrality measures and their originating papers, aiming to encompass all these measures in the future.
Code structure
All custom implementations are provided under netcenlib/algorithms
package. Each centrality measure is implemented in a separate file, named after the measure itself. Correspondingly, each file contains a function, named identically to the file, which calculates the centrality measure. This function accepts a NetworkX graph as input (and other params if applicable) and returns a dictionary, mapping nodes to their centrality values. Ultimately, every custom implementation is made available through the netcenlib/algorithms
package.
Implemented centrality measures:
- Algebraic
- Average Distance
- Barycenter
- Betweenness
- BottleNeck
- Centroid
- Closeness
- ClusterRank
- Communicability Betweenness
- Coreness
- Current Flow Betweenness
- Current Flow Closeness
- Decay
- Degree
- Diffusion degree
- Eigenvector
- Entropy
- Geodestic k path
- Group Betweenness Centrality
- Group Closeness
- Group Degree
- Harmonic
- Heatmap
- Katz
- Hubbell
- Laplacian
- Leverage
- Lin
- Load
- Mnc
- Pagerank
- Pdi
- Percolation
- Radiality
- Rumor
- Second Order
- Semi Local
- Subgraph
- Topological
- Trophic Levels
How to use
Library can be installed using pip:
pip install netcenlib
Code usage
Provided algorithms can be executed in the following ways:
- by invoking a specific function from
netcenlib.algorithms
package, which computes a given centrality measure for a given graph.
import networkx as nx
import netcenlib as ncl
# Create a graph
G = nx.karate_club_graph()
# Compute degree centrality
degree_centrality = ncl.degree_centrality(G)
# Compute betweenness centrality
betweenness_centrality = ncl.betweenness_centrality(G)
# Compute closeness centrality
closeness_centrality = ncl.closeness_centrality(G)
# Compute eigenvector centrality
eigenvector_centrality = ncl.eigenvector_centrality(G)
- invoking
compute_centrality
method ofCentralityService
class, which allows to compute centrality for a given centrality measure.
from typing import Any
import networkx as nx
from networkx import Graph
from netcenlib.centrality import compute_centrality
from netcenlib.taxonomies import Centrality
g: Graph = nx.karate_club_graph()
centrality_centroid: dict[Any, float] = compute_centrality(g, Centrality.CENTROID)
This method allows you not to directly specify centrality, making it easy to compute different centralities in a loop.
Contributing
For contributing, refer to its CONTRIBUTING.md file. We are a welcoming community... just follow the Code of Conduct.
Maintainers
Project maintainers are:
- Damian Frąszczak
- Edyta Frąszczak
Project details
Release history Release notifications | RSS feed
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
Hashes for netcenlib-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc8cc5e9c092e06bc3b4412439a99fd52141f2b7c9c3cecc4a0fd78098868b42 |
|
MD5 | 3f750d506dba57a1a81b0fb37f91e2c6 |
|
BLAKE2b-256 | 6d2f96bb4a82255541bb22864b408826bfb2811f8578f3b4cdc7c1aabcadbdff |