graphclust 1.0__py3-none-any.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.
graphclust/__init__.py ADDED
@@ -0,0 +1,102 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2026 Ágnes Vathy-Fogarassy, János Abonyi
3
+ """graphclust -- graph-based clustering and data visualization in Python.
4
+
5
+ The Python successor of the MATLAB Graph-Based Clustering and Data
6
+ Visualization Toolbox of Ágnes Vathy-Fogarassy and János Abonyi, extended with
7
+ the main graph-based methods published since 2013. Modules:
8
+
9
+ * :mod:`graphclust.graphs` -- neighborhood graphs, spanning trees, geodesic distances
10
+ * :mod:`graphclust.vq` -- vector quantization and topology learning (NG, GNG, GWR, TRN, DTRN, WINN, LBG)
11
+ * :mod:`graphclust.cluster` -- graph-based clustering (MST, hybrid MST-GG, HDBSCAN*, Jarvis--Patrick,
12
+ fuzzy neighborhood similarity, SNN, density peaks, spectral, Louvain/Leiden)
13
+ * :mod:`graphclust.manifold` -- mappings (Sammon, MDS, LPP, SOM, IGG, Isomap, Isotop, CCA/CDA,
14
+ OVI-NG, GNLP-NG, TRNMap, Laplacian eigenmaps, diffusion maps, UMAP, t-SNE)
15
+ * :mod:`graphclust.metrics` -- mapping quality (stress, trustworthiness, continuity, co-ranking, R_NX)
16
+ * :mod:`graphclust.validity` -- cluster validity (Dunn-MST, FHV, Fukuyama--Sugeno, DBCV)
17
+ * :mod:`graphclust.vat` -- visual assessment of cluster tendency (VAT, iVAT)
18
+ * :mod:`graphclust.datasets`, :mod:`graphclust.plotting`
19
+ """
20
+
21
+ from .cluster import (
22
+ DensityPeaks,
23
+ FuzzyNeighborhoodClustering,
24
+ GraphCommunityClustering,
25
+ HDBSCANStar,
26
+ HybridMSTGG,
27
+ JarvisPatrick,
28
+ MSTClustering,
29
+ SharedNearestNeighborClustering,
30
+ SpectralGraphClustering,
31
+ fuzzy_neighborhood_similarity,
32
+ )
33
+ from .fuzzy import GathGeva
34
+ from .manifold import (
35
+ CurvilinearComponentAnalysis,
36
+ DiffusionMap,
37
+ GeodesicNLPNG,
38
+ IncrementalGridGrowing,
39
+ Isomap,
40
+ Isotop,
41
+ LaplacianEigenmap,
42
+ LocalityPreservingProjection,
43
+ MetricMDS,
44
+ NonMetricMDS,
45
+ OnlineVisualizationNG,
46
+ SammonMapping,
47
+ SelfOrganizingMap,
48
+ TRNMap,
49
+ UMAPEmbedding,
50
+ classical_mds,
51
+ tsne,
52
+ )
53
+ from .vq import (
54
+ LBG,
55
+ DynamicTopologyRepresentingNetwork,
56
+ GrowingNeuralGas,
57
+ GrowWhenRequired,
58
+ NeuralGas,
59
+ TopologyRepresentingNetwork,
60
+ WeightedIncrementalNetwork,
61
+ )
62
+
63
+ __version__ = "1.0"
64
+
65
+ __all__ = [
66
+ "LBG",
67
+ "CurvilinearComponentAnalysis",
68
+ "DensityPeaks",
69
+ "DiffusionMap",
70
+ "DynamicTopologyRepresentingNetwork",
71
+ "FuzzyNeighborhoodClustering",
72
+ "GathGeva",
73
+ "GeodesicNLPNG",
74
+ "GraphCommunityClustering",
75
+ "GrowWhenRequired",
76
+ "GrowingNeuralGas",
77
+ "HDBSCANStar",
78
+ "HybridMSTGG",
79
+ "IncrementalGridGrowing",
80
+ "Isomap",
81
+ "Isotop",
82
+ "JarvisPatrick",
83
+ "LaplacianEigenmap",
84
+ "LocalityPreservingProjection",
85
+ "MSTClustering",
86
+ "MetricMDS",
87
+ "NeuralGas",
88
+ "NonMetricMDS",
89
+ "OnlineVisualizationNG",
90
+ "SammonMapping",
91
+ "SelfOrganizingMap",
92
+ "SharedNearestNeighborClustering",
93
+ "SpectralGraphClustering",
94
+ "TRNMap",
95
+ "TopologyRepresentingNetwork",
96
+ "UMAPEmbedding",
97
+ "WeightedIncrementalNetwork",
98
+ "__version__",
99
+ "classical_mds",
100
+ "fuzzy_neighborhood_similarity",
101
+ "tsne",
102
+ ]
graphclust/_utils.py ADDED
@@ -0,0 +1,86 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2026 Ágnes Vathy-Fogarassy, János Abonyi
3
+ """Small numerical helpers shared by all modules (not part of the public API)."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import numpy as np
8
+ from scipy.spatial.distance import cdist, pdist, squareform
9
+ from sklearn.utils import check_array, check_random_state
10
+
11
+ EPS = np.finfo(float).eps
12
+
13
+ __all__ = [
14
+ "EPS",
15
+ "as_data",
16
+ "check_random_state",
17
+ "decay",
18
+ "minmax_scale",
19
+ "pairwise_distances",
20
+ "sq_distances",
21
+ "ranks_from_distances",
22
+ ]
23
+
24
+
25
+ def as_data(X, *, min_samples: int = 1, name: str = "X") -> np.ndarray:
26
+ """Validate a data matrix and return it as a C-contiguous float array."""
27
+ X = check_array(X, dtype=float, ensure_min_samples=min_samples, input_name=name)
28
+ return np.ascontiguousarray(X)
29
+
30
+
31
+ def decay(initial: float, final: float, t: float, t_max: float) -> float:
32
+ r"""Exponential schedule :math:`g(t) = g_i\,(g_f/g_i)^{t/t_{\max}}`.
33
+
34
+ All the competitive learning algorithms of the package (neural gas,
35
+ topology representing networks, OVI-NG, GNLP-NG, TRNMap fine tuning, the
36
+ self-organizing map) use this schedule for their step sizes, neighborhood
37
+ ranges and edge lifetimes.
38
+
39
+ Examples
40
+ --------
41
+ >>> round(decay(1.0, 0.01, 50, 100), 3)
42
+ 0.1
43
+ """
44
+ if initial == 0.0:
45
+ return final
46
+ return float(initial * (final / initial) ** (t / max(t_max, 1)))
47
+
48
+
49
+ def minmax_scale(X) -> np.ndarray:
50
+ """Scale every feature to [0, 1] (constant features become 0)."""
51
+ X = as_data(X)
52
+ lo, hi = X.min(axis=0), X.max(axis=0)
53
+ rng = np.where(hi - lo > 0, hi - lo, 1.0)
54
+ return (X - lo) / rng
55
+
56
+
57
+ def pairwise_distances(X, Y=None, metric: str = "euclidean") -> np.ndarray:
58
+ """Dense matrix of pairwise distances (SciPy backend)."""
59
+ X = np.asarray(X, dtype=float)
60
+ if Y is None:
61
+ return squareform(pdist(X, metric=metric))
62
+ return cdist(X, np.asarray(Y, dtype=float), metric=metric)
63
+
64
+
65
+ def sq_distances(X, Y) -> np.ndarray:
66
+ """Squared Euclidean distances between the rows of ``X`` and ``Y``."""
67
+ X = np.asarray(X, dtype=float)
68
+ Y = np.asarray(Y, dtype=float)
69
+ d2 = (X * X).sum(1)[:, None] - 2.0 * X @ Y.T + (Y * Y).sum(1)[None, :]
70
+ return np.maximum(d2, 0.0)
71
+
72
+
73
+ def ranks_from_distances(D: np.ndarray) -> np.ndarray:
74
+ r"""Neighborhood ranks :math:`\rho_{ij}` from a distance matrix.
75
+
76
+ ``R[i, j]`` is the rank of sample ``j`` among the neighbors of sample ``i``
77
+ (the sample itself has rank 0, its nearest neighbor rank 1). Ties are
78
+ broken by index, as in the co-ranking framework of Lee and Verleysen.
79
+ """
80
+ D = np.asarray(D, dtype=float)
81
+ N = D.shape[0]
82
+ order = np.argsort(D + np.diag(np.full(N, -np.inf)), axis=1, kind="stable")
83
+ R = np.empty_like(order)
84
+ rows = np.arange(N)[:, None]
85
+ R[rows, order] = np.arange(N)[None, :]
86
+ return R