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

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.

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.2.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.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rnbrw-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 130911481ad330552f88839a8d4bd88dc79147a01ea70a3b723309920a14c4db
MD5 cc345ed44ad42b3998a2d8b966925ac4
BLAKE2b-256 53e88f8d120de3a0d87a5fc5a9486031eccf9b10369afad8116e223e6f3d5e7d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rnbrw-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cd483a9380091ba74374091764e422e992e1564531546084c5e28bf6653fb364
MD5 434a0b9bd42fa3bea7a1b176b7c209f9
BLAKE2b-256 afa6dc0559416d5cf8548efd130ac2f5d7ae2cf2840e51cef44fef90370c2075

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