nsppk 1.3.1__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.
- nsppk-1.3.1/LICENSE +21 -0
- nsppk-1.3.1/PKG-INFO +142 -0
- nsppk-1.3.1/README.md +114 -0
- nsppk-1.3.1/pyproject.toml +45 -0
- nsppk-1.3.1/setup.cfg +4 -0
- nsppk-1.3.1/src/graph_io.py +538 -0
- nsppk-1.3.1/src/hash.py +109 -0
- nsppk-1.3.1/src/importance_nsppk.py +229 -0
- nsppk-1.3.1/src/nsppk.egg-info/PKG-INFO +142 -0
- nsppk-1.3.1/src/nsppk.egg-info/SOURCES.txt +18 -0
- nsppk-1.3.1/src/nsppk.egg-info/dependency_links.txt +1 -0
- nsppk-1.3.1/src/nsppk.egg-info/requires.txt +11 -0
- nsppk-1.3.1/src/nsppk.egg-info/top_level.txt +5 -0
- nsppk-1.3.1/src/nsppk.py +1918 -0
- nsppk-1.3.1/src/utils.py +272 -0
- nsppk-1.3.1/tests/test_encoder_api.py +134 -0
- nsppk-1.3.1/tests/test_hash.py +35 -0
- nsppk-1.3.1/tests/test_importance_archive.py +142 -0
- nsppk-1.3.1/tests/test_shortest_path_union.py +38 -0
- nsppk-1.3.1/tests/test_streaming.py +502 -0
nsppk-1.3.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 XFCOSTA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
nsppk-1.3.1/PKG-INFO
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nsppk
|
|
3
|
+
Version: 1.3.1
|
|
4
|
+
Summary: Neighbourhood Subgraph Pairwise Pathway Kernel for graph feature extraction.
|
|
5
|
+
Author: Fabrizio Costa
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/fabriziocosta/NSPPK
|
|
8
|
+
Project-URL: Documentation, https://nsppk.readthedocs.io/en/latest/
|
|
9
|
+
Project-URL: Repository, https://github.com/fabriziocosta/NSPPK
|
|
10
|
+
Project-URL: Issues, https://github.com/fabriziocosta/NSPPK/issues
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: networkx>=3.0
|
|
18
|
+
Requires-Dist: numpy>=1.24
|
|
19
|
+
Requires-Dist: scipy>=1.10
|
|
20
|
+
Requires-Dist: scikit-learn>=1.3
|
|
21
|
+
Requires-Dist: matplotlib>=3.7
|
|
22
|
+
Requires-Dist: multiprocessing-on-dill>=3.5.0a4
|
|
23
|
+
Provides-Extra: docs
|
|
24
|
+
Requires-Dist: sphinx<9,>=7.2; extra == "docs"
|
|
25
|
+
Requires-Dist: myst-parser<5,>=2.0; extra == "docs"
|
|
26
|
+
Requires-Dist: sphinx-rtd-theme<4,>=2.0; extra == "docs"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# NSPPK
|
|
30
|
+
|
|
31
|
+
[**Documentation**](https://nsppk.readthedocs.io/en/latest/)
|
|
32
|
+
|
|
33
|
+
Neighbourhood Subgraph Pairwise Pathway Kernel (NSPPK) converts labeled NetworkX graphs into fixed-width graph or node feature vectors for use with scikit-learn models.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
Python 3.10 or newer is required. Install NSPPK from PyPI with:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python -m pip install nsppk
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For local development from a checkout, use editable mode instead:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python -m pip install -e .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This installs the core dependencies. Optional source readers need extra packages:
|
|
50
|
+
|
|
51
|
+
- SMILES and SDF: `pip install rdkit`
|
|
52
|
+
- PyTorch Geometric files: install PyTorch for your platform, then `pip install torch_geometric`. See the [PyTorch installation guide](https://pytorch.org/get-started/locally/) and [PyG installation guide](https://pytorch-geometric.readthedocs.io/en/stable/install/installation.html) for compatible platform and accelerator commands.
|
|
53
|
+
|
|
54
|
+
These optional packages are not installed with NSPPK.
|
|
55
|
+
|
|
56
|
+
## Quick start
|
|
57
|
+
|
|
58
|
+
Create simple undirected NetworkX graphs. Node and edge labels are optional; missing labels are treated as `0` during encoding.
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import networkx as nx
|
|
62
|
+
from nsppk import NSPPK, NodeNSPPK
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def labeled_graph(node_labels, edges):
|
|
66
|
+
graph = nx.Graph()
|
|
67
|
+
graph.add_nodes_from(
|
|
68
|
+
(node_id, {"label": label})
|
|
69
|
+
for node_id, label in enumerate(node_labels)
|
|
70
|
+
)
|
|
71
|
+
graph.add_edges_from(
|
|
72
|
+
(u, v, {"label": "bond"})
|
|
73
|
+
for u, v in edges
|
|
74
|
+
)
|
|
75
|
+
return graph
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
graphs = [
|
|
79
|
+
labeled_graph(["C", "O", "C"], [(0, 1), (1, 2)]),
|
|
80
|
+
labeled_graph(["C", "N", "C"], [(0, 1), (1, 2)]),
|
|
81
|
+
labeled_graph(["O", "C", "O"], [(0, 1), (1, 2)]),
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
encoder = NSPPK(nbits=8, dense=False, parallel=False)
|
|
85
|
+
X = encoder.fit_transform(graphs)
|
|
86
|
+
print(X.shape) # (3, 256)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`NSPPK` returns one feature row per graph. With no continuous node attributes and the default graph-level mode, the width is `2 ** nbits`. `dense=False` returns a SciPy sparse matrix; the default `dense=True` returns a NumPy array.
|
|
90
|
+
|
|
91
|
+
For node-level vectors, use `NodeNSPPK`. Its output is a list with one node-by-feature matrix per input graph:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
node_encoder = NodeNSPPK(nbits=8, dense=False, parallel=False)
|
|
95
|
+
node_features = node_encoder.fit_transform(graphs)
|
|
96
|
+
print(node_features[0].shape) # (number of nodes in graphs[0], 256)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Rows follow each graph’s `graph.nodes()` iteration order. See the [API reference](docs/API.md) for graph requirements, parameter meanings, and output shapes.
|
|
100
|
+
|
|
101
|
+
For supervised learning directly from graph lists, use `NSPPKClassifier` or `NSPPKRegressor`. Both accept any compatible scikit-learn estimator, with `"linear"` and `"rf"` shortcuts:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from nsppk import NSPPKClassifier
|
|
105
|
+
|
|
106
|
+
classifier = NSPPKClassifier(
|
|
107
|
+
estimator="linear",
|
|
108
|
+
estimator_params={"C": 0.5},
|
|
109
|
+
nbits=14,
|
|
110
|
+
parallel=False,
|
|
111
|
+
)
|
|
112
|
+
classifier.fit(train_graphs, y_train)
|
|
113
|
+
predictions = classifier.predict(test_graphs)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The `"linear"` shortcut uses logistic regression for classification and Ridge regression for regression. The `"rf"` shortcut uses the corresponding random forest. See the [API reference](docs/API.md) for custom estimators and parameter options.
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
- [API and output reference](docs/API.md)
|
|
121
|
+
- [Graph loading and streaming](docs/IO.md)
|
|
122
|
+
- [Node attributes](docs/ATTRIBUTES_INTEGRATION.md)
|
|
123
|
+
- [Hashing procedure](docs/HASH.md)
|
|
124
|
+
- [Node and feature importance](docs/IMPORTANCE_NSPPK.md)
|
|
125
|
+
- [Development and releases](docs/DEVELOPMENT.md)
|
|
126
|
+
- [Changelog](CHANGELOG.md)
|
|
127
|
+
|
|
128
|
+
## Examples
|
|
129
|
+
|
|
130
|
+
Runnable notebooks are in `notebooks/`:
|
|
131
|
+
|
|
132
|
+
- `Demo.ipynb`: graph-level feature extraction
|
|
133
|
+
- `Importance Demo.ipynb`: node and edge importance on a synthetic dataset
|
|
134
|
+
- `Streaming Benchmark.ipynb`: loading and streaming examples
|
|
135
|
+
- `Molecular Graph Learning Curve.ipynb`, `Molecular Graph nbits Benchmark.ipynb`, and `Molecular Graph Speed Benchmark.ipynb`: molecular graph experiments
|
|
136
|
+
- `NSPPK Classifier Benchmark.ipynb`: compare the `linear` and `rf` supervised estimator shortcuts on HIV
|
|
137
|
+
|
|
138
|
+
Some notebooks require optional chemistry or machine-learning packages beyond NSPPK’s core dependencies. The graph readers and their optional requirements are documented in [IO.md](docs/IO.md).
|
|
139
|
+
|
|
140
|
+
## Citation
|
|
141
|
+
|
|
142
|
+
The repository’s Zenodo DOI is [10.5281/zenodo.14261713](https://doi.org/10.5281/zenodo.14261713).
|
nsppk-1.3.1/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# NSPPK
|
|
2
|
+
|
|
3
|
+
[**Documentation**](https://nsppk.readthedocs.io/en/latest/)
|
|
4
|
+
|
|
5
|
+
Neighbourhood Subgraph Pairwise Pathway Kernel (NSPPK) converts labeled NetworkX graphs into fixed-width graph or node feature vectors for use with scikit-learn models.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Python 3.10 or newer is required. Install NSPPK from PyPI with:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
python -m pip install nsppk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
For local development from a checkout, use editable mode instead:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
python -m pip install -e .
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This installs the core dependencies. Optional source readers need extra packages:
|
|
22
|
+
|
|
23
|
+
- SMILES and SDF: `pip install rdkit`
|
|
24
|
+
- PyTorch Geometric files: install PyTorch for your platform, then `pip install torch_geometric`. See the [PyTorch installation guide](https://pytorch.org/get-started/locally/) and [PyG installation guide](https://pytorch-geometric.readthedocs.io/en/stable/install/installation.html) for compatible platform and accelerator commands.
|
|
25
|
+
|
|
26
|
+
These optional packages are not installed with NSPPK.
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
Create simple undirected NetworkX graphs. Node and edge labels are optional; missing labels are treated as `0` during encoding.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import networkx as nx
|
|
34
|
+
from nsppk import NSPPK, NodeNSPPK
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def labeled_graph(node_labels, edges):
|
|
38
|
+
graph = nx.Graph()
|
|
39
|
+
graph.add_nodes_from(
|
|
40
|
+
(node_id, {"label": label})
|
|
41
|
+
for node_id, label in enumerate(node_labels)
|
|
42
|
+
)
|
|
43
|
+
graph.add_edges_from(
|
|
44
|
+
(u, v, {"label": "bond"})
|
|
45
|
+
for u, v in edges
|
|
46
|
+
)
|
|
47
|
+
return graph
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
graphs = [
|
|
51
|
+
labeled_graph(["C", "O", "C"], [(0, 1), (1, 2)]),
|
|
52
|
+
labeled_graph(["C", "N", "C"], [(0, 1), (1, 2)]),
|
|
53
|
+
labeled_graph(["O", "C", "O"], [(0, 1), (1, 2)]),
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
encoder = NSPPK(nbits=8, dense=False, parallel=False)
|
|
57
|
+
X = encoder.fit_transform(graphs)
|
|
58
|
+
print(X.shape) # (3, 256)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`NSPPK` returns one feature row per graph. With no continuous node attributes and the default graph-level mode, the width is `2 ** nbits`. `dense=False` returns a SciPy sparse matrix; the default `dense=True` returns a NumPy array.
|
|
62
|
+
|
|
63
|
+
For node-level vectors, use `NodeNSPPK`. Its output is a list with one node-by-feature matrix per input graph:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
node_encoder = NodeNSPPK(nbits=8, dense=False, parallel=False)
|
|
67
|
+
node_features = node_encoder.fit_transform(graphs)
|
|
68
|
+
print(node_features[0].shape) # (number of nodes in graphs[0], 256)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Rows follow each graph’s `graph.nodes()` iteration order. See the [API reference](docs/API.md) for graph requirements, parameter meanings, and output shapes.
|
|
72
|
+
|
|
73
|
+
For supervised learning directly from graph lists, use `NSPPKClassifier` or `NSPPKRegressor`. Both accept any compatible scikit-learn estimator, with `"linear"` and `"rf"` shortcuts:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from nsppk import NSPPKClassifier
|
|
77
|
+
|
|
78
|
+
classifier = NSPPKClassifier(
|
|
79
|
+
estimator="linear",
|
|
80
|
+
estimator_params={"C": 0.5},
|
|
81
|
+
nbits=14,
|
|
82
|
+
parallel=False,
|
|
83
|
+
)
|
|
84
|
+
classifier.fit(train_graphs, y_train)
|
|
85
|
+
predictions = classifier.predict(test_graphs)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The `"linear"` shortcut uses logistic regression for classification and Ridge regression for regression. The `"rf"` shortcut uses the corresponding random forest. See the [API reference](docs/API.md) for custom estimators and parameter options.
|
|
89
|
+
|
|
90
|
+
## Documentation
|
|
91
|
+
|
|
92
|
+
- [API and output reference](docs/API.md)
|
|
93
|
+
- [Graph loading and streaming](docs/IO.md)
|
|
94
|
+
- [Node attributes](docs/ATTRIBUTES_INTEGRATION.md)
|
|
95
|
+
- [Hashing procedure](docs/HASH.md)
|
|
96
|
+
- [Node and feature importance](docs/IMPORTANCE_NSPPK.md)
|
|
97
|
+
- [Development and releases](docs/DEVELOPMENT.md)
|
|
98
|
+
- [Changelog](CHANGELOG.md)
|
|
99
|
+
|
|
100
|
+
## Examples
|
|
101
|
+
|
|
102
|
+
Runnable notebooks are in `notebooks/`:
|
|
103
|
+
|
|
104
|
+
- `Demo.ipynb`: graph-level feature extraction
|
|
105
|
+
- `Importance Demo.ipynb`: node and edge importance on a synthetic dataset
|
|
106
|
+
- `Streaming Benchmark.ipynb`: loading and streaming examples
|
|
107
|
+
- `Molecular Graph Learning Curve.ipynb`, `Molecular Graph nbits Benchmark.ipynb`, and `Molecular Graph Speed Benchmark.ipynb`: molecular graph experiments
|
|
108
|
+
- `NSPPK Classifier Benchmark.ipynb`: compare the `linear` and `rf` supervised estimator shortcuts on HIV
|
|
109
|
+
|
|
110
|
+
Some notebooks require optional chemistry or machine-learning packages beyond NSPPK’s core dependencies. The graph readers and their optional requirements are documented in [IO.md](docs/IO.md).
|
|
111
|
+
|
|
112
|
+
## Citation
|
|
113
|
+
|
|
114
|
+
The repository’s Zenodo DOI is [10.5281/zenodo.14261713](https://doi.org/10.5281/zenodo.14261713).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nsppk"
|
|
7
|
+
version = "1.3.1"
|
|
8
|
+
description = "Neighbourhood Subgraph Pairwise Pathway Kernel for graph feature extraction."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Fabrizio Costa" },
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"networkx>=3.0",
|
|
23
|
+
"numpy>=1.24",
|
|
24
|
+
"scipy>=1.10",
|
|
25
|
+
"scikit-learn>=1.3",
|
|
26
|
+
"matplotlib>=3.7",
|
|
27
|
+
"multiprocessing-on-dill>=3.5.0a4",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/fabriziocosta/NSPPK"
|
|
32
|
+
Documentation = "https://nsppk.readthedocs.io/en/latest/"
|
|
33
|
+
Repository = "https://github.com/fabriziocosta/NSPPK"
|
|
34
|
+
Issues = "https://github.com/fabriziocosta/NSPPK/issues"
|
|
35
|
+
|
|
36
|
+
[project.optional-dependencies]
|
|
37
|
+
docs = [
|
|
38
|
+
"sphinx>=7.2,<9",
|
|
39
|
+
"myst-parser>=2.0,<5",
|
|
40
|
+
"sphinx-rtd-theme>=2.0,<4",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[tool.setuptools]
|
|
44
|
+
package-dir = {"" = "src"}
|
|
45
|
+
py-modules = ["nsppk", "importance_nsppk", "hash", "graph_io", "utils"]
|
nsppk-1.3.1/setup.cfg
ADDED