Skip to main content

No project description provided

Project description

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.

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

torch_rolx-0.1.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

torch_rolx-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: torch_rolx-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.2 Darwin/24.3.0

File hashes

Hashes for torch_rolx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8b4690eaa9a44725cf8531446d68e69b06bab643f5424829ed127db0849cef1
MD5 b7e8baa55488020ecb96e3ea2cbbc7e1
BLAKE2b-256 99dd808d7b7bf4a00ae84db06737d5ead254c73c759515d9dad4a2005215105d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: torch_rolx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.2 Darwin/24.3.0

File hashes

Hashes for torch_rolx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53078fbeb4474cc68f84630de5591f4b51444bac7b8925dcfb17b7d32d36bc5b
MD5 d07f6f5e8e4440197e06717645be0499
BLAKE2b-256 da63fbc731f27138009132d9e423b5738b5b6f82a24feeb848eeca9f19629042

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