Skip to main content

Python library for computing Bundle, Pivotal, and Weighted Bundle centrality indices.

Project description

CentralityIndices

CentralityIndices is a Python library for computing centrality indices for weighted directed graphs:

  • Bundle Index (BI)
  • Pivotal Index (PI)
  • Weighted Bundle Index 1 (wBI1)
  • Weighted Bundle Index 2 (wBI2)

The library accepts dense numpy.ndarray adjacency matrices and sparse SciPy matrices. For sparse graphs it can store the adjacency matrix in CSC format, which is efficient for extracting incoming edges of a target vertex.

Installation

Install the package in editable mode from the repository root:

pip install -e .

For running tests:

pip install -e ".[test]"

Quick Start

import numpy as np

from centralityindices import CentralityIndices

W = np.array(
    [
        [0, 0, 0],
        [50, 0, 0],
        [70, 40, 0],
    ],
    dtype=float,
)

centrality = CentralityIndices(W)

print(centrality.backend)
print(centrality.bundle_index(i=2, q=60, k=3))
print(centrality.pivotal_index(i=2, q=60, k=3))
print(centrality.weighted_bundle_index_1(i=2, q=60, k=3))
print(centrality.weighted_bundle_index_2(i=2, q=60, k=3))
print(centrality.all_indices(i=2, q=60, k=3))

Sparse Matrix Support

The density_threshold parameter controls backend selection. If the fraction of non-zero matrix entries is below the threshold, the graph is stored as scipy.sparse.csc_array; otherwise it is stored as a dense NumPy array.

from scipy.sparse import csc_array

W_sparse = csc_array(W)
centrality = CentralityIndices(W_sparse, density_threshold=0.1)
print(centrality.backend)

Tests

pytest tests/test_coverage.py

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

centralityindices-0.1.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

centralityindices-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file centralityindices-0.1.0.tar.gz.

File metadata

  • Download URL: centralityindices-0.1.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for centralityindices-0.1.0.tar.gz
Algorithm Hash digest
SHA256 37144729007b2ea9a775139be0ae318ae3ac08bccd554d3b972b845a93467988
MD5 582bb8b22db571994fa20d6d8b2678de
BLAKE2b-256 fe8ba581d39ffaae76f2953f73982640e64725f71705b12c90d15a6378a2e0ab

See more details on using hashes here.

File details

Details for the file centralityindices-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for centralityindices-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e08e414c231b78c0bd74db9d40b820fad44e2fe4161bb207c2d59165a127f5fe
MD5 8ad2a3b8754d5b978b70bbe030476971
BLAKE2b-256 787ace024e0b58f568b1e885711b16ec3164bfa7c8c0901f02e9534acc16ee87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page