Skip to main content

torch-rolx - PyTorch Implementation of RolX Algorithm

A PyTorch implementation of the RolX (Role eXtraction) algorithm for role discovery in graphs. This package provides efficient, GPU-accelerated tools for extracting structural roles from network data using feature-based approaches.

Overview

RolX is an unsupervised learning approach that discovers roles in networks based on recursive feature extraction and non-negative matrix factorization. This implementation provides:

  • ReFeX: Recursive Feature Extraction to generate node features based on local and neighborhood properties
  • RolX: Role extraction using Non-negative Matrix Factorization (NMF) on the extracted features
  • GPU Acceleration: Leverages PyTorch for efficient computation on both CPU and GPU

Installation

pip install torch-rolx

Requirements

  • Python 3.6+
  • PyTorch
  • NetworkX
  • NumPy

Usage

Basic Example

import networkx as nx
from torch_rolx.rolx import RolX

# Create a sample graph
G = nx.karate_club_graph()

# Initialize RolX with 4 roles
rolx = RolX(n_roles=4, device='cpu')  # Use 'cuda' for GPU acceleration

# Extract roles
role_assignments = rolx.fit_transform(G)

# Print role assignments for the first 5 nodes
print(role_assignments[:5])

# Get role features
role_features = rolx.get_role_features()
print(role_features)

Advanced Configuration

from torch_rolx.rolx import RolX

# Create RolX with custom parameters
rolx = RolX(
    n_roles=5,                 # Number of roles to extract
    max_iterations=3,          # Maximum iterations for feature extraction
    n_epochs=2000,             # Training epochs for NMF
    learning_rate=0.005,       # Learning rate for optimizer
    device='cuda'              # Use GPU if available
)

# The rest of your code...

API Overview

RolX Class

The main class for role extraction.

rolx = RolX(
    n_roles=4,             # Number of roles to discover
    max_iterations=4,      # Maximum iterations for ReFeX
    refex_params=None,     # Additional parameters for ReFeX
    n_epochs=1000,         # Number of epochs for NMF training
    learning_rate=0.01,    # Learning rate
    device='cpu'           # Computation device ('cpu' or 'cuda')
)

Methods:

  • fit(G): Train the RolX model on graph G
  • transform(): Get role assignments for nodes
  • fit_transform(G): Train the model and return node role assignments
  • get_role_features(): Get feature vectors for each role

ReFeX Class

Extracts recursive features from graphs.

refex = ReFeX(
    max_iterations=2,      # Maximum number of recursive iterations
    normalize=True,        # Whether to normalize features
    device='cpu'           # Computation device
)

References

  • Henderson, K., Gallagher, B., Eliassi-Rad, T., Tong, H., Basu, S., Akoglu, L., Koutra, D., Faloutsos, C., & Li, L. (2012). RolX: Structural Role Extraction & Mining in Large Graphs. Proceedings of the 18th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining.

  • Henderson, K., Gallagher, B., Li, L., Akoglu, L., Eliassi-Rad, T., Tong, H., & Faloutsos, C. (2011). It's Who You Know: Graph Mining Using Recursive Structural Features. Proceedings of the 17th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining.

Metadata

Release files for torch-rolx 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torch-rolx 0.1.0
File Size Uploaded
torch_rolx-0.1.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torch-rolx 0.1.0
File Interpreter ABI Platform
torch_rolx-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.5 kB

Release files / torch_rolx-0.1.0.tar.gz

Download URL torch_rolx-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f8b4690eaa9a44725cf8531446d68e69b06bab643f5424829ed127db0849cef1
BLAKE2b-256 checksum
How to use checksums
99dd808d7b7bf4a00ae84db06737d5ead254c73c759515d9dad4a2005215105d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.2 Darwin/24.3.0

Release files / torch_rolx-0.1.0-py3-none-any.whl

Download URL torch_rolx-0.1.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
53078fbeb4474cc68f84630de5591f4b51444bac7b8925dcfb17b7d32d36bc5b
BLAKE2b-256 checksum
How to use checksums
da63fbc731f27138009132d9e423b5738b5b6f82a24feeb848eeca9f19629042
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.2 Darwin/24.3.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page