srdkit 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.
- srdkit/__init__.py +101 -0
- srdkit/_utils.py +75 -0
- srdkit/_version.py +1 -0
- srdkit/anova.py +185 -0
- srdkit/clustering.py +110 -0
- srdkit/core.py +364 -0
- srdkit/datasets/__init__.py +160 -0
- srdkit/datasets/data/co2_2018.csv +148 -0
- srdkit/diagnostics.py +186 -0
- srdkit/distances.py +204 -0
- srdkit/distribution.py +503 -0
- srdkit/framework.py +368 -0
- srdkit/fusion.py +221 -0
- srdkit/gpcm.py +138 -0
- srdkit/mcda.py +201 -0
- srdkit/nmf.py +141 -0
- srdkit/parcoord.py +283 -0
- srdkit/pareto.py +126 -0
- srdkit/promethee.py +371 -0
- srdkit/ranking.py +193 -0
- srdkit/reference.py +232 -0
- srdkit/report.py +114 -0
- srdkit/representation.py +127 -0
- srdkit/segmentation.py +247 -0
- srdkit/simulate.py +171 -0
- srdkit/tournament.py +167 -0
- srdkit/utility.py +277 -0
- srdkit/validation.py +501 -0
- srdkit/value.py +189 -0
- srdkit/viz/__init__.py +31 -0
- srdkit/viz/_style.py +87 -0
- srdkit/viz/applications.py +156 -0
- srdkit/viz/basic.py +201 -0
- srdkit/viz/framework.py +148 -0
- srdkit/viz/maps.py +145 -0
- srdkit/viz/validation.py +149 -0
- srdkit/weighted.py +167 -0
- srdkit/weights.py +230 -0
- srdkit-1.0.dist-info/METADATA +151 -0
- srdkit-1.0.dist-info/RECORD +42 -0
- srdkit-1.0.dist-info/WHEEL +4 -0
- srdkit-1.0.dist-info/licenses/LICENSE +21 -0
srdkit/weights.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
r"""Weights taken from the data: SRD-based weighting.
|
|
2
|
+
|
|
3
|
+
Most MCDM methods need criterion weights, and the choice of a weighting scheme
|
|
4
|
+
is itself a subjective decision: the many "objective" schemes (entropy,
|
|
5
|
+
standard deviation, CRITIC, ...) give different rankings, so choosing among them
|
|
6
|
+
is subjective again (Héberger, 2026). SRD needs no weights, but it can supply
|
|
7
|
+
them from the structure of the data (Gere, Szakál and Héberger, 2022): the
|
|
8
|
+
columns are ranked and grouped by SRD, the groups get reversed-rank weights
|
|
9
|
+
(with three groups 3/6, 2/6 and 1/6, best group first), and the weights are used
|
|
10
|
+
to build a weighted reference --- or handed to another MCDM method as its
|
|
11
|
+
criterion weights.
|
|
12
|
+
|
|
13
|
+
The functions below implement this idea in several variants:
|
|
14
|
+
|
|
15
|
+
* :func:`srd_weights` --- weights of the columns from their SRD ranking or SRD
|
|
16
|
+
grouping (reversed group rank as in the paper, reversed rank, or the
|
|
17
|
+
complement of the normalized SRD);
|
|
18
|
+
* :func:`group_srd_values` --- one-dimensional grouping of SRD values by
|
|
19
|
+
explicit cut points, by the largest gaps or by the optimal partition into
|
|
20
|
+
``k`` groups (Fisher's exact 1-D clustering);
|
|
21
|
+
* :func:`weighted_reference_srd` --- SRD against the weighted reference;
|
|
22
|
+
* :func:`self_weighted_srd` --- the iteration *SRD → weights → weighted
|
|
23
|
+
reference → SRD* until the weights stop changing (new: a fixed point of the
|
|
24
|
+
data-driven weighting);
|
|
25
|
+
* :func:`criterion_weights` --- weights of the criteria of an MCDM decision
|
|
26
|
+
matrix from an SRD analysis of the criteria, for the weighted MCDM methods.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
from dataclasses import dataclass, field
|
|
32
|
+
|
|
33
|
+
import numpy as np
|
|
34
|
+
import pandas as pd
|
|
35
|
+
|
|
36
|
+
from ._utils import as_frame
|
|
37
|
+
from .core import SRDResult, srd
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _fisher_partition(v: np.ndarray, k: int) -> np.ndarray:
|
|
41
|
+
"""Optimal partition of sorted values into k contiguous groups (minimum within-group SS)."""
|
|
42
|
+
n = v.size
|
|
43
|
+
k = max(1, min(k, n))
|
|
44
|
+
cs = np.concatenate([[0], np.cumsum(v)])
|
|
45
|
+
cs2 = np.concatenate([[0], np.cumsum(v ** 2)])
|
|
46
|
+
|
|
47
|
+
def ss(i, j): # values i..j-1
|
|
48
|
+
s, s2, c = cs[j] - cs[i], cs2[j] - cs2[i], j - i
|
|
49
|
+
return s2 - s * s / c
|
|
50
|
+
|
|
51
|
+
cost = np.full((k + 1, n + 1), np.inf)
|
|
52
|
+
arg = np.zeros((k + 1, n + 1), int)
|
|
53
|
+
cost[0, 0] = 0.0
|
|
54
|
+
for g in range(1, k + 1):
|
|
55
|
+
for j in range(g, n + 1):
|
|
56
|
+
best, bi = np.inf, g - 1
|
|
57
|
+
for i in range(g - 1, j):
|
|
58
|
+
c = cost[g - 1, i] + ss(i, j)
|
|
59
|
+
if c < best:
|
|
60
|
+
best, bi = c, i
|
|
61
|
+
cost[g, j], arg[g, j] = best, bi
|
|
62
|
+
labels = np.zeros(n, int)
|
|
63
|
+
j = n
|
|
64
|
+
for g in range(k, 0, -1):
|
|
65
|
+
i = arg[g, j]
|
|
66
|
+
labels[i:j] = g
|
|
67
|
+
j = i
|
|
68
|
+
return labels
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def group_srd_values(values, cuts=None, k: int | None = None, gap: float | None = None) -> pd.Series:
|
|
72
|
+
"""Group SRD values along the line (1 = group of the smallest values).
|
|
73
|
+
|
|
74
|
+
Exactly one rule is used, in this order: ``cuts`` (explicit boundaries, in the
|
|
75
|
+
units of ``values``), ``gap`` (a new group starts where consecutive sorted
|
|
76
|
+
values differ by more than ``gap``), ``k`` (optimal partition into ``k``
|
|
77
|
+
groups). Default: ``k=3``, as in Gere et al. (2022).
|
|
78
|
+
|
|
79
|
+
>>> group_srd_values([10, 12, 30, 33, 60], k=3).tolist()
|
|
80
|
+
[1, 1, 2, 2, 3]
|
|
81
|
+
"""
|
|
82
|
+
s = pd.Series(values, dtype=float)
|
|
83
|
+
order = np.argsort(s.to_numpy(), kind="stable")
|
|
84
|
+
v = s.to_numpy()[order]
|
|
85
|
+
if cuts is not None:
|
|
86
|
+
lab_sorted = np.searchsorted(np.sort(np.asarray(cuts, float)), v, side="right") + 1
|
|
87
|
+
# renumber so that empty groups do not leave holes
|
|
88
|
+
_, lab_sorted = np.unique(lab_sorted, return_inverse=True)
|
|
89
|
+
lab_sorted = lab_sorted + 1
|
|
90
|
+
elif gap is not None:
|
|
91
|
+
lab_sorted = np.concatenate([[1], 1 + np.cumsum(np.diff(v) > gap)])
|
|
92
|
+
else:
|
|
93
|
+
lab_sorted = _fisher_partition(v, 3 if k is None else int(k))
|
|
94
|
+
lab = np.empty_like(lab_sorted)
|
|
95
|
+
lab[order] = lab_sorted
|
|
96
|
+
return pd.Series(lab, index=s.index, name="group")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def srd_weights(result_or_X, reference="mean", scheme: str = "group", cuts=None, k: int | None = 3, gap: float | None = None,
|
|
100
|
+
normalize: bool = True, **srd_kwargs) -> pd.Series:
|
|
101
|
+
r"""Data-driven weights of the columns from an SRD analysis.
|
|
102
|
+
|
|
103
|
+
Parameters
|
|
104
|
+
----------
|
|
105
|
+
result_or_X : SRDResult or array-like
|
|
106
|
+
An SRD result, or the data (then ``srd(X, reference)`` is computed).
|
|
107
|
+
scheme : {"group", "rank", "complement"}
|
|
108
|
+
``"group"``: the columns are grouped by their SRD values
|
|
109
|
+
(:func:`group_srd_values`) and group :math:`g` of :math:`G` (1 = best)
|
|
110
|
+
gets :math:`(G-g+1)/\sum_{h=1}^G h` --- 3/6, 2/6, 1/6 for three groups,
|
|
111
|
+
the scheme of Gere et al. (2022). ``"rank"``: reversed SRD rank,
|
|
112
|
+
:math:`w_j\propto m+1-\mathrm{rank}_j`. ``"complement"``:
|
|
113
|
+
:math:`w_j\propto 1-\mathrm{SRD}_j/\mathrm{SRD}_{\max}`, which keeps the
|
|
114
|
+
distances between the columns.
|
|
115
|
+
cuts, k, gap
|
|
116
|
+
Grouping rule for ``scheme="group"`` (``cuts`` in percent of the maximum).
|
|
117
|
+
normalize : bool
|
|
118
|
+
Scale the weights to sum 1 (for ``"group"`` the group weights of the paper
|
|
119
|
+
are returned when False).
|
|
120
|
+
|
|
121
|
+
>>> import numpy as np
|
|
122
|
+
>>> X = np.array([[1, 1, 2, 5], [2, 2, 1, 4], [3, 3, 3, 3], [4, 5, 4, 2], [5, 4, 5, 1]])
|
|
123
|
+
>>> srd_weights(X, scheme="group", k=2, normalize=False).round(3).tolist()
|
|
124
|
+
[0.667, 0.667, 0.667, 0.333]
|
|
125
|
+
"""
|
|
126
|
+
res = result_or_X if isinstance(result_or_X, SRDResult) else srd(result_or_X, reference=reference, **srd_kwargs)
|
|
127
|
+
pct = res.percent
|
|
128
|
+
m = len(pct)
|
|
129
|
+
if scheme == "group":
|
|
130
|
+
g = group_srd_values(pct, cuts=cuts, k=k, gap=gap)
|
|
131
|
+
G = int(g.max())
|
|
132
|
+
w = (G - g + 1) / (G * (G + 1) / 2)
|
|
133
|
+
elif scheme == "rank":
|
|
134
|
+
w = (m + 1 - pct.rank(method="average")).astype(float)
|
|
135
|
+
elif scheme == "complement":
|
|
136
|
+
w = (1 - res.normalized).clip(lower=0)
|
|
137
|
+
else:
|
|
138
|
+
raise ValueError("scheme must be 'group', 'rank' or 'complement'")
|
|
139
|
+
w = pd.Series(w, index=pct.index, name="weight", dtype=float)
|
|
140
|
+
if normalize and w.sum() > 0:
|
|
141
|
+
w = w / w.sum()
|
|
142
|
+
return w
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def weighted_reference_srd(X, weights, method: str = "mean", **srd_kwargs) -> SRDResult:
|
|
146
|
+
"""SRD against the weighted reference (weighted row mean, or weighted median with ``method="median"``)."""
|
|
147
|
+
df = as_frame(X)
|
|
148
|
+
w = pd.Series(weights, index=df.columns, dtype=float) if not isinstance(weights, pd.Series) else weights.reindex(df.columns)
|
|
149
|
+
w = w.fillna(0).to_numpy()
|
|
150
|
+
A = df.to_numpy(float)
|
|
151
|
+
if method == "mean":
|
|
152
|
+
y = A @ w / w.sum()
|
|
153
|
+
elif method == "median":
|
|
154
|
+
y = np.empty(A.shape[0])
|
|
155
|
+
for i, row in enumerate(A):
|
|
156
|
+
o = np.argsort(row)
|
|
157
|
+
cw = np.cumsum(w[o]) / w.sum()
|
|
158
|
+
y[i] = row[o][np.searchsorted(cw, 0.5)]
|
|
159
|
+
else:
|
|
160
|
+
raise ValueError("method must be 'mean' or 'median'")
|
|
161
|
+
res = srd(df, reference=y, **srd_kwargs)
|
|
162
|
+
res.reference_method = f"weighted {method}"
|
|
163
|
+
res.meta["weights"] = pd.Series(w, index=df.columns)
|
|
164
|
+
return res
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@dataclass
|
|
168
|
+
class SelfWeightedResult:
|
|
169
|
+
"""Result of :func:`self_weighted_srd`."""
|
|
170
|
+
|
|
171
|
+
result: SRDResult
|
|
172
|
+
weights: pd.Series
|
|
173
|
+
history: pd.DataFrame
|
|
174
|
+
converged: bool
|
|
175
|
+
n_iter: int
|
|
176
|
+
meta: dict = field(default_factory=dict)
|
|
177
|
+
|
|
178
|
+
def __repr__(self) -> str:
|
|
179
|
+
return (f"SelfWeightedResult(converged={self.converged}, n_iter={self.n_iter}, "
|
|
180
|
+
f"weights={self.weights.round(3).to_dict()})")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def self_weighted_srd(X, reference="mean", scheme: str = "group", k: int | None = 3, cuts=None, gap: float | None = None,
|
|
184
|
+
max_iter: int = 25, tol: float = 1e-9, **srd_kwargs) -> SelfWeightedResult:
|
|
185
|
+
"""Iterate SRD → data-driven weights → weighted reference → SRD to a fixed point (new).
|
|
186
|
+
|
|
187
|
+
The first step is the unweighted analysis against ``reference``; the
|
|
188
|
+
following steps use the weighted row mean. With the discrete schemes
|
|
189
|
+
(``"group"``, ``"rank"``) the iteration either reaches a fixed point or
|
|
190
|
+
cycles; a cycle is reported as not converged and the last weights are kept.
|
|
191
|
+
"""
|
|
192
|
+
df = as_frame(X)
|
|
193
|
+
res = srd(df, reference=reference, **srd_kwargs)
|
|
194
|
+
hist, seen = [], {}
|
|
195
|
+
converged = False
|
|
196
|
+
w = None
|
|
197
|
+
for it in range(1, max_iter + 1):
|
|
198
|
+
w_new = srd_weights(res, scheme=scheme, k=k, cuts=cuts, gap=gap)
|
|
199
|
+
hist.append(w_new.rename(f"iter{it}"))
|
|
200
|
+
key = tuple(np.round(w_new.to_numpy(), 12))
|
|
201
|
+
if w is not None and np.max(np.abs(w_new.to_numpy() - w.to_numpy())) <= tol:
|
|
202
|
+
converged = True
|
|
203
|
+
w = w_new
|
|
204
|
+
break
|
|
205
|
+
if key in seen: # a cycle of the discrete map
|
|
206
|
+
w = w_new
|
|
207
|
+
break
|
|
208
|
+
seen[key] = it
|
|
209
|
+
w = w_new
|
|
210
|
+
res = weighted_reference_srd(df, w, **srd_kwargs)
|
|
211
|
+
return SelfWeightedResult(result=res, weights=w, history=pd.DataFrame(hist), converged=converged, n_iter=len(hist),
|
|
212
|
+
meta={"scheme": scheme})
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def criterion_weights(D, directions=None, reference="borda", scheme: str = "complement", **kwargs) -> pd.Series:
|
|
216
|
+
"""Criterion weights for the MCDM methods of :mod:`srdkit.mcda`, taken from the data.
|
|
217
|
+
|
|
218
|
+
``D`` is a decision matrix in MCDM orientation (rows = alternatives, columns =
|
|
219
|
+
criteria). Cost criteria (``directions`` ``"min"``) are reversed, every
|
|
220
|
+
criterion is treated as a solution ranking the alternatives, and the
|
|
221
|
+
criteria that agree best with the consensus ranking (``reference``, by
|
|
222
|
+
default the mean rank) get the largest weights (:func:`srd_weights`).
|
|
223
|
+
"""
|
|
224
|
+
df = as_frame(D)
|
|
225
|
+
if directions is not None:
|
|
226
|
+
dirs = [directions.get(c, "max") for c in df.columns] if isinstance(directions, dict) else list(directions)
|
|
227
|
+
for c, d in zip(df.columns, dirs):
|
|
228
|
+
if str(d).lower() == "min":
|
|
229
|
+
df[c] = -df[c]
|
|
230
|
+
return srd_weights(df, reference=reference, scheme=scheme, **kwargs)
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: srdkit
|
|
3
|
+
Version: 1.0
|
|
4
|
+
Summary: Sum of Ranking Differences (SRD) in Python: the complete SRD family (classic, tied, weighted, value-based DnE/DnM, utility-based uSRD, Promethee P-SRD, NMF-SRD), exact null distributions for any tie pattern, cross-validation tests, SRD-ANOVA, data-driven weights, a tested consensus of complementary MCDM methods, GPCM, fusion, segmentation, representation and visualization.
|
|
5
|
+
Project-URL: Homepage, https://github.com/ComplexSystemsIntelligence/srdkit
|
|
6
|
+
Project-URL: Documentation, https://complexsystemsintelligence.github.io/srdkit
|
|
7
|
+
Project-URL: Repository, https://github.com/ComplexSystemsIntelligence/srdkit
|
|
8
|
+
Project-URL: Issues, https://github.com/ComplexSystemsIntelligence/srdkit/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/ComplexSystemsIntelligence/srdkit/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Book (PDF), https://complexsystemsintelligence.github.io/srdkit/srdkit-book.pdf
|
|
11
|
+
Author: Ádám Ipkovich
|
|
12
|
+
Author-email: Károly Héberger <heberger.karoly@ttk.hu>, János Abonyi <janos@abonyilab.com>
|
|
13
|
+
Maintainer-email: János Abonyi <janos@abonyilab.com>
|
|
14
|
+
License-Expression: MIT
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Keywords: MCDM,Promethee,SRD,Spearman footrule,chemometrics,cross-validation,method comparison,model comparison,multicriteria decision making,parallel coordinates,permutation test,rank aggregation,ranking,sum of ranking differences
|
|
17
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Operating System :: OS Independent
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
28
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
29
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
30
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
31
|
+
Requires-Python: >=3.10
|
|
32
|
+
Requires-Dist: matplotlib>=3.7
|
|
33
|
+
Requires-Dist: numpy>=1.24
|
|
34
|
+
Requires-Dist: pandas>=2.0
|
|
35
|
+
Requires-Dist: scipy>=1.11
|
|
36
|
+
Provides-Extra: all
|
|
37
|
+
Requires-Dist: openpyxl>=3.1; extra == 'all'
|
|
38
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'all'
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: build; extra == 'dev'
|
|
41
|
+
Requires-Dist: myst-parser; extra == 'dev'
|
|
42
|
+
Requires-Dist: numpydoc; extra == 'dev'
|
|
43
|
+
Requires-Dist: openpyxl>=3.1; extra == 'dev'
|
|
44
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'dev'
|
|
45
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
47
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
48
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'dev'
|
|
49
|
+
Requires-Dist: sphinx-copybutton; extra == 'dev'
|
|
50
|
+
Requires-Dist: sphinx-design; extra == 'dev'
|
|
51
|
+
Requires-Dist: sphinx-gallery>=0.15; extra == 'dev'
|
|
52
|
+
Requires-Dist: sphinx>=7; extra == 'dev'
|
|
53
|
+
Requires-Dist: twine; extra == 'dev'
|
|
54
|
+
Provides-Extra: docs
|
|
55
|
+
Requires-Dist: myst-parser; extra == 'docs'
|
|
56
|
+
Requires-Dist: numpydoc; extra == 'docs'
|
|
57
|
+
Requires-Dist: openpyxl>=3.1; extra == 'docs'
|
|
58
|
+
Requires-Dist: pydata-sphinx-theme; extra == 'docs'
|
|
59
|
+
Requires-Dist: sphinx-copybutton; extra == 'docs'
|
|
60
|
+
Requires-Dist: sphinx-design; extra == 'docs'
|
|
61
|
+
Requires-Dist: sphinx-gallery>=0.15; extra == 'docs'
|
|
62
|
+
Requires-Dist: sphinx>=7; extra == 'docs'
|
|
63
|
+
Provides-Extra: excel
|
|
64
|
+
Requires-Dist: openpyxl>=3.1; extra == 'excel'
|
|
65
|
+
Provides-Extra: ml
|
|
66
|
+
Requires-Dist: scikit-learn>=1.3; extra == 'ml'
|
|
67
|
+
Provides-Extra: test
|
|
68
|
+
Requires-Dist: pytest-cov; extra == 'test'
|
|
69
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
70
|
+
Description-Content-Type: text/markdown
|
|
71
|
+
|
|
72
|
+
<p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/srdkit/main/docs/_static/banner.png" alt="srdkit: sum of ranking differences in Python"></p>
|
|
73
|
+
|
|
74
|
+
# srdkit: sum of ranking differences in Python
|
|
75
|
+
|
|
76
|
+
[](https://github.com/ComplexSystemsIntelligence/srdkit/actions/workflows/ci.yml)
|
|
77
|
+
[](https://complexsystemsintelligence.github.io/srdkit)
|
|
78
|
+
[](https://complexsystemsintelligence.github.io/srdkit/book.html)
|
|
79
|
+
[](https://pypi.org/project/srdkit/)
|
|
80
|
+
[](https://github.com/ComplexSystemsIntelligence/srdkit/blob/main/LICENSE)
|
|
81
|
+
|
|
82
|
+
**srdkit** compares methods, models, laboratories, experts or alternatives
|
|
83
|
+
fairly. The sum of ranking differences (SRD) of Héberger
|
|
84
|
+
([TrAC 29: 101–109, 2010](https://doi.org/10.1016/j.trac.2009.09.009)) ranks
|
|
85
|
+
every solution and a reference — a gold standard or a consensus fused from the
|
|
86
|
+
data — and sums the absolute rank differences. Two statistical validations
|
|
87
|
+
follow: a randomization test (comparison of ranks with random numbers, CRRN)
|
|
88
|
+
and cross-validation. SRD needs no weights, and the classical multicriteria
|
|
89
|
+
decision-making (MCDM) methods offer no such validation of their rankings
|
|
90
|
+
(Héberger, [Anal. Chim. Acta 1381: 344649, 2026](https://doi.org/10.1016/j.aca.2025.344649)).
|
|
91
|
+
|
|
92
|
+
The package implements the published SRD methods — of Héberger and co-workers,
|
|
93
|
+
of the authors' group and of others — and adds new ones.
|
|
94
|
+
|
|
95
|
+
| Module | Contents |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `srdkit.core`, `ranking`, `reference` | SRD with mid-ranks, every data-fusion reference (mean, median, min, max, mixed, trimmed, weighted, mean rank), footrule-optimal and Kemeny consensus, leave-one-out references, pairwise SRD, a scikit-learn style estimator |
|
|
98
|
+
| `srdkit.distribution`, `validation`, `anova` | **exact null distribution for any number of objects and any ties** (new), exact moments, rSRD-compatible Monte Carlo options; CRRN; cross-validation (random, k-fold, contiguous, LOO, bootstrap, 5x2) with Wilcoxon, Dietterich, Alpaydin, Nadeau–Bengio, sign and permutation tests; Friedman test, critical differences, letter displays; SRD-ANOVA |
|
|
99
|
+
| `srdkit.distances`, `weighted`, `value`, `utility` | Kendall, Cayley, Ulam, Hamming, Spearman, Chebyshev and Cayley–footrule distances with exact nulls; weighted and top-k SRD with exact normalization; soft ranks; **DnE and DnM** beyond the ranks with randomization test and cross-validation; utility-based SRD (uSRD) |
|
|
100
|
+
| `srdkit.promethee`, `mcda`, `pareto`, `nmf` | Promethee II, P-SRD, GAIA, sparse GAIA, P-PFA; eleven MCDM methods and objective weights; non-dominated sorting, post-Pareto SRD; NMF-SRD many-objective ranking |
|
|
101
|
+
| `srdkit.weights`, `tournament`, `framework` | SRD-derived weights and weighted references (Gere et al. 2022), self-consistent weighting (new); power–weakness ratio and sPWR; **the seven-method consensus framework of Héberger (2026)** — SRD, DnE, DnM, COVAT heatmap, CEpW, WtpW, DRAPE/PWR — with Friedman, Wilcoxon and leave-one-method-out tests |
|
|
102
|
+
| `srdkit.parcoord`, `representation`, `clustering`, `viz` | SRD-ordered parallel coordinates with the deviation angle (Ipkovich et al. 2021) and crossing-minimal orderings; SRD maps and constellations; heatmaps, dendrograms, similarity groups; all plots |
|
|
103
|
+
| `srdkit.segmentation`, `fusion`, `gpcm` | regimes of ranking sequences, range-dependent agreement; model-merit fusion, consensus outliers, SRD-ROC; PCM and GPCM with conditional exact and Williams' tests |
|
|
104
|
+
| `srdkit.diagnostics`, `report` | object influence, reference and tie sensitivity, noise robustness, power analysis, criteria reduction; the one-call report |
|
|
105
|
+
|
|
106
|
+
## Installation
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install srdkit
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Python ≥ 3.10; depends on numpy, scipy, pandas and matplotlib.
|
|
113
|
+
|
|
114
|
+
## Quick start
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import srdkit as sk
|
|
118
|
+
|
|
119
|
+
X, y = sk.datasets.small_example() # 8 objects (rows), 5 solutions (columns), a gold standard
|
|
120
|
+
res = sk.srd(X, reference=y) # or reference="mean", "max", "min", "mixed", ...
|
|
121
|
+
val = res.validate() # exact randomization test: similar / random / reversed
|
|
122
|
+
cv = res.cross_validate(n_folds=8) # uncertainties
|
|
123
|
+
print(cv.test()) # Wilcoxon tests of neighbouring solutions
|
|
124
|
+
sk.viz.plot_srd(res, val) # the classical SRD plot
|
|
125
|
+
|
|
126
|
+
sk.dne(X, reference=y) # beyond ranks: sum of Euclidean distance differences
|
|
127
|
+
fc = sk.fair_comparison(X, reference=y) # tested consensus of seven complementary methods
|
|
128
|
+
print(fc.summary())
|
|
129
|
+
print(sk.analyze(X, reference=y).to_markdown()) # the whole analysis as a report
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Documentation and book
|
|
133
|
+
|
|
134
|
+
* Documentation with the example gallery and the API: https://complexsystemsintelligence.github.io/srdkit
|
|
135
|
+
* The book *Sum of Ranking Differences in Python: The srdkit toolbox* (CC BY 4.0) is built from `book/`;
|
|
136
|
+
every computed figure comes from a script of the gallery.
|
|
137
|
+
|
|
138
|
+
## Citing
|
|
139
|
+
|
|
140
|
+
K. Héberger, Á. Ipkovich, J. Abonyi, *srdkit: sum of ranking differences in Python*, version 1.0, 2026.
|
|
141
|
+
Please cite also the original publications of the methods you use; see `CITATION.cff` and the
|
|
142
|
+
[citing page](https://complexsystemsintelligence.github.io/srdkit/citing.html).
|
|
143
|
+
|
|
144
|
+
## Acknowledgement
|
|
145
|
+
|
|
146
|
+
Supported by the National Research, Development and Innovation Office of Hungary (NKFIH) through the
|
|
147
|
+
OTKA 143482 project.
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT for the software, CC BY 4.0 for the book.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
srdkit/__init__.py,sha256=RxldDpF0KVvFzQraZ5oKl1FnNA_IAsYc9Y5Eqn42c2Q,5356
|
|
2
|
+
srdkit/_utils.py,sha256=zSV4Vq5ANhW1uvBjCd6TBUfxTDNIarYhFuPt4pGO6kI,2794
|
|
3
|
+
srdkit/_version.py,sha256=kM55qqhSrc4b-StNTuN03Srg0kwfg1G4BckCKhUytaE,20
|
|
4
|
+
srdkit/anova.py,sha256=yodYeXJot4-1MJ7Q6yVKUhpLvnTpYaZ6W0reeeQiiXM,8066
|
|
5
|
+
srdkit/clustering.py,sha256=nBGrzI03iP7XAvJOGto93Tv6KeZn6rQiceMqJ0VNedY,4891
|
|
6
|
+
srdkit/core.py,sha256=x3AbeHg3NcPPyHko4cFCck8GPc4dO3QezePYxtzm1DM,15268
|
|
7
|
+
srdkit/diagnostics.py,sha256=uvrkS3OXOAwkpN8RzcufrOFTda_J1GWDuya8WJCCTrc,8572
|
|
8
|
+
srdkit/distances.py,sha256=YSbAsG-LnQ-GGsSIxprBzx96vK4PhKj1QuPau4X6u_U,7617
|
|
9
|
+
srdkit/distribution.py,sha256=vXKohSefOqq8HLEkuAnRzDPB9TCsTxo43kPw9MtGKBw,21614
|
|
10
|
+
srdkit/framework.py,sha256=SJQ-F2F68aAXxGfR7VCeqSW4P-7fu5APkufebgYSQm0,16603
|
|
11
|
+
srdkit/fusion.py,sha256=jU_7hlrkvuqbkUhtqr10BvvTZcdVgOl1eDvkkzLLgAs,10073
|
|
12
|
+
srdkit/gpcm.py,sha256=Tz6qZH3wpzFKua9lYaZKs_1zocgCsTyNF5sVp2xUZhU,6251
|
|
13
|
+
srdkit/mcda.py,sha256=033T9n9yxv1vn-ttYtaf3WANyGHHkazGRiJsBS3737I,8672
|
|
14
|
+
srdkit/nmf.py,sha256=IL_oTCa4lNpJf8zcB1EGI2ncbnUBLSOorQfJPxNBsrM,6808
|
|
15
|
+
srdkit/parcoord.py,sha256=bmtiBe1FVgsGnoRDniMHtvlW0RWcWLf1P01Shd3j2Yo,11631
|
|
16
|
+
srdkit/pareto.py,sha256=QDS1fxcieRK51isR8PRZD9Fx62PN2TlhIZ-uwvqGwZo,5008
|
|
17
|
+
srdkit/promethee.py,sha256=abUtbzpPnLms32527Gzlu2uolHVp9crmIPLTTKBT1ow,15646
|
|
18
|
+
srdkit/ranking.py,sha256=uo31Y8grcN7wChSP1giyKus4KcNdDURenE8M3VUxSYU,6994
|
|
19
|
+
srdkit/reference.py,sha256=FLz59GXigfktUJIXvlpSys6mQoaXTsl8P_rRDs8TYcQ,9412
|
|
20
|
+
srdkit/report.py,sha256=jqZcHZL1BkN9_8eCU6cHkHnA_8v1uOj_OkSxoNkOuD4,4801
|
|
21
|
+
srdkit/representation.py,sha256=EmTiI5pJjrSalxXoKr9cveLCYUPYlwEbuYvjQf9eD20,6168
|
|
22
|
+
srdkit/segmentation.py,sha256=HIVcE6O75wmjSkC7VRfqThlkqiiUt-QhReP30O4jxic,11104
|
|
23
|
+
srdkit/simulate.py,sha256=6ZjBPAAwo8-YB0evf_rts4584F-ACsQOZ823JmoCX7c,7066
|
|
24
|
+
srdkit/tournament.py,sha256=VX4f4rcecfgwWZFupO2maK-4E2blKYL_ZJ72cLGH0t4,7577
|
|
25
|
+
srdkit/utility.py,sha256=d4_dpOjF0gqTMK37hJTgSxuD6ztX7d4T55XnMXwXR7I,10817
|
|
26
|
+
srdkit/validation.py,sha256=fMIDjPkg0vPIZ6400XCoSxfzEBw_LaiLemv_ogxrbjs,21655
|
|
27
|
+
srdkit/value.py,sha256=p93fr8tJk8UKqw4ozmDgSJHLF3MjEDCkNJ1nsIiSZXQ,8768
|
|
28
|
+
srdkit/weighted.py,sha256=GIB9LPhAWQPPLKKWoWvkXm3AN2P7zUySGHgnNwyKKLs,7883
|
|
29
|
+
srdkit/weights.py,sha256=byUtQ91HtgMrDoej9tldnpj7qguzI54r88UE8Ch1cO4,9885
|
|
30
|
+
srdkit/datasets/__init__.py,sha256=aYWxnct1E6GJEaiEMghLBhBwCOXCIwh8LtZ33KnkKho,7909
|
|
31
|
+
srdkit/datasets/data/co2_2018.csv,sha256=17tdhQCVVCMLWuVOy3ynhESdspoUdGPG9am6d3Q2Pfo,26039
|
|
32
|
+
srdkit/viz/__init__.py,sha256=3-5RAFRxKO_h8dFvkc7ulM8bDIhifadaGauai8iOZCM,1304
|
|
33
|
+
srdkit/viz/_style.py,sha256=R5DjnRKpAk_wsmBMdicBqOcm-TUH5P8A96ONF2XF8oE,3091
|
|
34
|
+
srdkit/viz/applications.py,sha256=Fiuu2qME1JuagmfiK41UxxD4l_MigJTDwgKS6TvcSIE,6810
|
|
35
|
+
srdkit/viz/basic.py,sha256=pZSAMsBcpTlP1XGE81SNpZxgfMfuvSRMY58IckqHi2o,9811
|
|
36
|
+
srdkit/viz/framework.py,sha256=vbUAWg_vqvcBHO_-SSmh33QAK9GtdFPEusz1UskU-EQ,6442
|
|
37
|
+
srdkit/viz/maps.py,sha256=cUjTT0K9ragUAfcVk_I9SHhY1XilAVYlUYKULYnOjFs,6891
|
|
38
|
+
srdkit/viz/validation.py,sha256=2dri7dpzf5w21oGN3k708ec1CdPBrDxP71KYmOe3Zo4,6734
|
|
39
|
+
srdkit-1.0.dist-info/METADATA,sha256=LkVixsYSq7I4-AXBi6ZjsmTIqp30zXDIq1VIRY3RfOQ,9404
|
|
40
|
+
srdkit-1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
41
|
+
srdkit-1.0.dist-info/licenses/LICENSE,sha256=qDFsMZbJa6769gyvggRz14VscYXeuzm406tO5e_jTXc,1106
|
|
42
|
+
srdkit-1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Károly Héberger, Ádám Ipkovich, 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.
|