graphembed-rs 0.1.0__cp312-cp312-macosx_10_12_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphembed_rs/__init__.py +5 -0
- graphembed_rs/__init__.pyi +79 -0
- graphembed_rs/graphembed_rs.cpython-312-darwin.so +0 -0
- graphembed_rs/py.typed +0 -0
- graphembed_rs-0.1.0.dist-info/METADATA +230 -0
- graphembed_rs-0.1.0.dist-info/RECORD +8 -0
- graphembed_rs-0.1.0.dist-info/WHEEL +4 -0
- graphembed_rs-0.1.0.dist-info/licenses/LICENSE-MIT +25 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
3
|
+
# ---------- Embedding ----------
|
4
|
+
def embed_hope_rank(
|
5
|
+
csv: str,
|
6
|
+
symetric: bool,
|
7
|
+
target_rank: int,
|
8
|
+
nbiter: int,
|
9
|
+
output: Optional[str] = None,
|
10
|
+
) -> None: ...
|
11
|
+
def embed_hope_precision(
|
12
|
+
csv: str,
|
13
|
+
symetric: bool,
|
14
|
+
epsil: float,
|
15
|
+
maxrank: int,
|
16
|
+
blockiter: int,
|
17
|
+
output: Optional[str] = None,
|
18
|
+
) -> None: ...
|
19
|
+
def embed_sketching(
|
20
|
+
csv: str,
|
21
|
+
symetric: bool,
|
22
|
+
decay: float,
|
23
|
+
dim: int,
|
24
|
+
nbiter: int,
|
25
|
+
output: Optional[str] = None,
|
26
|
+
) -> None: ...
|
27
|
+
|
28
|
+
# ---------- Validation (returns mean AUC) ----------
|
29
|
+
def validate_hope_rank(
|
30
|
+
csv: str,
|
31
|
+
symetric: bool,
|
32
|
+
target_rank: int,
|
33
|
+
nbiter: int,
|
34
|
+
nbpass: int = 10,
|
35
|
+
skip_frac: float = 0.1,
|
36
|
+
centric: bool = False,
|
37
|
+
) -> float: ...
|
38
|
+
def validate_hope_precision(
|
39
|
+
csv: str,
|
40
|
+
symetric: bool,
|
41
|
+
epsil: float,
|
42
|
+
maxrank: int,
|
43
|
+
blockiter: int,
|
44
|
+
nbpass: int = 10,
|
45
|
+
skip_frac: float = 0.1,
|
46
|
+
centric: bool = False,
|
47
|
+
) -> float: ...
|
48
|
+
def validate_sketching(
|
49
|
+
csv: str,
|
50
|
+
symetric: bool,
|
51
|
+
decay: float,
|
52
|
+
dim: int,
|
53
|
+
nbiter: int,
|
54
|
+
nbpass: int = 10,
|
55
|
+
skip_frac: float = 0.1,
|
56
|
+
centric: bool = False,
|
57
|
+
) -> float: ...
|
58
|
+
|
59
|
+
# ---------- VCMPR (precision/recall curves) ----------
|
60
|
+
def estimate_vcmpr_hope_rank(
|
61
|
+
csv: str,
|
62
|
+
symetric: bool,
|
63
|
+
target_rank: int,
|
64
|
+
nbiter: int,
|
65
|
+
nbpass: int = 2,
|
66
|
+
topk: int = 10,
|
67
|
+
skip_frac: float = 0.1,
|
68
|
+
) -> None: ...
|
69
|
+
def estimate_vcmpr_sketching(
|
70
|
+
csv: str,
|
71
|
+
symetric: bool,
|
72
|
+
decay: float,
|
73
|
+
dim: int,
|
74
|
+
nbiter: int,
|
75
|
+
nbpass: int = 2,
|
76
|
+
topk: int = 10,
|
77
|
+
skip_frac: float = 0.1,
|
78
|
+
) -> None: ...
|
79
|
+
|
Binary file
|
graphembed_rs/py.typed
ADDED
File without changes
|
@@ -0,0 +1,230 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: graphembed_rs
|
3
|
+
Version: 0.1.0
|
4
|
+
License-File: LICENSE-MIT
|
5
|
+
Summary: Python bindings for the high‑performance Rust graph/network embedding library graphembed
|
6
|
+
Keywords: graph,embedding,hash
|
7
|
+
Author: Jianshu Zhao
|
8
|
+
Author-email: jeanpierre.both@gmail.com
|
9
|
+
License: MIT OR Apache-2.0
|
10
|
+
Requires-Python: >=3.8
|
11
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
12
|
+
Project-URL: Source Code, https://github.com/jean-pierreBoth/graphembed
|
13
|
+
|
14
|
+
[](http://bioconda.github.io/recipes/graphembed/README.html)
|
15
|
+

|
16
|
+

|
17
|
+

|
18
|
+

|
19
|
+
[](https://anaconda.org/bioconda/graphembed)
|
20
|
+
|
21
|
+
|
22
|
+
# GraphEmbed: Efficient and Robust Network Embedding via High-Order Proximity Preservation or Recursive Sketching
|
23
|
+
|
24
|
+
This crate provides an executable and a library for embedding of directed or undirected graphs with positively weighted edges. We engineered and optimized current network embedding algorithms for large-scale network embedding, especially biological network. This crate was developed by [Jianshu Zhao](https://gitlab.com/Jianshu_Zhao) and Jean-Pierre Both [jpboth](https://gitlab.com/jpboth). We have a copy here in [Github](https://github.com/jianshu93/graphembed)
|
25
|
+
|
26
|
+
|
27
|
+
- For simple graphs, without data attached to nodes, there are 2 modules **nodesketch** and **atp**. A simple executable with a validation option based on link prediction is also provided.
|
28
|
+
|
29
|
+
## Quick Install
|
30
|
+
|
31
|
+
### Pre-built binaries on Linux
|
32
|
+
```bash
|
33
|
+
wget https://gitlab.com/-/project/64961144/uploads/ea72ca007e9e4899e0c830e708f52939/graphembed_Linux_x86-64_v0.1.4.zip
|
34
|
+
unzip graphembed_Linux_x86-64_v0.1.4.zip
|
35
|
+
chmod a+x ./graphembed
|
36
|
+
./graphembed -h
|
37
|
+
```
|
38
|
+
|
39
|
+
### Bioconda on Linux
|
40
|
+
```bash
|
41
|
+
conda install -c conda-forge -c bioconda graphembed
|
42
|
+
```
|
43
|
+
|
44
|
+
### Homebrew on MacOS
|
45
|
+
```bash
|
46
|
+
brew tap jianshu93/graphembed
|
47
|
+
brew update
|
48
|
+
brew install graphembed
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
### In Python (Please install python first)
|
53
|
+
```bash
|
54
|
+
pip install graphembed_rs
|
55
|
+
|
56
|
+
### or you can build from source (Linux) after installing maturin
|
57
|
+
git clone https://gitlab.com/Jianshu_Zhao/graphembed
|
58
|
+
cd graphembed
|
59
|
+
pip install maturin
|
60
|
+
### note: for macOS, you need to change the line "features = ["pyo3/extension-module", "intel-mkl-static", "simdeez_f"]" in pyporject.toml to "features = ["pyo3/extension-module","openblas-system","stdsimd"]"
|
61
|
+
maturin develop --release
|
62
|
+
|
63
|
+
#### Prepare some data
|
64
|
+
wget https://gitlab.com/-/project/64961144/uploads/4e341383d62d86d1dd66e668e91b2c07/BlogCatalog.txt
|
65
|
+
```
|
66
|
+
|
67
|
+
```python
|
68
|
+
import os
|
69
|
+
os.environ["RUST_LOG"] = "graphembed=info"
|
70
|
+
import graphembed as ge
|
71
|
+
help(ge)
|
72
|
+
### HOPE
|
73
|
+
ge.embed_hope_rank("BlogCatalog.txt", target_rank=128, nbiter=4)
|
74
|
+
|
75
|
+
### Sketching
|
76
|
+
### sketching only
|
77
|
+
ge.embed_sketching("BlogCatalog.txt", decay=0.3, dim=128, nbiter=5, symetric=True, output="embedding_output")
|
78
|
+
### validate accuracy
|
79
|
+
auc_scores = ge.validate_sketching("BlogCatalog.txt",decay=0.3, dim=128, nbiter=3, nbpass=1, skip_frac=0.2,symetric=True, centric=True)
|
80
|
+
print("Standard AUC per pass:", auc_scores)
|
81
|
+
```
|
82
|
+
|
83
|
+
## Methods
|
84
|
+
### The embedding algorithms used in this crate are based on the following papers
|
85
|
+
|
86
|
+
- **nodesketch**
|
87
|
+
|
88
|
+
*NodeSketch : Highly-Efficient Graph Embeddings via Recursive Sketching KDD 2019*. see [nodesketch](https://dl.acm.org/doi/10.1145/3292500.3330951)
|
89
|
+
D. Yang,P. Rosso,Bin-Li, P. Cudre-Mauroux.
|
90
|
+
|
91
|
+
It is based on multi hop neighbourhood identification via sensitive hashing based on the recent algorithm **probminhash**. See [arxiv](https://arxiv.org/abs/1911.00675) or [ieee-2022](https://ieeexplore.ieee.org/document/9185081).
|
92
|
+
|
93
|
+
The algorithm associates a probability distribution on neighbours of each point depending on edge weights and distance to the point.
|
94
|
+
Then this distribution is hashed to build a (discrete) embedding vector consisting in nodes identifiers.
|
95
|
+
The distance between embedded vectors is the Jaccard distance so we get
|
96
|
+
a real distance on the embedding space for the symetric embedding.
|
97
|
+
|
98
|
+
An extension of the paper is also implemented to get asymetric embedding for directed graph. The similarity is also based on the hash of sets (nodes going to or from) a given node but then the dissimilarity is no more a distance (no symetry and some discrepancy with the triangular inequality).
|
99
|
+
|
100
|
+
**The orkut graph with 3 millions nodes and 100 millions of edge is embedded in 5' with a 24 core i9 laptop with this algorithm giving an AUC of 0.95**.
|
101
|
+
|
102
|
+
|
103
|
+
- **atp**
|
104
|
+
|
105
|
+
*Asymetric Transitivity Preserving Graph Embedding 2016*.
|
106
|
+
M. Ou, P Cui, J. Pei, Z. Zhang and W. Zhu. See [hope](https://dl.acm.org/doi/10.1145/2939672.2939751).
|
107
|
+
|
108
|
+
The objective is to provide an asymetric graph embedding and get estimate of the precision of the embedding in function of its dimension.
|
109
|
+
|
110
|
+
We use the Adamic-Adar matricial representation of the graph. (It must be noted that the ponderation of a node by the number of couples joined by it is called Resource Allocation in the Graph Kernel litterature).
|
111
|
+
The asymetric embedding is obtained from the left and right singular eigenvectors of the Adamic-Adar representation of the graph.
|
112
|
+
Source node are related to left singular vectors and target nodes to the right ones.
|
113
|
+
The similarity measure is the dot product, so it is not a norm.
|
114
|
+
The svd is approximated by randomization as described in Halko-Tropp 2011 as implemented in the [annembed crate](https://crates.io/crates/annembed).
|
115
|
+
|
116
|
+
## Validation
|
117
|
+
|
118
|
+
Validation of embeddings is assessed via standard Auc with random deletion of edges. See documentation in the *link* module and *embed* binary.
|
119
|
+
We give also a variation based on centric quality assessment as explained at [cauc](http://github.com/jean-pierreBoth/linkauc)
|
120
|
+
## Some data sets
|
121
|
+
|
122
|
+
Small datasets are given in the Data subdirectory (with 7z compression) to run tests.
|
123
|
+
Larger datasets can be downloaded from the SNAP data collections <https://snap.stanford.edu/data>
|
124
|
+
|
125
|
+
#### Some small test graphs are provided in a Data subdirectory
|
126
|
+
|
127
|
+
- Symetric graphs
|
128
|
+
|
129
|
+
- Les miserables <http://konect.cc/networks/moreno_lesmis>.
|
130
|
+
This is the graph of co-occurence of characters in Victor Hugo's novel 'Les Misérables'.
|
131
|
+
|
132
|
+
- Asymetric graphs
|
133
|
+
|
134
|
+
- wiki-vote <https://snap.stanford.edu/data/wiki-Vote.html>
|
135
|
+
7115 nodes 103689 edges
|
136
|
+
|
137
|
+
- Cora : <http://konect.cc/networks/subelj_cora>
|
138
|
+
citation network 23166 nodes 91500 edges
|
139
|
+
|
140
|
+
#### Some larger data tests for user to download
|
141
|
+
|
142
|
+
These graphs were used in results see below.
|
143
|
+
|
144
|
+
Beware of the possible need to convert from Windows to Linux End Of Line, see the dos2unix utility.
|
145
|
+
Possibly some data can need to be converted from Tsv format to Csv, before being read by the program.
|
146
|
+
|
147
|
+
- Symetric
|
148
|
+
|
149
|
+
- Amazon. Nodes: 334 863 Edges: 925 872 <https://snap.stanford.edu/data/amazon0601.html>
|
150
|
+
- youtube. Nodes: 1 134 890 Edges: 2 987 624 <https://snap.stanford.edu/data/com-Youtube.html>
|
151
|
+
- orkut. Nodes: 3 072 441 Edges: 117 185 083 <https://snap.stanford.edu/data/com-Orkut.html>
|
152
|
+
|
153
|
+
- Asymetric
|
154
|
+
|
155
|
+
- twitter as tested in Hope <http://konect.cc/networks/munmun_twitter_social>
|
156
|
+
465017 nodes 834797 edges
|
157
|
+
|
158
|
+
## Some results
|
159
|
+
|
160
|
+
### results for the *atp* and *nodesketch* modules
|
161
|
+
|
162
|
+
Embedding and link prediction evaluation for the above data sets are given in file [resultats.md](./resultats.md)
|
163
|
+
A more global analysis of the embedding with the nodesketch module is done for the orkut graph in file [orkut.md](./orkut.md)
|
164
|
+
|
165
|
+
A preliminary of node centric quality estimation is provided in the validation module (see documentation in validation::link).
|
166
|
+
|
167
|
+
### Some qualitative comments
|
168
|
+
|
169
|
+
- For the embedding using the randomized svd, increasing the embedding dimension is interesting as far as the corresponding eigenvalues continue to decrease significantly.
|
170
|
+
|
171
|
+
- The munmun_twitter_social graph shows that treating a directed graph as an undirected graph give significantly different results in terms of link prediction AUC.
|
172
|
+
|
173
|
+
|
174
|
+
## Generalized Svd
|
175
|
+
|
176
|
+
An implementation of Generalized Svd comes as a by-product in module [gsvd](./src/atp/gsvd.rs).
|
177
|
+
|
178
|
+
## Detailed Installation and Usage
|
179
|
+
|
180
|
+
### Installation
|
181
|
+
|
182
|
+
The crate provides features (with a default configuration), required by the *annembed* dependency, to specify which version of lapack you want to use or the choice of simd implementation.
|
183
|
+
- For example compilation is done by :
|
184
|
+
*cargo build --release --features="openblas-system"* to use a dynamic link with openblas.
|
185
|
+
The choice of one feature is mandatory to provide required linear algebra library.
|
186
|
+
- On Intel the simdeez_f feature can be used. On other cpus the stdsimd feature can be chosen but it requires compiler >= 1.79
|
187
|
+
|
188
|
+
### Usage
|
189
|
+
|
190
|
+
The embed module can be generated with the standard : cargo doc --no-deps --bin embed.
|
191
|
+
|
192
|
+
- The Hope embedding relying on matrices computations limits the size of the graph to some hundred thousands nodes.
|
193
|
+
It is intrinsically asymetric in nature. It nevertheless gives access to the spectrum of Adamic Adar matrix representing the graph and
|
194
|
+
so to the required dimension to get a valid embedding in $R^{n}$.
|
195
|
+
|
196
|
+
- The Sketching embedding is much faster for large graphs but embeds in a space consisting in sequences of node id equipped with the Jaccard distance. It is particularly efficient in low degrees graph.
|
197
|
+
|
198
|
+
- The *embed* module takes embedding and possibly validation commands (link prediction task) in one directive.
|
199
|
+
The general syntax is :
|
200
|
+
|
201
|
+
graphembed file_description [validation_command --validation_arguments] sketching mode --embedding_arguments
|
202
|
+
for example:
|
203
|
+
|
204
|
+
For a symetric graph we get:
|
205
|
+
|
206
|
+
- just embedding:
|
207
|
+
graphembed --csv ./Data/Graphs/Orkut/com-orkut.ungraph.txt --symetric sketching --decay 0.2 --dim 200 --nbiter
|
208
|
+
|
209
|
+
- embedding and validation:
|
210
|
+
|
211
|
+
graphembed --csv ./Data/Graphs/Orkut/com-orkut.ungraph.txt --symetric validation --nbpass 5 --skip 0.15 sketching --decay 0.2 --dim 200 --nbiter 5
|
212
|
+
|
213
|
+
For an asymetric graph we get
|
214
|
+
|
215
|
+
graphembed --csv ./Data/Graphs/asymetric.csv validation --nbpass 5 --skip 0.15 sketching --decay 0.2 --dim 200 --nbiter 5
|
216
|
+
|
217
|
+
|
218
|
+
More details can be found in docs of the embed module. Use cargo doc --no-dep --bin embed (and cargo doc --no-dep) as usual.
|
219
|
+
|
220
|
+
- Use the environment variable RUST_LOG gives access to some information at various level (debug, info, error) via the **log** and **env_logger** crates.
|
221
|
+
|
222
|
+
## License
|
223
|
+
|
224
|
+
Licensed under either of
|
225
|
+
|
226
|
+
* Apache License, Version 2.0, [LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>
|
227
|
+
* MIT license [LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>
|
228
|
+
|
229
|
+
at your option.
|
230
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
graphembed_rs-0.1.0.dist-info/METADATA,sha256=i3R39b6-1qrXlFd_tEQOVf-miAnLfgDy53oUQMkJ59c,10890
|
2
|
+
graphembed_rs-0.1.0.dist-info/WHEEL,sha256=jKg_qhGQRID055hVxosWMB2IKmS8PlXSmgpiuDvBEvk,106
|
3
|
+
graphembed_rs-0.1.0.dist-info/licenses/LICENSE-MIT,sha256=ndZ12D28O4UkfOeoa6HP9E7IKyYG4iH79iQ6WiLs9bc,1077
|
4
|
+
graphembed_rs/__init__.py,sha256=R2D0If_-sN__21LBYNod0CNgVo2dCd2RqM11AStM3X0,135
|
5
|
+
graphembed_rs/__init__.pyi,sha256=3_KBFG4g9akylo32CHlm9bZStcLwxIY2X4si21ilD3w,1626
|
6
|
+
graphembed_rs/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
+
graphembed_rs/graphembed_rs.cpython-312-darwin.so,sha256=WdWX0Zhp0PpiDYZGv_EoQ5G69arnDsWersPUuB6SA7c,5339916
|
8
|
+
graphembed_rs-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2022 jean-pierre.both and Jianshu Zhao
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any
|
4
|
+
person obtaining a copy of this software and associated
|
5
|
+
documentation files (the "Software"), to deal in the
|
6
|
+
Software without restriction, including without
|
7
|
+
limitation the rights to use, copy, modify, merge,
|
8
|
+
publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software
|
10
|
+
is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice
|
14
|
+
shall be included in all copies or substantial portions
|
15
|
+
of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
18
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
19
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
20
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
21
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
24
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
25
|
+
DEALINGS IN THE SOFTWARE.
|