Skip to content

skojaku/graphvec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Python package for graph embedding methods

Unit Test & Deploy

This package contains algorithms for graph embedding for networks. All algorithms are implemented in Python, with speed accelerations by numba.

Contents

Installation

pip install git+https://github.com/skojaku/graphvec.git

For conda users,

git clone https://github.com/skojaku/graphvec
cd graphvec
conda develop .

Dependency:

See setup.py

Usage

Following the scikit-learn's API design, all algorithms have two methods.fit and .transform. The .fit method takes a network to learn the network structure, and the .transform produces the emebdding of nodes. More specifically, follow the steps below.

First, load a graph embedding method. For demonstration, we use Node2Vec. See the "Available algorithms" Section for other graph embedding methods.

import graphvec
model = graphvec.Node2Vec()

Second, call .fit with the network A:

model.fit(A)

where A is the adjacency matrix in scipy.sparse format. For networkx user, networkx.Graph can be converted to the scipy.sparse format by A = nx.adjacency_matrix(G).

Lastly, call .transform to generate an embedding:

emb = model.transform(dim=64)

where dim is the number of dimensions. emb is a numpy.ndarray with size (number of nodes, dim). The ith row in emb (emb[i, :]) is the embedding vector of the ith node in the given adjacency matrix.

Available algorithms

Algorithm Reference
graphvec.Node2Vec Grover, Aditya, and Jure Leskovec. "node2vec: Scalable feature learning for networks." Proceedings of the 22nd ACM SIGKDD international conference on Knowledge discovery and data mining. 2016.
graphvec.LINE Tang, Jian, et al. "Line: Large-scale information network embedding." Proceedings of the 24th international conference on World Wide Web. 2015.
graphvec.DeepWalk Perozzi, Bryan, Rami Al-Rfou, and Steven Skiena. "Deepwalk: Online learning of social representations." Proceedings of the 20th ACM SIGKDD international conference on Knowledge discovery and data mining. 2014.
graphvec.LaplacianEigenMap Belkin, Mikhail, and Partha Niyogi. "Laplacian eigenmaps and spectral techniques for embedding and clustering." Advances in neural information processing systems 14 (2001).
graphvec.ModularityMatrixSpectralEmbedding Nadakuditi, Raj Rao, and Mark EJ Newman. "Graph spectra and the detectability of community structure in networks." Physical review letters 108.18 (2012): 188701.
graphvec.AdjacencyMatrixSpectralEmbedding The spectrum of the adjacency matrix
graphvec.NonBacktrackingSpectralEmbedding Krzakala, Florent, et al. "Spectral redemption in clustering sparse networks." Proceedings of the National Academy of Sciences 110.52 (2013): 20935-20940.
graphvec.FastRP Chen, Haochen, et al. "Fast and accurate network embeddings via very sparse random projection." Proceedings of the 28th ACM international conference on information and knowledge management. 2019.

For development

Install

conda create -n graphvec python=3.9
conda activate graphvec
conda install -c conda-forge mamba -y
mamba install -c conda-forge graph-tool scikit-learn numpy numba scipy pandas networkx seaborn matplotlib gensim ipykernel tqdm black -y
mamba install -c conda-forge numpy==1.23.5

About

Toolkit for graph embedding

Resources

License

Stars

Watchers

Forks

Packages

No packages published