8000 GitHub - c0mm4nd/torch-rolx: A PyTorch implementation of the RolX (Role eXtraction) algorithm for role discovery in graphs
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A PyTorch implementation of the RolX (Role eXtraction) algorithm for role discovery in graphs

Notifications You must be signed in to change notification settings

c0mm4nd/torch-rolx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A PyTorch implementation of the RolX (Role eXtraction) algorithm for role discovery in graphs

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0