Skip to main content

Renewal Non-Backtracking Random Walk (RNBRW) for community detection

Project description

RNBRW

PyPI version

RNBRW (Renewal Non-Backtracking Random Walks) is a Python package for estimating edge-level importance in networks using random walks that restart upon cycle closure. These weights can be used to improve community detection algorithms like Louvain.

Based on:

Moradi, B., Shakeri, H., Poggi-Corradini, P., & Higgins, M.
New methods for incorporating network cyclic structures to improve community detection
arXiv:1805.07484


Installation

pip install rnbrw


## Features
- Parallel RNBRW edge weight estimation
- Seamless integration with Louvain
- Based on [Moradi-Jamei et al., 2019](https://arxiv.org/abs/1805.07484)

## Installation
```bash
pip install rnbrw

Usage

import networkx as nx
from rnbrw.weights import compute_weights
from rnbrw.community import detect_communities_louvain

# Create or load a graph
G = nx.karate_club_graph()

# Compute RNBRW weights
G = compute_weights(G, nsim=1000, n_jobs=4)

# Detect communities
partition = detect_communities_louvain(G)

## API Reference
- compute_weights(G, nsim=1000, n_jobs=1, weight_attr='rnbrw_weight', seed_base=0)
- Simulates RNBRW on graph G to assign edge importance scores as weights.

# Parameter	Type	Description
| Parameter     | Type            | Description                                       |
|-------------- |---------------- |--------------------------------------------------|
| G             | networkx.Graph  | Input undirected graph                           |
| nsim          | int             | Number of simulations (default = 1000)           |
| n_jobs        | int             | Number of parallel jobs (default = 1; -1 = all)  |
| weight_attr   | str             | Name of the edge attribute to store weights      |
| seed_base     | int             | Base random seed for reproducibility             |


detect_communities_louvain(G, weight_attr='rnbrw_weight')
Runs Louvain on G using edge weights.

Parameter	Type	Description
| Parameter     | Type            | Description                                  |
|-------------- |---------------- |---------------------------------------------|
| G             | networkx.Graph  | Weighted graph with edge weights            |
| weight_attr   | str             | Edge attribute name (default = 'rnbrw_weight') |

normalize_edge_weights(G, weight='rnbrw_weight')
Normalizes the weights to sum to 1 across all edges.

Parameter	Type	Description
| Parameter     | Type            | Description                                 |
|-------------- |---------------- |--------------------------------------------|
| G             | networkx.Graph  | Graph whose weights are to be normalized   |
| weight        | str             | Edge attribute to normalize (default='rnbrw_weight') |


 Citation
If you use this package in your research, please cite:


@article{moradi2018new,
  title={New methods for incorporating network cyclic structures to improve community detection},
  author={Moradi, Behnaz and Shakeri, Heman and Poggi-Corradini, Pietro and Higgins, Michael},
  journal={arXiv preprint arXiv:1805.07484},
  year={2018}
}
Or use the Cite this repository button above.

📄 License
This project is licensed under the MIT License © 2025 Behnaz Moradi-Jamei.
## Documentation
Full documentation is available at [Read the Docs](https://rnbrw.readthedocs.io).

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

rnbrw-0.1.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

rnbrw-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file rnbrw-0.1.1.tar.gz.

File metadata

  • Download URL: rnbrw-0.1.1.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for rnbrw-0.1.1.tar.gz
Algorithm Hash digest
SHA256 141596bcdd5431ddd58f2b9c814ab928dc01410dc1e1e82e8b1bfcf76900321e
MD5 0dcf0f0ed670e79f02811ddc1c611304
BLAKE2b-256 07f0e29967a8faea984096e96596ab1ee856cac7ea7a7914d59ae62afd322f2a

See more details on using hashes here.

File details

Details for the file rnbrw-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: rnbrw-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for rnbrw-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa13c825db05131eeb1ac22122a6e1121276795410da75f61b7bf2a02eeb544d
MD5 06a345ef441707e24c0a404a9cc717f4
BLAKE2b-256 c435c8806caa78752668cf4862edf664db5d50a7b97649c79c5e3d31e1146f0b

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