Metadata-Version: 2.4
Name: centralityindices
Version: 0.1.0
Summary: Python library for computing Bundle, Pivotal, and Weighted Bundle centrality indices.
Author-email: Saidazamkhon Buzurukov <abuzurukov2005@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Azamkhon2005/CentralityIndices
Project-URL: Repository, https://github.com/Azamkhon2005/CentralityIndices
Project-URL: Issues, https://github.com/Azamkhon2005/CentralityIndices/issues
Keywords: centrality,graph theory,network analysis,bundle index,pivotal index,weighted bundle index
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: scipy
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"

# 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:

```bash
pip install -e .
```

For running tests:

```bash
pip install -e ".[test]"
```

## Quick Start

```python
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.

```python
from scipy.sparse import csc_array

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

## Tests

```bash
pytest tests/test_coverage.py
```
