This package contains algorithms for graph embedding for networks. All algorithms are implemented in Python, with speed accelerations by numba.
pip install git+https://github.com/skojaku/graphvec.git
For conda
users,
git clone https://github.com/skojaku/graphvec
cd graphvec
conda develop .
See setup.py
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.
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