graphclust 1.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.
- graphclust-1.0/.gitignore +47 -0
- graphclust-1.0/CHANGELOG.md +32 -0
- graphclust-1.0/CITATION.cff +37 -0
- graphclust-1.0/LICENSE +21 -0
- graphclust-1.0/PKG-INFO +168 -0
- graphclust-1.0/README.md +106 -0
- graphclust-1.0/book/README.md +65 -0
- graphclust-1.0/examples/01_graphs/README.rst +6 -0
- graphclust-1.0/examples/01_graphs/plot_01_proximity_graphs.py +45 -0
- graphclust-1.0/examples/01_graphs/plot_02_geodesic_distances.py +57 -0
- graphclust-1.0/examples/02_topology/README.rst +5 -0
- graphclust-1.0/examples/02_topology/plot_01_neural_gas.py +37 -0
- graphclust-1.0/examples/02_topology/plot_02_trn.py +34 -0
- graphclust-1.0/examples/02_topology/plot_03_growing_networks.py +52 -0
- graphclust-1.0/examples/02_topology/plot_04_edge_lifetime.py +32 -0
- graphclust-1.0/examples/03_trees/README.rst +4 -0
- graphclust-1.0/examples/03_trees/plot_01_mst_zahn.py +39 -0
- graphclust-1.0/examples/03_trees/plot_02_hybrid_mst_gg.py +44 -0
- graphclust-1.0/examples/03_trees/plot_03_curves_initialization.py +43 -0
- graphclust-1.0/examples/03_trees/plot_04_iris.py +36 -0
- graphclust-1.0/examples/03_trees/plot_05_hdbscan.py +40 -0
- graphclust-1.0/examples/04_neighborhoods/README.rst +5 -0
- graphclust-1.0/examples/04_neighborhoods/plot_01_jarvis_patrick.py +31 -0
- graphclust-1.0/examples/04_neighborhoods/plot_02_fuzzy_similarity.py +48 -0
- graphclust-1.0/examples/04_neighborhoods/plot_03_wine.py +39 -0
- graphclust-1.0/examples/04_neighborhoods/plot_04_snn_density_peaks.py +44 -0
- graphclust-1.0/examples/04_neighborhoods/plot_05_spectral_communities.py +53 -0
- graphclust-1.0/examples/05_assessment/README.rst +4 -0
- graphclust-1.0/examples/05_assessment/plot_01_vat_ivat.py +33 -0
- graphclust-1.0/examples/05_assessment/plot_02_quality_measures.py +51 -0
- graphclust-1.0/examples/06_classical_maps/README.rst +5 -0
- graphclust-1.0/examples/06_classical_maps/plot_01_distance_maps.py +37 -0
- graphclust-1.0/examples/06_classical_maps/plot_02_neighborhood_maps.py +41 -0
- graphclust-1.0/examples/07_topology_maps/README.rst +5 -0
- graphclust-1.0/examples/07_topology_maps/plot_01_isomap_isotop_cda.py +40 -0
- graphclust-1.0/examples/07_topology_maps/plot_02_ovi_gnlp_trnmap.py +43 -0
- graphclust-1.0/examples/07_topology_maps/plot_03_component_planes.py +23 -0
- graphclust-1.0/examples/07_topology_maps/plot_04_number_of_nodes.py +38 -0
- graphclust-1.0/examples/08_neighbor_embedding/README.rst +4 -0
- graphclust-1.0/examples/08_neighbor_embedding/plot_01_spectral_embeddings.py +27 -0
- graphclust-1.0/examples/08_neighbor_embedding/plot_02_umap_tsne.py +33 -0
- graphclust-1.0/examples/09_case_studies/README.rst +5 -0
- graphclust-1.0/examples/09_case_studies/plot_01_combinations.py +59 -0
- graphclust-1.0/examples/09_case_studies/plot_02_compare_maps.py +65 -0
- graphclust-1.0/examples/09_case_studies/plot_03_real_data.py +51 -0
- graphclust-1.0/examples/README.rst +7 -0
- graphclust-1.0/pyproject.toml +79 -0
- graphclust-1.0/src/graphclust/__init__.py +102 -0
- graphclust-1.0/src/graphclust/_utils.py +86 -0
- graphclust-1.0/src/graphclust/cluster.py +971 -0
- graphclust-1.0/src/graphclust/data/__init__.py +1 -0
- graphclust-1.0/src/graphclust/data/boxlinecircle.txt +7100 -0
- graphclust-1.0/src/graphclust/datasets.py +173 -0
- graphclust-1.0/src/graphclust/fuzzy.py +152 -0
- graphclust-1.0/src/graphclust/graphs.py +311 -0
- graphclust-1.0/src/graphclust/manifold.py +1135 -0
- graphclust-1.0/src/graphclust/metrics.py +213 -0
- graphclust-1.0/src/graphclust/plotting.py +185 -0
- graphclust-1.0/src/graphclust/validity.py +184 -0
- graphclust-1.0/src/graphclust/vat.py +71 -0
- graphclust-1.0/src/graphclust/vq.py +707 -0
- graphclust-1.0/tests/test_cluster.py +132 -0
- graphclust-1.0/tests/test_graphs_vq.py +106 -0
- graphclust-1.0/tests/test_manifold_metrics.py +147 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.pyc
|
|
3
|
+
*.egg-info/
|
|
4
|
+
dist/
|
|
5
|
+
build/
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
.ruff_cache/
|
|
8
|
+
docs/_build/
|
|
9
|
+
docs/auto_examples/
|
|
10
|
+
docs/gen_modules/
|
|
11
|
+
docs/sg_execution_times.rst
|
|
12
|
+
book/figures/
|
|
13
|
+
book/*.aux
|
|
14
|
+
book/*.log
|
|
15
|
+
book/*.out
|
|
16
|
+
book/*.toc
|
|
17
|
+
book/*.bbl
|
|
18
|
+
book/*.bcf
|
|
19
|
+
book/*.blg
|
|
20
|
+
book/*.run.xml
|
|
21
|
+
book/*.idx
|
|
22
|
+
book/*.ilg
|
|
23
|
+
book/*.ind
|
|
24
|
+
book/*.fls
|
|
25
|
+
book/*.fdb_latexmk
|
|
26
|
+
book/*.synctex.gz
|
|
27
|
+
book/main.pdf
|
|
28
|
+
*.ipynb_checkpoints
|
|
29
|
+
book/_check_tmp/
|
|
30
|
+
book/_check.tex
|
|
31
|
+
docs/_build/
|
|
32
|
+
docs/api/generated/
|
|
33
|
+
docs/_build_log.txt
|
|
34
|
+
book/_build/
|
|
35
|
+
.coverage
|
|
36
|
+
book/_build_new/
|
|
37
|
+
book/_check_*.tex
|
|
38
|
+
book/cover/*.aux
|
|
39
|
+
book/cover/*.log
|
|
40
|
+
book/cover/*.fls
|
|
41
|
+
book/cover/*.fdb_latexmk
|
|
42
|
+
book/cover/*.pdf
|
|
43
|
+
book/cover/*.png
|
|
44
|
+
book/cover/logo.svg
|
|
45
|
+
*.blg
|
|
46
|
+
book/_build_epub/
|
|
47
|
+
book/_build_web/
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0 (2026-11-28)
|
|
4
|
+
|
|
5
|
+
First public release: the Python successor of the MATLAB Graph-Based Clustering
|
|
6
|
+
and Data Visualization Toolbox, with a companion open book.
|
|
7
|
+
|
|
8
|
+
* `graphclust.graphs`: kNN, mutual kNN, ε, nearest neighbor, MST, relative
|
|
9
|
+
neighborhood, Gabriel and Delaunay graphs; competitive Hebbian graph;
|
|
10
|
+
shared-neighbor counts; component joining and geodesic distances.
|
|
11
|
+
* `graphclust.vq`: LBG, neural gas, topology representing network (with
|
|
12
|
+
pruning), growing neural gas, grow when required, dynamic TRN, weighted
|
|
13
|
+
incremental network.
|
|
14
|
+
* `graphclust.cluster`: Zahn's MST clustering, hybrid MST–Gath–Geva,
|
|
15
|
+
HDBSCAN*, Jarvis–Patrick, transitive fuzzy neighborhood similarity and
|
|
16
|
+
hierarchical clustering on it, SNN density clustering, density peaks,
|
|
17
|
+
self-tuning spectral clustering, Louvain/Leiden/label-propagation
|
|
18
|
+
communities on Jaccard-weighted kNN graphs.
|
|
19
|
+
* `graphclust.fuzzy`: Gath–Geva clustering, fuzzy covariances, fuzzy hypervolume.
|
|
20
|
+
* `graphclust.validity`: Dunn index with MST diameters, Fukuyama–Sugeno,
|
|
21
|
+
fuzzy hypervolume, DBCV, eigengap, clustering rate.
|
|
22
|
+
* `graphclust.vat`: VAT and iVAT.
|
|
23
|
+
* `graphclust.manifold`: classical, metric (SMACOF) and non-metric MDS,
|
|
24
|
+
Sammon mapping, LPP, batch SOM, incremental grid growing, Isomap, Isotop,
|
|
25
|
+
CCA/CDA, OVI-NG, GNLP-NG, TRNMap (metric, non-metric, classical, fine
|
|
26
|
+
tuning), Laplacian eigenmaps, diffusion maps, UMAP (NumPy), t-SNE wrapper.
|
|
27
|
+
* `graphclust.metrics`: Sammon and MDS stress, residual variance,
|
|
28
|
+
trustworthiness and continuity, co-ranking matrix, Q_NX, R_NX, LCMC, AUC,
|
|
29
|
+
topographic error and product.
|
|
30
|
+
* `graphclust.datasets`: Variety, ChainLink, Curves, Boxlinecircle (original
|
|
31
|
+
data shipped), S curve, swiss roll and scikit-learn real data loaders.
|
|
32
|
+
* 29 gallery examples; book (PDF, EPUB, web edition) generated from LaTeX.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use graphclust, please cite it as below, together with the original publications of the methods you use."
|
|
3
|
+
title: "graphclust: graph-based clustering and data visualization in Python"
|
|
4
|
+
version: "1.0"
|
|
5
|
+
date-released: 2026-11-28
|
|
6
|
+
license: MIT
|
|
7
|
+
repository-code: "https://github.com/ComplexSystemsIntelligence/graphclust"
|
|
8
|
+
url: "https://complexsystemsintelligence.github.io/graphclust"
|
|
9
|
+
authors:
|
|
10
|
+
- family-names: Vathy-Fogarassy
|
|
11
|
+
given-names: Ágnes
|
|
12
|
+
affiliation: University of Pannonia
|
|
13
|
+
- family-names: Abonyi
|
|
14
|
+
given-names: János
|
|
15
|
+
affiliation: University of Pannonia
|
|
16
|
+
orcid: "https://orcid.org/0000-0001-8593-1493"
|
|
17
|
+
keywords:
|
|
18
|
+
- graph-based clustering
|
|
19
|
+
- minimal spanning tree
|
|
20
|
+
- topology representing network
|
|
21
|
+
- TRNMap
|
|
22
|
+
- HDBSCAN
|
|
23
|
+
- dimensionality reduction
|
|
24
|
+
- Python
|
|
25
|
+
references:
|
|
26
|
+
- type: book
|
|
27
|
+
title: "Graph-Based Clustering and Data Visualization Algorithms"
|
|
28
|
+
authors:
|
|
29
|
+
- family-names: Vathy-Fogarassy
|
|
30
|
+
given-names: Ágnes
|
|
31
|
+
- family-names: Abonyi
|
|
32
|
+
given-names: János
|
|
33
|
+
publisher:
|
|
34
|
+
name: Springer
|
|
35
|
+
collection-title: "SpringerBriefs in Computer Science"
|
|
36
|
+
year: 2013
|
|
37
|
+
doi: "10.1007/978-1-4471-5158-6"
|
graphclust-1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ágnes Vathy-Fogarassy, János Abonyi
|
|
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.
|
graphclust-1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: graphclust
|
|
3
|
+
Version: 1.0
|
|
4
|
+
Summary: Graph-based clustering and data visualization: topology representing networks, MST and hybrid MST-Gath-Geva clustering, fuzzy neighborhood similarity, HDBSCAN*, TRNMap, Isotop, CDA, UMAP and mapping quality measures, scikit-learn compatible.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ComplexSystemsIntelligence/graphclust
|
|
6
|
+
Project-URL: Documentation, https://complexsystemsintelligence.github.io/graphclust
|
|
7
|
+
Project-URL: Repository, https://github.com/ComplexSystemsIntelligence/graphclust
|
|
8
|
+
Project-URL: Issues, https://github.com/ComplexSystemsIntelligence/graphclust/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/ComplexSystemsIntelligence/graphclust/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Book (PDF), https://complexsystemsintelligence.github.io/graphclust/graphclust-book.pdf
|
|
11
|
+
Author: Ágnes Vathy-Fogarassy
|
|
12
|
+
Author-email: János Abonyi <janos@abonyilab.com>
|
|
13
|
+
License-Expression: MIT
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Keywords: HDBSCAN,Isomap,Jarvis-Patrick,TRNMap,UMAP,dimensionality reduction,graph-based clustering,minimal spanning tree,neural gas,topology representing network,trustworthiness
|
|
16
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Requires-Dist: matplotlib>=3.7
|
|
30
|
+
Requires-Dist: networkx>=3.0
|
|
31
|
+
Requires-Dist: numpy>=1.24
|
|
32
|
+
Requires-Dist: scikit-learn>=1.3
|
|
33
|
+
Requires-Dist: scipy>=1.10
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: build; extra == 'dev'
|
|
36
|
+
Requires-Dist: myst-parser; extra == 'dev'
|
|
37
|
+
Requires-Dist: numpydoc; extra == 'dev'
|
|
38
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
40
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
41
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
42
|
+
Requires-Dist: sphinx-copybutton; extra == 'dev'
|
|
43
|
+
Requires-Dist: sphinx-design; extra == 'dev'
|
|
44
|
+
Requires-Dist: sphinx-gallery>=0.15; extra == 'dev'
|
|
45
|
+
Requires-Dist: sphinx>=7; extra == 'dev'
|
|
46
|
+
Requires-Dist: twine; extra == 'dev'
|
|
47
|
+
Provides-Extra: docs
|
|
48
|
+
Requires-Dist: myst-parser; extra == 'docs'
|
|
49
|
+
Requires-Dist: numpydoc; extra == 'docs'
|
|
50
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'docs'
|
|
51
|
+
Requires-Dist: sphinx-copybutton; extra == 'docs'
|
|
52
|
+
Requires-Dist: sphinx-design; extra == 'docs'
|
|
53
|
+
Requires-Dist: sphinx-gallery>=0.15; extra == 'docs'
|
|
54
|
+
Requires-Dist: sphinx>=7; extra == 'docs'
|
|
55
|
+
Provides-Extra: leiden
|
|
56
|
+
Requires-Dist: igraph>=0.11; extra == 'leiden'
|
|
57
|
+
Requires-Dist: leidenalg>=0.10; extra == 'leiden'
|
|
58
|
+
Provides-Extra: test
|
|
59
|
+
Requires-Dist: pytest-cov; extra == 'test'
|
|
60
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
61
|
+
Description-Content-Type: text/markdown
|
|
62
|
+
|
|
63
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/graphclust/main/docs/_static/banner.png" alt="graphclust: graph-based clustering and data visualization in Python"></p>
|
|
64
|
+
|
|
65
|
+
# graphclust: graph-based clustering and data visualization in Python
|
|
66
|
+
|
|
67
|
+
[](https://github.com/ComplexSystemsIntelligence/graphclust/actions/workflows/ci.yml)
|
|
68
|
+
[](https://complexsystemsintelligence.github.io/graphclust)
|
|
69
|
+
[](https://pypi.org/project/graphclust/)
|
|
70
|
+
[](https://github.com/ComplexSystemsIntelligence/graphclust/blob/main/LICENSE)
|
|
71
|
+
|
|
72
|
+
**graphclust** is a scikit-learn compatible toolbox for clustering and
|
|
73
|
+
visualizing data through graphs: neighborhood graphs and geodesic distances,
|
|
74
|
+
topology learning with neural gas and topology representing networks,
|
|
75
|
+
clustering with spanning trees, shared neighbors and communities, and maps of
|
|
76
|
+
high-dimensional data from Sammon's mapping to TRNMap and UMAP. It is the
|
|
77
|
+
Python successor of the MATLAB toolbox that accompanied the monograph
|
|
78
|
+
*Graph-Based Clustering and Data Visualization Algorithms* (Á. Vathy-Fogarassy,
|
|
79
|
+
J. Abonyi, SpringerBriefs in Computer Science, 2013), extended with the main
|
|
80
|
+
graph-based methods published since then.
|
|
81
|
+
|
|
82
|
+
| Module | Contents |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `graphclust.graphs` | kNN, mutual kNN, ε, nearest neighbor, MST, relative neighborhood, Gabriel and Delaunay graphs; competitive Hebbian (induced Delaunay) graph; shared-neighbor counts; geodesic distances |
|
|
85
|
+
| `graphclust.vq` | LBG, neural gas, topology representing network, growing neural gas, grow when required, dynamic TRN, weighted incremental network |
|
|
86
|
+
| `graphclust.cluster` | Zahn's MST clustering, hybrid MST–Gath–Geva, HDBSCAN\*, Jarvis–Patrick, fuzzy neighborhood similarity, SNN density clustering, density peaks, self-tuning spectral clustering, Louvain/Leiden communities |
|
|
87
|
+
| `graphclust.validity` | Dunn index with MST diameters, Fukuyama–Sugeno, fuzzy hypervolume, DBCV, eigengap, clustering rate |
|
|
88
|
+
| `graphclust.vat` | VAT and iVAT images |
|
|
89
|
+
| `graphclust.manifold` | classical/metric/non-metric MDS, Sammon, LPP, SOM, incremental grid growing, Isomap, Isotop, CCA/CDA, OVI-NG, GNLP-NG, TRNMap, Laplacian eigenmaps, diffusion maps, UMAP, t-SNE |
|
|
90
|
+
| `graphclust.metrics` | Sammon and MDS stress, residual variance, trustworthiness, continuity, co-ranking matrix, Q_NX, R_NX, LCMC, AUC, topographic error and product |
|
|
91
|
+
| `graphclust.datasets`, `plotting` | Variety, ChainLink, Curves, Boxlinecircle and manifold generators; plotting helpers |
|
|
92
|
+
|
|
93
|
+
## Installation
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install graphclust # numpy, scipy, scikit-learn, networkx, matplotlib
|
|
97
|
+
pip install "graphclust[leiden]" # optional Leiden community detection
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Quick start
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from graphclust import TRNMap, HybridMSTGG, HDBSCANStar, fuzzy_neighborhood_similarity
|
|
104
|
+
from graphclust.datasets import make_s_curve, make_chainlink
|
|
105
|
+
from graphclust.metrics import trustworthiness_continuity
|
|
106
|
+
|
|
107
|
+
# map a curved manifold with the topology representing network map
|
|
108
|
+
X, t = make_s_curve(2000, random_state=0)
|
|
109
|
+
tm = TRNMap(n_nodes=150, random_state=0).fit(X)
|
|
110
|
+
tm.nodes_, tm.adjacency_, tm.embedding_
|
|
111
|
+
print(trustworthiness_continuity(tm.dist_matrix_, tm.embedding_, 5, precomputed=True))
|
|
112
|
+
|
|
113
|
+
# cluster groups joined by a chain
|
|
114
|
+
Xc, yc = make_chainlink()
|
|
115
|
+
hyb = HybridMSTGG(max_clusters=4, lambda_=2.5).fit(Xc)
|
|
116
|
+
hyb.labels_, hyb.membership_, hyb.covariances_
|
|
117
|
+
HDBSCANStar(min_cluster_size=8).fit(Xc).labels_
|
|
118
|
+
|
|
119
|
+
# shared-neighbor similarity for hierarchical clustering, MDS or VAT
|
|
120
|
+
S = fuzzy_neighborhood_similarity(Xc, k=6, r_max=3, alpha=0.2)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## The book
|
|
124
|
+
|
|
125
|
+
*Graph-Based Clustering and Data Visualization in Python: The graphclust
|
|
126
|
+
toolbox* (Á. Vathy-Fogarassy, J. Abonyi) develops every method in one notation
|
|
127
|
+
and illustrates it with the scripts of the example gallery. It is available as
|
|
128
|
+
a [web edition](https://complexsystemsintelligence.github.io/graphclust/book/),
|
|
129
|
+
[PDF](https://complexsystemsintelligence.github.io/graphclust/graphclust-book.pdf)
|
|
130
|
+
and [EPUB](https://complexsystemsintelligence.github.io/graphclust/graphclust-book.epub)
|
|
131
|
+
under CC BY 4.0. The book is a new text: it re-derives and re-implements the
|
|
132
|
+
methods of the 2013 monograph and adds HDBSCAN\*, DBCV, density peaks,
|
|
133
|
+
Louvain/Leiden communities, iVAT, the co-ranking framework, diffusion maps,
|
|
134
|
+
t-SNE and UMAP.
|
|
135
|
+
|
|
136
|
+
## Documentation
|
|
137
|
+
|
|
138
|
+
* [Example gallery](https://complexsystemsintelligence.github.io/graphclust/auto_examples/index.html):
|
|
139
|
+
29 scripts, each runnable as a Jupyter notebook (Binder, Colab).
|
|
140
|
+
* [API reference](https://complexsystemsintelligence.github.io/graphclust/api/index.html).
|
|
141
|
+
* [Migration from the MATLAB toolbox](https://complexsystemsintelligence.github.io/graphclust/migration.html).
|
|
142
|
+
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
git clone https://github.com/ComplexSystemsIntelligence/graphclust.git
|
|
147
|
+
cd graphclust
|
|
148
|
+
pip install -e ".[dev]"
|
|
149
|
+
pytest # unit tests and doctests
|
|
150
|
+
book/build.sh # the book (TeX Live with raleway, plex, libertinus, biber)
|
|
151
|
+
sphinx-build -b html docs docs/_build/html
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Citing
|
|
155
|
+
|
|
156
|
+
Please cite the package (see `CITATION.cff`) together with the original
|
|
157
|
+
publications of the methods you use; every docstring and every chapter of the
|
|
158
|
+
book lists them.
|
|
159
|
+
|
|
160
|
+
## Acknowledgments
|
|
161
|
+
|
|
162
|
+
The research summarized in the package and the book was supported by the
|
|
163
|
+
National Research, Development and Innovation Office of Hungary (NKFIH)
|
|
164
|
+
through the OTKA 143482 project.
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
Software: MIT. Book: CC BY 4.0.
|
graphclust-1.0/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/graphclust/main/docs/_static/banner.png" alt="graphclust: graph-based clustering and data visualization in Python"></p>
|
|
2
|
+
|
|
3
|
+
# graphclust: graph-based clustering and data visualization in Python
|
|
4
|
+
|
|
5
|
+
[](https://github.com/ComplexSystemsIntelligence/graphclust/actions/workflows/ci.yml)
|
|
6
|
+
[](https://complexsystemsintelligence.github.io/graphclust)
|
|
7
|
+
[](https://pypi.org/project/graphclust/)
|
|
8
|
+
[](https://github.com/ComplexSystemsIntelligence/graphclust/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
**graphclust** is a scikit-learn compatible toolbox for clustering and
|
|
11
|
+
visualizing data through graphs: neighborhood graphs and geodesic distances,
|
|
12
|
+
topology learning with neural gas and topology representing networks,
|
|
13
|
+
clustering with spanning trees, shared neighbors and communities, and maps of
|
|
14
|
+
high-dimensional data from Sammon's mapping to TRNMap and UMAP. It is the
|
|
15
|
+
Python successor of the MATLAB toolbox that accompanied the monograph
|
|
16
|
+
*Graph-Based Clustering and Data Visualization Algorithms* (Á. Vathy-Fogarassy,
|
|
17
|
+
J. Abonyi, SpringerBriefs in Computer Science, 2013), extended with the main
|
|
18
|
+
graph-based methods published since then.
|
|
19
|
+
|
|
20
|
+
| Module | Contents |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `graphclust.graphs` | kNN, mutual kNN, ε, nearest neighbor, MST, relative neighborhood, Gabriel and Delaunay graphs; competitive Hebbian (induced Delaunay) graph; shared-neighbor counts; geodesic distances |
|
|
23
|
+
| `graphclust.vq` | LBG, neural gas, topology representing network, growing neural gas, grow when required, dynamic TRN, weighted incremental network |
|
|
24
|
+
| `graphclust.cluster` | Zahn's MST clustering, hybrid MST–Gath–Geva, HDBSCAN\*, Jarvis–Patrick, fuzzy neighborhood similarity, SNN density clustering, density peaks, self-tuning spectral clustering, Louvain/Leiden communities |
|
|
25
|
+
| `graphclust.validity` | Dunn index with MST diameters, Fukuyama–Sugeno, fuzzy hypervolume, DBCV, eigengap, clustering rate |
|
|
26
|
+
| `graphclust.vat` | VAT and iVAT images |
|
|
27
|
+
| `graphclust.manifold` | classical/metric/non-metric MDS, Sammon, LPP, SOM, incremental grid growing, Isomap, Isotop, CCA/CDA, OVI-NG, GNLP-NG, TRNMap, Laplacian eigenmaps, diffusion maps, UMAP, t-SNE |
|
|
28
|
+
| `graphclust.metrics` | Sammon and MDS stress, residual variance, trustworthiness, continuity, co-ranking matrix, Q_NX, R_NX, LCMC, AUC, topographic error and product |
|
|
29
|
+
| `graphclust.datasets`, `plotting` | Variety, ChainLink, Curves, Boxlinecircle and manifold generators; plotting helpers |
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install graphclust # numpy, scipy, scikit-learn, networkx, matplotlib
|
|
35
|
+
pip install "graphclust[leiden]" # optional Leiden community detection
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick start
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from graphclust import TRNMap, HybridMSTGG, HDBSCANStar, fuzzy_neighborhood_similarity
|
|
42
|
+
from graphclust.datasets import make_s_curve, make_chainlink
|
|
43
|
+
from graphclust.metrics import trustworthiness_continuity
|
|
44
|
+
|
|
45
|
+
# map a curved manifold with the topology representing network map
|
|
46
|
+
X, t = make_s_curve(2000, random_state=0)
|
|
47
|
+
tm = TRNMap(n_nodes=150, random_state=0).fit(X)
|
|
48
|
+
tm.nodes_, tm.adjacency_, tm.embedding_
|
|
49
|
+
print(trustworthiness_continuity(tm.dist_matrix_, tm.embedding_, 5, precomputed=True))
|
|
50
|
+
|
|
51
|
+
# cluster groups joined by a chain
|
|
52
|
+
Xc, yc = make_chainlink()
|
|
53
|
+
hyb = HybridMSTGG(max_clusters=4, lambda_=2.5).fit(Xc)
|
|
54
|
+
hyb.labels_, hyb.membership_, hyb.covariances_
|
|
55
|
+
HDBSCANStar(min_cluster_size=8).fit(Xc).labels_
|
|
56
|
+
|
|
57
|
+
# shared-neighbor similarity for hierarchical clustering, MDS or VAT
|
|
58
|
+
S = fuzzy_neighborhood_similarity(Xc, k=6, r_max=3, alpha=0.2)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## The book
|
|
62
|
+
|
|
63
|
+
*Graph-Based Clustering and Data Visualization in Python: The graphclust
|
|
64
|
+
toolbox* (Á. Vathy-Fogarassy, J. Abonyi) develops every method in one notation
|
|
65
|
+
and illustrates it with the scripts of the example gallery. It is available as
|
|
66
|
+
a [web edition](https://complexsystemsintelligence.github.io/graphclust/book/),
|
|
67
|
+
[PDF](https://complexsystemsintelligence.github.io/graphclust/graphclust-book.pdf)
|
|
68
|
+
and [EPUB](https://complexsystemsintelligence.github.io/graphclust/graphclust-book.epub)
|
|
69
|
+
under CC BY 4.0. The book is a new text: it re-derives and re-implements the
|
|
70
|
+
methods of the 2013 monograph and adds HDBSCAN\*, DBCV, density peaks,
|
|
71
|
+
Louvain/Leiden communities, iVAT, the co-ranking framework, diffusion maps,
|
|
72
|
+
t-SNE and UMAP.
|
|
73
|
+
|
|
74
|
+
## Documentation
|
|
75
|
+
|
|
76
|
+
* [Example gallery](https://complexsystemsintelligence.github.io/graphclust/auto_examples/index.html):
|
|
77
|
+
29 scripts, each runnable as a Jupyter notebook (Binder, Colab).
|
|
78
|
+
* [API reference](https://complexsystemsintelligence.github.io/graphclust/api/index.html).
|
|
79
|
+
* [Migration from the MATLAB toolbox](https://complexsystemsintelligence.github.io/graphclust/migration.html).
|
|
80
|
+
|
|
81
|
+
## Development
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git clone https://github.com/ComplexSystemsIntelligence/graphclust.git
|
|
85
|
+
cd graphclust
|
|
86
|
+
pip install -e ".[dev]"
|
|
87
|
+
pytest # unit tests and doctests
|
|
88
|
+
book/build.sh # the book (TeX Live with raleway, plex, libertinus, biber)
|
|
89
|
+
sphinx-build -b html docs docs/_build/html
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Citing
|
|
93
|
+
|
|
94
|
+
Please cite the package (see `CITATION.cff`) together with the original
|
|
95
|
+
publications of the methods you use; every docstring and every chapter of the
|
|
96
|
+
book lists them.
|
|
97
|
+
|
|
98
|
+
## Acknowledgments
|
|
99
|
+
|
|
100
|
+
The research summarized in the package and the book was supported by the
|
|
101
|
+
National Research, Development and Innovation Office of Hungary (NKFIH)
|
|
102
|
+
through the OTKA 143482 project.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
Software: MIT. Book: CC BY 4.0.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# The graphclust book — authoring conventions
|
|
2
|
+
|
|
3
|
+
`main.tex` includes `preamble.tex` and one file per chapter from `chapters/`.
|
|
4
|
+
Build: `book/build.sh` (cover artwork, figures, generated appendices, PDF in `book/_build/`).
|
|
5
|
+
EPUB edition: `python book/epub/make_epub.py` after `book/build.sh` (needs tex4ebook, biber and dvisvgm;
|
|
6
|
+
output in `book/_build_epub/`). It is generated from the same chapters with an e-book preamble.
|
|
7
|
+
Web edition: `python book/web/make_web.py` (same requirements plus beautifulsoup4; output in
|
|
8
|
+
`book/_build_web/site/`, published as `book/` on the documentation site).
|
|
9
|
+
|
|
10
|
+
## Chapter template (follow exactly)
|
|
11
|
+
|
|
12
|
+
```latex
|
|
13
|
+
\chapter{Title}\label{ch:slug}
|
|
14
|
+
\begin{roadmap}
|
|
15
|
+
What this chapter covers, why it matters, how it connects to the previous one (3–5 sentences).
|
|
16
|
+
\end{roadmap}
|
|
17
|
+
|
|
18
|
+
\section{Problem and idea} % motivation in plain words, one TikZ concept figure
|
|
19
|
+
\section{Theory} % unified notation (preamble macros: \X \xk \W \wi \y \yi \Nk \G \Fi ...)
|
|
20
|
+
...
|
|
21
|
+
\begin{algobox}{Name of the algorithm}{slug}
|
|
22
|
+
\begin{algorithm}[H] ... \end{algorithm} % or an enumerated list for short procedures
|
|
23
|
+
\end{algobox}
|
|
24
|
+
\begin{summarybox}{Name}
|
|
25
|
+
3–6 bullets: what it does, what it assumes, when to use it, main parameters.
|
|
26
|
+
\end{summarybox}
|
|
27
|
+
\section{Using it in graphclust} % \begin{apibox}{graphclust.module.Class} parameters \end{apibox}
|
|
28
|
+
% + code snippets via \pysnippet{examples/<sec>/plot_xx.py}{tag}
|
|
29
|
+
\section{Examples} % one subsection per example script; figures via \exfig; discuss parameter effects
|
|
30
|
+
\section{Further reading} % 3–8 references with \cite{} (BibTeX keys in references.bib)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Rules
|
|
34
|
+
* Theory and experiments are kept apart (Theory vs. Examples sections).
|
|
35
|
+
* Every algorithm gets exactly one `algobox` and one `summarybox`.
|
|
36
|
+
* Every example script of the chapter is referenced at least once with `\exfig`; captions are descriptive sentences ("GK adapts the shape of the clusters, FCM cuts across them"), not labels. A caption of several sentences gets a short form for the list of figures: `\exfig[width]{section/script_n}[First sentence.]{Full caption.}{label}` (manual figures and tables: `\caption[short]{long}`).
|
|
37
|
+
* Every `algobox` is followed by `\index{}` entries for the algorithm name, its abbreviation and its class (`FCM@\code{FCM}`); add them when a new algorithm box is written.
|
|
38
|
+
* Spelling is American (-ize, color, center, neighbor, modeling); code identifiers, file names, labels and BibTeX keys are never changed (`plot_10_initialisation_restarts.py` keeps its name).
|
|
39
|
+
* Concept figures (TikZ) are drawn at natural font size inside the 360 pt text width: no `\resizebox`; stack panels vertically or use `scale=` on the coordinates instead; `\code{}` breaks lines after underscores, so long identifiers may be used in running text.
|
|
40
|
+
* Snippet tags: in the example scripts wrap the lines to quote between `# [snippet:tag]` and `# [/snippet:tag]`.
|
|
41
|
+
* Figures: `book/build_figures.py` writes `figures/<section>/<script>_<n>.pdf`; `n` is the 1-based figure number inside the script.
|
|
42
|
+
* Citations: add BibTeX entries to `references.bib` (key style `author:year` or `author:year:topic`); only cite works you have actually seen (the uploaded papers, standard textbooks, the original method papers).
|
|
43
|
+
* No MATLAB code; mention the MATLAB toolbox only in the migration appendix.
|
|
44
|
+
* The book is a new text: no sentence, figure or table of the 2013 Springer monograph may be copied; methods are re-derived in our own words and all figures are computed by the example scripts.
|
|
45
|
+
|
|
46
|
+
## Design
|
|
47
|
+
|
|
48
|
+
The visual identity is defined once, in `cover/brand.tex`, and shared by the
|
|
49
|
+
book, the cover, the documentation (`docs/_static/custom.css`, logo, banner)
|
|
50
|
+
and the README:
|
|
51
|
+
|
|
52
|
+
* colors: Pannon blue `#285780` for headings, rules and links; navy `#14304A`
|
|
53
|
+
for dark backgrounds; the Okabe–Ito triple blue/vermilion/green of the logo,
|
|
54
|
+
which is also the palette of every data figure (`graphclust.plotting.PALETTE`);
|
|
55
|
+
* type: Libertinus Serif and Libertinus Math for text and formulas, Raleway for
|
|
56
|
+
headings and display, IBM Plex Mono for code;
|
|
57
|
+
* boxes: one geometry (colored rule on the left, light tint, title in Raleway);
|
|
58
|
+
only the color tells the kind (algorithm, summary, hint, API, roadmap);
|
|
59
|
+
* the cover artwork (`cover/make_cover_art.py`) is a Gustafson–Kessel run of the
|
|
60
|
+
package: samples in the blend of their membership colors, membership contours
|
|
61
|
+
as lines. The same script draws the banner of the README and the docs.
|
|
62
|
+
|
|
63
|
+
Page layout rules: algorithm boxes are floats; headings and listings carry a
|
|
64
|
+
`\needspace`, so they never end a page; widows and orphans are forbidden. Do
|
|
65
|
+
not add `\clearpage` or `\vspace` in the chapters.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
r"""
|
|
2
|
+
Proximity graphs and their nesting
|
|
3
|
+
==================================
|
|
4
|
+
|
|
5
|
+
A graph turns a cloud of samples into a structure: who is whose neighbor.
|
|
6
|
+
The classical proximity graphs differ in how strict "neighbor" is:
|
|
7
|
+
|
|
8
|
+
* the nearest neighbor graph (NNG) links each sample to its nearest neighbor;
|
|
9
|
+
* the minimal spanning tree (MST) connects all samples with minimal total length;
|
|
10
|
+
* the relative neighborhood graph (RNG) links two samples when no third
|
|
11
|
+
sample is closer to both of them;
|
|
12
|
+
* the Gabriel graph (GG) links two samples when the ball spanned by them as a
|
|
13
|
+
diameter is empty;
|
|
14
|
+
* the Delaunay triangulation (DT) is the dual of the Voronoi diagram.
|
|
15
|
+
|
|
16
|
+
Each graph contains the previous one, NNG ⊆ MST ⊆ RNG ⊆ GG ⊆ DT, so the
|
|
17
|
+
chain moves from "only the most obvious relations" to "every geometrically
|
|
18
|
+
possible relation".
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import matplotlib.pyplot as plt
|
|
22
|
+
|
|
23
|
+
from graphclust import graphs
|
|
24
|
+
from graphclust.datasets import make_variety
|
|
25
|
+
from graphclust.plotting import plot_graph
|
|
26
|
+
|
|
27
|
+
# [snippet:graphs]
|
|
28
|
+
X, y = make_variety()
|
|
29
|
+
G = {
|
|
30
|
+
"nearest neighbor graph": graphs.nearest_neighbor_graph(X),
|
|
31
|
+
"minimal spanning tree": graphs.minimum_spanning_tree(X),
|
|
32
|
+
"relative neighborhood graph": graphs.relative_neighborhood_graph(X),
|
|
33
|
+
"Gabriel graph": graphs.gabriel_graph(X),
|
|
34
|
+
"Delaunay triangulation": graphs.delaunay_graph(X),
|
|
35
|
+
"symmetric 5-NN graph": graphs.knn_graph(X, k=5),
|
|
36
|
+
}
|
|
37
|
+
print(graphs.neighborhood_chain(X))
|
|
38
|
+
# [/snippet:graphs]
|
|
39
|
+
|
|
40
|
+
fig, axes = plt.subplots(2, 3, figsize=(12, 7.6))
|
|
41
|
+
for ax, (name, A) in zip(axes.flat, G.items()):
|
|
42
|
+
plot_graph(X, A, ax=ax, node_size=10, title=f"{name} ({A.nnz // 2} edges)")
|
|
43
|
+
ax.set_xticks([])
|
|
44
|
+
ax.set_yticks([])
|
|
45
|
+
plt.tight_layout()
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
r"""
|
|
2
|
+
Geodesic distances on a neighborhood graph
|
|
3
|
+
==========================================
|
|
4
|
+
|
|
5
|
+
On a curved manifold the Euclidean distance cuts through empty space. The
|
|
6
|
+
length of the shortest path in a neighborhood graph, with edges weighted by
|
|
7
|
+
their Euclidean length, follows the data instead: it approximates the
|
|
8
|
+
*geodesic* distance along the manifold. Too few neighbors split the graph,
|
|
9
|
+
too many create short-circuit edges between the windings of the swiss roll.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
import numpy as np
|
|
14
|
+
from scipy.sparse.csgraph import connected_components
|
|
15
|
+
|
|
16
|
+
from graphclust import graphs
|
|
17
|
+
from graphclust.datasets import make_swiss_roll
|
|
18
|
+
|
|
19
|
+
X, t = make_swiss_roll(1000, random_state=0)
|
|
20
|
+
|
|
21
|
+
# [snippet:geodesic]
|
|
22
|
+
A = graphs.knn_graph(X, k=8)
|
|
23
|
+
D_geo = graphs.geodesic_distances(A, points=X, connect=True)
|
|
24
|
+
D_eu = np.linalg.norm(X[:, None] - X[None], axis=-1)
|
|
25
|
+
# [/snippet:geodesic]
|
|
26
|
+
|
|
27
|
+
src = int(np.argmin(t))
|
|
28
|
+
fig = plt.figure(figsize=(12, 4))
|
|
29
|
+
for i, (D, name) in enumerate([(D_eu, "Euclidean distance"), (D_geo, "geodesic distance (8-NN graph)")]):
|
|
30
|
+
ax = fig.add_subplot(1, 3, i + 1, projection="3d")
|
|
31
|
+
ax.scatter(*X.T, c=D[src], cmap="viridis", s=6)
|
|
32
|
+
ax.scatter(*X[src], c="#D55E00", s=60, marker="*")
|
|
33
|
+
ax.set_title(f"{name} from the marked sample", fontsize=10)
|
|
34
|
+
ax.view_init(8, -70)
|
|
35
|
+
ax.set_xticks([])
|
|
36
|
+
ax.set_yticks([])
|
|
37
|
+
ax.set_zticks([])
|
|
38
|
+
ax = fig.add_subplot(1, 3, 3)
|
|
39
|
+
ks = [2, 3, 4, 6, 8, 12, 16, 24, 32]
|
|
40
|
+
comps, corr = [], []
|
|
41
|
+
for k in ks:
|
|
42
|
+
Ak = graphs.knn_graph(X, k)
|
|
43
|
+
comps.append(connected_components(Ak)[0])
|
|
44
|
+
Dk = graphs.geodesic_distances(Ak, points=X, connect=True)
|
|
45
|
+
corr.append(np.corrcoef(Dk[src], t)[0, 1])
|
|
46
|
+
ax.plot(ks, corr, "o-", color="#0072B2", label="corr(geodesic, position on curve)")
|
|
47
|
+
ax2 = ax.twinx()
|
|
48
|
+
ax2.plot(ks, comps, "s--", color="#D55E00", label="graph components")
|
|
49
|
+
ax.set_xscale("log")
|
|
50
|
+
ax.set_xlabel("k")
|
|
51
|
+
ax.set_ylabel("correlation")
|
|
52
|
+
ax2.set_ylabel("components")
|
|
53
|
+
ax.set_title("choice of k", fontsize=10)
|
|
54
|
+
fig.legend(loc="lower right", fontsize=8, frameon=False)
|
|
55
|
+
plt.tight_layout()
|
|
56
|
+
for k, c, r in zip(ks, comps, corr):
|
|
57
|
+
print(f"k={k:2d}: {c} component(s), correlation {r:.3f}")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
r"""
|
|
2
|
+
Neural gas learns the shape of the data
|
|
3
|
+
=======================================
|
|
4
|
+
|
|
5
|
+
Neural gas moves *all* representatives towards every drawn sample, with steps
|
|
6
|
+
that decay exponentially with their distance rank. Early on, when the
|
|
7
|
+
neighborhood range is large, the codebook contracts towards the data mean;
|
|
8
|
+
as the range shrinks the representatives spread out and finally cover the
|
|
9
|
+
data with roughly equal probability mass. The data set combines a noisy cube,
|
|
10
|
+
a bent line and a circle: shapes of three different intrinsic dimensions.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import matplotlib.pyplot as plt
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
from graphclust import NeuralGas
|
|
17
|
+
from graphclust.datasets import load_boxlinecircle
|
|
18
|
+
|
|
19
|
+
X = load_boxlinecircle()
|
|
20
|
+
rng = np.random.default_rng(0)
|
|
21
|
+
sub = X[rng.choice(len(X), 2000, replace=False)]
|
|
22
|
+
|
|
23
|
+
fig = plt.figure(figsize=(12, 7.5))
|
|
24
|
+
for i, t_max in enumerate([0, 100, 1000, 10000, 30000, 60000]):
|
|
25
|
+
# [snippet:ng]
|
|
26
|
+
ng = NeuralGas(n_nodes=300, max_iter=max(t_max, 1), random_state=0).fit(X)
|
|
27
|
+
# [/snippet:ng]
|
|
28
|
+
ax = fig.add_subplot(2, 3, i + 1, projection="3d")
|
|
29
|
+
ax.scatter(*sub.T, s=1, c="#C9D3DD")
|
|
30
|
+
ax.scatter(*ng.nodes_.T, s=6, c="#0072B2")
|
|
31
|
+
ax.set_title("initialization" if t_max == 0 else f"{t_max} adaptation steps", fontsize=10)
|
|
32
|
+
ax.view_init(20, -60)
|
|
33
|
+
ax.set_xticks([])
|
|
34
|
+
ax.set_yticks([])
|
|
35
|
+
ax.set_zticks([])
|
|
36
|
+
print(f"t_max={t_max:6d} quantization error {ng.quantization_error(X):.3f}")
|
|
37
|
+
plt.tight_layout()
|