pysurprise 1.0.0__tar.gz
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.
Potentially problematic release.
This version of pysurprise might be problematic. Click here for more details.
- pysurprise-1.0.0/MANIFEST.in +7 -0
- pysurprise-1.0.0/PKG-INFO +184 -0
- pysurprise-1.0.0/README +166 -0
- pysurprise-1.0.0/net_examples/karate.pairs +78 -0
- pysurprise-1.0.0/net_examples/network1000.pairs +9983 -0
- pysurprise-1.0.0/net_examples/sample.pairs +4 -0
- pysurprise-1.0.0/pyproject.toml +63 -0
- pysurprise-1.0.0/pysurprise/LICENSE +14 -0
- pysurprise-1.0.0/pysurprise/README.md +150 -0
- pysurprise-1.0.0/pysurprise/csrc/bindings.cpp +191 -0
- pysurprise-1.0.0/pysurprise/csrc/surprise.cpp +130 -0
- pysurprise-1.0.0/pysurprise/csrc/surprise.h +57 -0
- pysurprise-1.0.0/pysurprise/src/pysurprise/__init__.py +38 -0
- pysurprise-1.0.0/pysurprise/src/pysurprise/_api.py +71 -0
- pysurprise-1.0.0/pysurprise/src/pysurprise/algorithms.py +547 -0
- pysurprise-1.0.0/pysurprise/src/pysurprise.egg-info/PKG-INFO +184 -0
- pysurprise-1.0.0/pysurprise/src/pysurprise.egg-info/SOURCES.txt +20 -0
- pysurprise-1.0.0/pysurprise/src/pysurprise.egg-info/dependency_links.txt +1 -0
- pysurprise-1.0.0/pysurprise/src/pysurprise.egg-info/requires.txt +10 -0
- pysurprise-1.0.0/pysurprise/src/pysurprise.egg-info/top_level.txt +1 -0
- pysurprise-1.0.0/setup.cfg +4 -0
- pysurprise-1.0.0/setup.py +24 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pysurprise
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python bindings for the Surprise network community structure metric
|
|
5
|
+
Author: José Marín
|
|
6
|
+
Maintainer-email: Rodrigo Aldecoa <raldecoa@ibv.csic.es>, Ignacio Marín <imarin@ibv.csic.es>
|
|
7
|
+
License-Expression: GPL-3.0-or-later
|
|
8
|
+
Project-URL: Homepage, https://github.com/raldecoa/SurpriseMe
|
|
9
|
+
Project-URL: Repository, https://github.com/raldecoa/SurpriseMe
|
|
10
|
+
Project-URL: Issues, https://github.com/raldecoa/SurpriseMe/issues
|
|
11
|
+
Keywords: networks,community-detection,surprise,graph,clustering,bioinformatics
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: C++
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Provides-Extra: algorithms
|
|
28
|
+
Requires-Dist: infomap>=2.0; extra == "algorithms"
|
|
29
|
+
Requires-Dist: igraph>=0.10; extra == "algorithms"
|
|
30
|
+
Provides-Extra: infomap
|
|
31
|
+
Requires-Dist: infomap>=2.0; extra == "infomap"
|
|
32
|
+
Provides-Extra: igraph
|
|
33
|
+
Requires-Dist: igraph>=0.10; extra == "igraph"
|
|
34
|
+
|
|
35
|
+
# pySurprise
|
|
36
|
+
|
|
37
|
+
Python package for computing the **Surprise** metric and running community
|
|
38
|
+
detection algorithms on complex networks.
|
|
39
|
+
|
|
40
|
+
Surprise quantifies the quality of a partition of a complex network into
|
|
41
|
+
communities using a cumulative hypergeometric distribution. Higher values
|
|
42
|
+
indicate a more *surprising* (i.e. better) community structure.
|
|
43
|
+
|
|
44
|
+
**pySurprise** wraps the original C++ Surprise computation via pybind11 for
|
|
45
|
+
maximum performance, and provides Python access to **7 clustering algorithms**
|
|
46
|
+
from the [SurpriseMe](https://github.com/raldecoa/SurpriseMe) project.
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install pysurprise
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To use the clustering algorithms that depend on optional packages:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Install all algorithm dependencies
|
|
58
|
+
pip install pysurprise[algorithms]
|
|
59
|
+
|
|
60
|
+
# Or individually
|
|
61
|
+
pip install pysurprise[infomap] # for Infomap
|
|
62
|
+
pip install pysurprise[igraph] # for RN
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### From source
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/raldecoa/SurpriseMe.git
|
|
69
|
+
cd SurpriseMe
|
|
70
|
+
pip install .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick start
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import pysurprise
|
|
77
|
+
|
|
78
|
+
# Define edges (undirected, listed once)
|
|
79
|
+
edges = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3),
|
|
80
|
+
(3, 4), (4, 5), (4, 6), (4, 7), (5, 6), (5, 7), (6, 7)]
|
|
81
|
+
|
|
82
|
+
# Partition: node i belongs to community partition[i]
|
|
83
|
+
partition = [0, 0, 0, 0, 1, 1, 1, 1]
|
|
84
|
+
|
|
85
|
+
value = pysurprise.surprise(edges, partition)
|
|
86
|
+
print(f"Surprise = {value}")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Using string labels
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
edges = [("a", "b"), ("a", "c"), ("b", "c"),
|
|
93
|
+
("c", "d"), ("d", "e"), ("d", "f"), ("e", "f")]
|
|
94
|
+
|
|
95
|
+
partition = {"a": 0, "b": 0, "c": 0, "d": 1, "e": 1, "f": 1}
|
|
96
|
+
|
|
97
|
+
value = pysurprise.surprise(edges, partition)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Low-level access
|
|
101
|
+
|
|
102
|
+
If you already have the four Surprise parameters (F, M, n, p):
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from pysurprise import compute_surprise
|
|
106
|
+
|
|
107
|
+
F = 28.0 # total possible pairs: N*(N-1)/2
|
|
108
|
+
M = 12.0 # intra-community possible pairs
|
|
109
|
+
n = 13.0 # total edges
|
|
110
|
+
p = 12.0 # intra-community edges
|
|
111
|
+
|
|
112
|
+
value = compute_surprise(F, M, n, p)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Clustering algorithms
|
|
116
|
+
|
|
117
|
+
`pysurprise.algorithms` exposes the 7 community detection algorithms from
|
|
118
|
+
SurpriseMe, ready to use from Python:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from pysurprise import algorithms
|
|
122
|
+
import pysurprise
|
|
123
|
+
|
|
124
|
+
# Run a single algorithm
|
|
125
|
+
partition = algorithms.cpm(edges)
|
|
126
|
+
score = pysurprise.surprise(edges, partition)
|
|
127
|
+
|
|
128
|
+
# Run all 7 algorithms and compare
|
|
129
|
+
results = algorithms.run_all(edges)
|
|
130
|
+
for name, part in results.items():
|
|
131
|
+
s = pysurprise.surprise(edges, part)
|
|
132
|
+
print(f"{name}: {s:.4f}")
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
| Algorithm | Function | Reference |
|
|
136
|
+
|-----------|----------|-----------|
|
|
137
|
+
| **CPM** | `algorithms.cpm()` | Traag et al., *Phys. Rev. E* 84 (2011) |
|
|
138
|
+
| **Infomap** | `algorithms.infomap()` | Rosvall & Bergstrom, *PNAS* 105 (2008) |
|
|
139
|
+
| **RB** | `algorithms.rb()` | Reichardt & Bornholdt, *Phys. Rev. E* 74 (2006) |
|
|
140
|
+
| **RN** | `algorithms.rn()` | Ronhovde & Nussinov, *Phys. Rev. E* 81 (2010) |
|
|
141
|
+
| **RNSC** | `algorithms.rnsc()` | King et al., *Bioinformatics* 20 (2004) |
|
|
142
|
+
| **SCluster** | `algorithms.scluster()` | Aldecoa & Marín, *PLoS ONE* 5 (2010) |
|
|
143
|
+
| **UVCluster** | `algorithms.uvcluster()` | Arnau et al., *Bioinformatics* 21 (2005) |
|
|
144
|
+
|
|
145
|
+
All functions accept `edges: list[(str, str)]` and return
|
|
146
|
+
`dict[str, int]` (node → community).
|
|
147
|
+
|
|
148
|
+
## API Reference
|
|
149
|
+
|
|
150
|
+
| Function | Description |
|
|
151
|
+
|---|---|
|
|
152
|
+
| `surprise(edges, partition)` | High-level: compute Surprise from edges and partition (list or dict) |
|
|
153
|
+
| `compute_surprise(F, M, n, p)` | Low-level: compute Surprise from the four parameters directly |
|
|
154
|
+
| `surprise_from_partition(edges, partition)` | C++ binding: int-indexed edges and partition list |
|
|
155
|
+
| `surprise_from_partition_dict(edges, partition)` | C++ binding: string-labelled edges and partition dict |
|
|
156
|
+
| `log_hyper_probability(F, M, n, j)` | Single hypergeometric probability term (log10) |
|
|
157
|
+
| `algorithms.run_all(edges)` | Run all 7 clustering algorithms and return results |
|
|
158
|
+
|
|
159
|
+
## Parameters
|
|
160
|
+
|
|
161
|
+
- **F**: Total number of possible node pairs = N×(N−1)/2
|
|
162
|
+
- **M**: Sum of intra-community possible pairs = Σ s_i×(s_i−1)/2
|
|
163
|
+
- **n**: Total number of edges in the network
|
|
164
|
+
- **p**: Number of intra-community edges
|
|
165
|
+
|
|
166
|
+
## Credits
|
|
167
|
+
|
|
168
|
+
**Developed by** José Marín.
|
|
169
|
+
|
|
170
|
+
**Based on the original Surprise metric and SurpriseMe software by:**
|
|
171
|
+
|
|
172
|
+
> Aldecoa R, Marín I (2011). *Deciphering network community structure by Surprise.*
|
|
173
|
+
> PLoS ONE 6(9): e24195.
|
|
174
|
+
|
|
175
|
+
> Aldecoa R, Marín I (2013). *Surprise maximization reveals the community structure
|
|
176
|
+
> of complex networks.* Scientific Reports 3, 1060.
|
|
177
|
+
|
|
178
|
+
The C++ Surprise computation and bundled clustering algorithms originate from
|
|
179
|
+
the [SurpriseMe](https://github.com/raldecoa/SurpriseMe) project by
|
|
180
|
+
Rodrigo Aldecoa and Ignacio Marín.
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
GPL-3.0-or-later. See [LICENSE](LICENSE).
|
pysurprise-1.0.0/README
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
* SurpriseMe - An integrated tool for network community structure
|
|
2
|
+
characterization using Surprise maximization *
|
|
3
|
+
----------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
SurpriseMe is a free, open source software for detecting community structure
|
|
6
|
+
in networks. The program uses Surprise to evaluate the outputs of 7 high-
|
|
7
|
+
quality community detection algorithms. It also generates distance matrices
|
|
8
|
+
that allow to visualize the relationships among the solutions generated.
|
|
9
|
+
|
|
10
|
+
You can find more information here:
|
|
11
|
+
|
|
12
|
+
arxiv.org/abs/1310.2357
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
License
|
|
16
|
+
=======
|
|
17
|
+
|
|
18
|
+
Copyright (C) 2013 Rodrigo Aldecoa and Ignacio Marín
|
|
19
|
+
This software is distributed under the GNU General Public License
|
|
20
|
+
version 3.0 (GPLv3). You should have received a copy of this license
|
|
21
|
+
with the program. Also, it can be found online at
|
|
22
|
+
http://www.opensource.org/licenses/gpl-3.0.html.
|
|
23
|
+
|
|
24
|
+
Version
|
|
25
|
+
=======
|
|
26
|
+
|
|
27
|
+
SupriseMe 1.0
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
Interesting related papers
|
|
31
|
+
==========================
|
|
32
|
+
|
|
33
|
+
For more information about Surprise, please check out:
|
|
34
|
+
|
|
35
|
+
* "Deciphering network community structure by Surprise".
|
|
36
|
+
Rodrigo Aldecoa and Ignacio Marín.
|
|
37
|
+
PloS ONE 6, e24195 (2011).
|
|
38
|
+
http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0024195
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
and:
|
|
42
|
+
|
|
43
|
+
* "Surprise maximization reveals the community structure of complex networks".
|
|
44
|
+
Rodrigo Aldecoa and Ignacio Marín.
|
|
45
|
+
Scientific Reports 3, 1060 (2013).
|
|
46
|
+
http://www.nature.com/srep/2013/130114/srep01060/full/srep01060.html
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
Programs included in this distribution
|
|
51
|
+
======================================
|
|
52
|
+
|
|
53
|
+
The following algorithms are included in SurpriseMe. If you use their solutions
|
|
54
|
+
in your publications, please cite them appropriately:
|
|
55
|
+
|
|
56
|
+
CPM: "Narrow scope for resolution-limit-free community detection"
|
|
57
|
+
Traag VA, Van Dooren P, Nesterov Y
|
|
58
|
+
Phys. Rev. E 84, 016114 (2011)
|
|
59
|
+
|
|
60
|
+
Infomap: "Maps of random walks on complex networks reveal community structure"
|
|
61
|
+
Rosvall M, Bergstrom CT
|
|
62
|
+
Proc. Natl. Acad. Sci. USA 105, 1118 (2008)
|
|
63
|
+
|
|
64
|
+
RB: "Statistical mechanics of community detection"
|
|
65
|
+
Reichardt J, Bornholdt S
|
|
66
|
+
Phys. Rev. E 74, 016110 (2006)
|
|
67
|
+
|
|
68
|
+
RN: "Local resolution-limit-free Potts model for community detection"
|
|
69
|
+
Ronhovde P, Nussinov Z
|
|
70
|
+
Phys. Rev. E 81, 046114 (2010)
|
|
71
|
+
|
|
72
|
+
RNSC: "Protein complex prediction via cost-based clustering"
|
|
73
|
+
King AD, Przulj N, Jurisica I
|
|
74
|
+
Bioinformatics 20, 3013 (2004)
|
|
75
|
+
|
|
76
|
+
SCluster: "Jerarca: efficient analysis of complex networks using hierarchical clustering"
|
|
77
|
+
Aldecoa R, Marin I
|
|
78
|
+
Plos ONE 5, e11585 (2010)
|
|
79
|
+
|
|
80
|
+
UVCluster: "Iterative cluster analysis of protein interaction data"
|
|
81
|
+
Arnau V, Mars S, Marin I
|
|
82
|
+
Bioinformatics 21, 364 (2005)
|
|
83
|
+
(and also the same reference as SCluster)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
Compilation
|
|
87
|
+
===========
|
|
88
|
+
|
|
89
|
+
Note: The code should compile in any Linux distribution using its basic,
|
|
90
|
+
standard libraries (g++, make...).
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
Unzip the tar.gz file and enter the directory:
|
|
94
|
+
|
|
95
|
+
tar -xvzf SurpriseMe.tar.gz
|
|
96
|
+
cd SurpriseMe
|
|
97
|
+
|
|
98
|
+
Build and compile the program:
|
|
99
|
+
|
|
100
|
+
make
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
Usage
|
|
105
|
+
=====
|
|
106
|
+
|
|
107
|
+
Once the program is compiled, just run:
|
|
108
|
+
|
|
109
|
+
./SurpriseMe.pl networkFile
|
|
110
|
+
|
|
111
|
+
where networkFile is the file containing the network to be analyzed.
|
|
112
|
+
Each line of network_file should be of the form
|
|
113
|
+
|
|
114
|
+
id_1 id_2
|
|
115
|
+
|
|
116
|
+
if node with id_1 is connected with node with id_2. Links are assumed
|
|
117
|
+
bidirectional, so that if id_1 id_2 is present in networkFile then
|
|
118
|
+
id_2 id_1 should not be present. Some examples of this format can be
|
|
119
|
+
seen in the net_examples folder.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
./SurpriseMe net_examples/sample.pairs
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
Output files
|
|
128
|
+
=============
|
|
129
|
+
|
|
130
|
+
The execution of the program creates the following files:
|
|
131
|
+
|
|
132
|
+
- networkFile.S Contains the value of Surprise for the
|
|
133
|
+
solution of each algorithm.
|
|
134
|
+
|
|
135
|
+
- networkFile_algorithm.part Partition obtained by an algorithm.
|
|
136
|
+
Each line contains the name of a node
|
|
137
|
+
and its corresponding community
|
|
138
|
+
|
|
139
|
+
- networkFile_VI.meg MEGA (www.megasoftware.net) input file.
|
|
140
|
+
Contains the distance matrix of all
|
|
141
|
+
solutions. Uses the Variation of
|
|
142
|
+
Information as a distance between partitions.
|
|
143
|
+
|
|
144
|
+
- networkFile_1-NMI.meg MEGA (www.megasoftware.net) input file.
|
|
145
|
+
Contains the distance matrix of all
|
|
146
|
+
solutions. Uses (1 minus the Normalized
|
|
147
|
+
Mutual Information) as a distance between
|
|
148
|
+
partitions.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
How to run only certain algorithms
|
|
152
|
+
==================================
|
|
153
|
+
|
|
154
|
+
You can modify line 27 in SurpriseMe.pl in order to run only a few algorithms.
|
|
155
|
+
By default, the program runs all of them. Just remove from the array @algs
|
|
156
|
+
those you want to exclude from the analysis.
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
Resources. Report bugs or suggestions
|
|
161
|
+
=====================================
|
|
162
|
+
|
|
163
|
+
* Homepage: https://github.com/raldecoa/SurpriseMe
|
|
164
|
+
|
|
165
|
+
* Email: Rodrigo Aldecoa <raldecoa (at) ibv.csic.es>
|
|
166
|
+
Ignacio Marín <imarin (at) ibv.csic.es>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
2 1
|
|
2
|
+
3 1
|
|
3
|
+
4 1
|
|
4
|
+
5 1
|
|
5
|
+
6 1
|
|
6
|
+
7 1
|
|
7
|
+
8 1
|
|
8
|
+
9 1
|
|
9
|
+
11 1
|
|
10
|
+
12 1
|
|
11
|
+
13 1
|
|
12
|
+
14 1
|
|
13
|
+
18 1
|
|
14
|
+
20 1
|
|
15
|
+
22 1
|
|
16
|
+
32 1
|
|
17
|
+
3 2
|
|
18
|
+
4 2
|
|
19
|
+
8 2
|
|
20
|
+
14 2
|
|
21
|
+
18 2
|
|
22
|
+
20 2
|
|
23
|
+
22 2
|
|
24
|
+
31 2
|
|
25
|
+
4 3
|
|
26
|
+
8 3
|
|
27
|
+
9 3
|
|
28
|
+
10 3
|
|
29
|
+
14 3
|
|
30
|
+
28 3
|
|
31
|
+
29 3
|
|
32
|
+
33 3
|
|
33
|
+
8 4
|
|
34
|
+
13 4
|
|
35
|
+
14 4
|
|
36
|
+
7 5
|
|
37
|
+
11 5
|
|
38
|
+
7 6
|
|
39
|
+
11 6
|
|
40
|
+
17 6
|
|
41
|
+
17 7
|
|
42
|
+
31 9
|
|
43
|
+
33 9
|
|
44
|
+
34 9
|
|
45
|
+
34 10
|
|
46
|
+
34 14
|
|
47
|
+
33 15
|
|
48
|
+
34 15
|
|
49
|
+
33 16
|
|
50
|
+
34 16
|
|
51
|
+
33 19
|
|
52
|
+
34 19
|
|
53
|
+
34 20
|
|
54
|
+
33 21
|
|
55
|
+
34 21
|
|
56
|
+
33 23
|
|
57
|
+
34 23
|
|
58
|
+
26 24
|
|
59
|
+
28 24
|
|
60
|
+
30 24
|
|
61
|
+
33 24
|
|
62
|
+
34 24
|
|
63
|
+
26 25
|
|
64
|
+
28 25
|
|
65
|
+
32 25
|
|
66
|
+
32 26
|
|
67
|
+
30 27
|
|
68
|
+
34 27
|
|
69
|
+
34 28
|
|
70
|
+
32 29
|
|
71
|
+
34 29
|
|
72
|
+
33 30
|
|
73
|
+
34 30
|
|
74
|
+
33 31
|
|
75
|
+
34 31
|
|
76
|
+
33 32
|
|
77
|
+
34 32
|
|
78
|
+
34 33
|