WEmbed python bindings to calculate weighted node embeddings
Project description
WEmbed
This project contains the source code of WEmbed for calculating low dimensional weighted vertex embeddings.
The library is written in C++ and includes Python bindings.
Below is an example of a two-dimensional embedding calculated by WEmbed.
WEmbed embedding of the internet graph obtained from Boguñá, M., Papadopoulos, F. & Krioukov, D. Sustaining the Internet with hyperbolic mapping . Nat Commun 1, 62 (2010). https://doi.org/10.1038/ncomms1063
The network represents the connections between internet routers. Vertex size represents a weight, calculated by WEmbed, and colors indicate the country of the respective routers IP-Address. Note that WEmbed had no knowledge of the countries during the embedding process and still managed to assign vertices from the same countries similar spacial coordinates.
Installing the Python module
On most Linux systems we provide prebuild binaries, and you should be able to install WEmbed via pip. We recommend creating a new virtual environment before installing WEmbed.
python -m venv .venv
source .venv/bin/activate
pip install wembed
If your Linux system is not supported, or you are on Windows/Mac, pip will try to build WEmbed from source. In this case you have to make sure, that you install all necessary dependencies (see section further below).
Usage and file formats
Both the C++ example and the Python example show how to use the code. A minimal working example for the python bindings might look like this:
import wembed
graph = wembed.readEdgeList("example.edg")
emb_opt = wembed.EmbedderOptions()
emb = wembed.Embedder(graph, emb_opt)
emb.calculateEmbedding()
wembed.writeCoordinates("example.emb", emb.getCoordinates(), emb.getWeights())
-
Start by creating a graph object. This can be done with a file or a
vector of pairsrepresenting an edge list. The graph is assumed to be undirected, connected and with consecutive vertex ids starting at zero. The file is expected to contain one line per edge. Each edge should only be given in one direction. The repository contains a small example graph file. -
Initialize the embedder with the
graphobject and anoptionsobject. You can modify the behavior of the embedder through this options object (e.g. changing the embedding dimension). You can calculate a single gradient descent step throughcalculateStep()or calculate until convergence withcalculateEmbedding(). -
The final embedding can be written to file. It will contain one line per vertex. The first number of every line is the id of the vertex and the next d entries contain the coordinates for this vertex. The last entry represents the weight of the vertex.
Installing Dependencies
In order to compile WEmbed you need to have Eigen3 headers installed.
You can look at the flake.nix for more information.
WEmbed also depends on a few other smaller libraries, these get downloaded automatically by CMake via Fetchcontent (you do not have to worry about them),
look at the root CMakeLists.txt for more information.
Compiling with CMake
The project uses CMake as a build tool (see the root CMakeLists.txt for more details).
In order to build the binaries clone this repository,
create a new folder and call CMake from it.
A bin and lib folder will be created containing the executables and libraries.
git clone git@github.com:Vraier/wembed.git
cd wembed
mkdir release
cd release
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4
Project Structure
All C++ source files can be found in src, this includes the library and small example command line applications for C++. The python folder contains code for the python bindings and an example using these bindings. Unit tests using google test are found in tests.
Work in progress
Note that WEmbed is still quite experimental, expect major changes in the future. Some code sections that will be changed in the immediate future include:
- The repository contains some embedding code that is dead or outdated. This has to be updated or removed
- Remove boost and SNN dependencies
- Fix PyPi CI packaging
- Allow embedding of unconnected graphs (add a global attracting force for that)
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wembed-0.1.0.tar.gz.
File metadata
- Download URL: wembed-0.1.0.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb0c9203a4a4de1ef83cf5ffc10cd51620bbb5584c8500ed60346e074d921461
|
|
| MD5 |
b263e88983e611643e2619b622f90b9e
|
|
| BLAKE2b-256 |
99294a256cd23416823e0c56edf29cae1177397aa44eb22c5e088d87c1b004ec
|
File details
Details for the file wembed-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wembed-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
315c15b6f3900f1166c14a56fc3e2db34302473743487b694a707e7881e5e58d
|
|
| MD5 |
e5695e0d6d303082f480b1db0c07d282
|
|
| BLAKE2b-256 |
67be514570b1b65a6db07e89e27d29e0b9b00593740bd197e1ebab2661cf2103
|
File details
Details for the file wembed-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wembed-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4db22b046114cafe5486852e20351f686387bbf797b1ce9de7b530a0b45a85d4
|
|
| MD5 |
1c3b57a14a80723c3bcce49b54fe3b5a
|
|
| BLAKE2b-256 |
a38c43e4e463ec901c9008ac1c209c9fec61c6b611902cb4c568fe593ef15623
|
File details
Details for the file wembed-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wembed-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
853112af90444a7504e7498bfe8bec48b13f970b2b5c50e87b3ad39435ae881e
|
|
| MD5 |
86b3782200188647c7360739b50c6a68
|
|
| BLAKE2b-256 |
76d4e491714afcddfd227041c7b1c5331ee66d61a2dcadd11bcbdd0f2ba7f190
|
File details
Details for the file wembed-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wembed-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b8beefc84193cf0f955bb9226fc1f14fa3235cef0a8dffe804f32a3576852ad
|
|
| MD5 |
8cbb372a6f0e738fb61c17dd702a0e05
|
|
| BLAKE2b-256 |
6df7aa8a90cf99585a719be1c981ebf71079397c9a89a396db879080248cf9c2
|
File details
Details for the file wembed-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wembed-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e693a7ae780e8e44d81fbc053664314b41f376288358237b6da9ef906f9e6184
|
|
| MD5 |
b313ac2af0ff545ca73dfdec2bf2951a
|
|
| BLAKE2b-256 |
7df45b95deafb59b11373ed803149866a8cc8b1ff6c471365b4dcc1879498b33
|
File details
Details for the file wembed-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wembed-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb3fff31a468140827f4c87444c93f839988fabcc8cbb8f8af985b49d154ee05
|
|
| MD5 |
a5728b6c3f274896b3181dbd3e7737f0
|
|
| BLAKE2b-256 |
1a1a900841ea33f70ecc8a8f4d6ce9d9f0f70d9bb5804d99e58c7731352db2e0
|