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
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
CountryName,AGReAllGHG,BLDeCO_2,BNKeCO_2,ELHeCO_2,ENGeAllGHG,ENGeCO_2,INDeAllGHG,INDeCO_2,LUCFeAllGHG,LUCFeCO_2,MANeCO_2,OFCeAllGHG,OFCeCO_2,TOTeAllGHG,TOTeCO_2,TRPeCO_2,WASeAllGHG,Pop,GDP,RuralPop,GDPGrowth,UrbanGrowth
|
|
2
|
+
Afghanistan,14.74,0.14,0.04,0.22,79.58,7.39,1.06,0.05,0.15,0.15,3.29,69.97,0.0,98.92,7.44,3.73,3.53,37171922,18353881129.52457,74.505,-1.194900383358842,3.3499343873148875
|
|
3
|
+
Albania,2.97,0.46,0.12,0.14,4.61,4.3,1.51,1.26,-0.24,-0.24,1.22,0.6,0.29,10.08,5.56,2.2,0.98,2866376,15147020535.386873,39.681,4.328395578467024,1.3171621044569775
|
|
4
|
+
Algeria,12.32,26.34,2.07,48.56,174.74,142.52,17.37,9.16,0.2,0.2,12.73,5.73,4.2,218.91,151.67,45.46,14.48,42228415,175414987760.92725,27.370999999999995,-0.8112331750953246,2.805020077080588
|
|
5
|
+
Angola,32.57,3.24,2.08,7.12,44.02,26.39,1.39,0.95,44.86,35.59,1.41,0.83,0.03,79.73,27.34,7.01,1.75,30809787,101353230784.59373,34.486000000000004,-5.162111790662408,4.311803148398667
|
|
6
|
+
Argentina,129.94,28.1,5.63,64.08,186.78,173.07,27.26,4.34,29.85,29.7,20.69,14.14,10.51,365.65,177.41,47.79,21.67,44494502,517626700412.8849,8.13,-3.5500911733347777,1.1476021589791883
|
|
7
|
+
Armenia,1.75,1.17,0.19,1.5,6.5,5.39,0.37,0.15,0.04,0.04,0.46,0.67,0.46,9.36,5.55,1.81,0.74,2951741,12457941907.033281,36.851,4.952230835625102,0.3086849233102482
|
|
8
|
+
Australia,159.54,15.1,16.1,221.26,426.09,383.6,17.44,3.02,3.89,2.19,39.32,13.61,7.56,615.38,386.62,99.64,12.31,24982688,1432881172002.1704,13.988,1.3799602209790578,1.6617492593712762
|
|
9
|
+
Austria,7.41,7.45,2.51,17.71,62.66,61.47,3.44,1.71,-7.12,-7.12,10.82,1.68,0.74,74.98,63.18,24.76,1.46,8840521,454872626780.0053,41.703,2.0816965919733974,0.8359055151181553
|
|
10
|
+
Azerbaijan,7.41,6.3,0.47,14.28,67.56,31.31,1.19,0.71,-1.91,-1.92,1.32,1.5,1.15,80.26,32.02,7.9,4.11,9939771,47112941176.47059,44.32,0.6248844097086277,1.4734001523808629
|
|
11
|
+
Bahrain,0.05,0.27,1.77,23.9,32.74,30.19,3.87,0.56,0.0,0.0,2.17,0.09,0.0,48.95,30.75,3.85,12.28,1569440,37652500000.0,10.712999999999994,-3.163570440824415,5.034177813106887
|
|
12
|
+
Bangladesh,88.53,9.82,1.68,38.87,85.84,81.97,3.97,0.8,21.78,21.74,17.72,6.01,3.56,198.97,82.76,12.01,20.64,161376713,274038973437.27548,63.368,6.733288194060734,3.18911971165231
|
|
13
|
+
Belarus,20.46,4.94,0.44,33.16,58.45,57.09,2.73,2.22,-21.46,-21.51,4.74,2.69,2.39,88.14,59.31,11.86,6.5,9483499,60031262269.33648,21.405,3.309792106647407,0.43270187102989033
|
|
14
|
+
Belgium,9.4,22.41,34.94,22.47,92.89,91.18,5.35,2.29,0.16,0.16,19.22,2.92,1.78,108.75,93.47,25.31,1.11,11427054,543410654016.6017,1.9989999999999952,1.3256499336505243,0.49600300346817217
|
|
15
|
+
Benin,5.58,0.13,0.1,0.17,9.86,7.21,1.7,0.7,10.74,10.71,0.12,2.69,0.05,17.38,7.91,6.75,0.25,11485035,14250987026.053297,52.688,3.81878334277161,3.8913321777948062
|
|
16
|
+
Bhutan,0.53,0.05,0.01,0.0,1.46,1.02,0.4,0.36,-1.31,-1.32,0.37,0.44,0.0,2.47,1.38,0.6,0.08,754396,2446866404.9305816,59.105,1.848487752398583,2.974001213739715
|
|
17
|
+
Bolivia,27.25,1.78,0.24,5.92,24.82,21.22,1.83,1.49,69.34,67.38,2.38,1.06,0.41,56.87,22.71,10.55,2.97,11353140,40287647930.53545,30.575,2.752163601629192,1.9200612402652462
|
|
18
|
+
Bosnia and Herzegovina,2.57,0.82,0.02,15.16,23.0,22.22,0.5,0.32,-1.73,-1.74,2.39,0.2,0.11,27.19,22.54,3.74,1.12,3323929,20183510561.25528,51.755,4.601625193347843,-0.05922305757831518
|
|
19
|
+
Botswana,5.15,0.11,0.04,4.48,10.4,8.07,0.33,0.14,41.33,41.33,0.77,1.62,0.05,16.12,8.21,2.66,0.25,2254067,18663265549.019608,30.554000000000002,2.2080421708636777,3.2774341936014038
|
|
20
|
+
Brazil,496.1,20.38,16.74,88.44,437.33,408.78,28.99,18.93,387.94,384.31,86.98,41.18,18.78,1032.64,427.71,191.66,70.22,209469320,1916947014067.5461,13.430999999999997,0.9889600326235808,1.084634853442427
|
|
21
|
+
Bulgaria,5.26,1.02,1.02,24.19,41.53,39.89,2.6,1.24,-33.81,-33.81,4.79,1.09,0.46,53.33,41.13,9.44,3.94,7025037,66230155099.577545,24.992000000000004,3.8395521186878767,-0.2691020823533362
|
|
22
|
+
Burkina Faso,23.01,0.3,0.09,0.83,5.46,4.15,1.26,0.12,24.1,24.1,0.83,1.31,0.0,30.85,4.27,2.19,1.13,19751466,16059910870.623903,70.642,3.7147214083749276,4.984051438299049
|
|
23
|
+
Burundi,3.33,0.02,0.02,0.07,1.3,0.56,0.46,0.04,3.48,3.48,0.0,0.75,0.0,5.52,0.59,0.46,0.42,11175379,3036937141.2706223,86.968,-1.5575434549572975,5.70023172321884
|
|
24
|
+
Cambodia,21.31,0.61,0.36,3.3,14.15,10.55,1.45,0.61,31.69,29.01,0.72,3.75,0.15,37.46,11.16,5.77,0.56,16249795,24571753583.50398,76.612,5.879385838528066,3.2502244279030084
|
|
25
|
+
Cameroon,12.74,0.44,0.05,2.64,12.88,7.61,59.49,1.01,34.28,33.76,0.24,5.32,0.08,89.05,8.62,2.87,3.94,25216261,38694156862.9922,43.626,1.3792780815302166,3.6769294630276126
|
|
26
|
+
Canada,58.95,75.68,4.12,209.54,626.07,567.65,21.64,6.75,38.51,35.27,69.17,31.87,18.74,724.93,574.4,192.11,18.28,37065178,1721853332869.631,18.589,0.9928518822292176,1.4875059869397684
|
|
27
|
+
Central African Republic,18.52,0.06,0.12,0.0,34.1,0.33,0.04,0.0,31.39,13.98,0.02,33.83,0.06,55.68,0.33,0.19,3.03,4666375,2220979144.5201836,58.636,2.2246754513949156,2.4517904935471817
|
|
28
|
+
Chad,70.07,0.09,0.06,0.2,7.57,1.02,0.78,0.08,24.37,23.33,0.0,1.25,0.52,80.68,1.07,0.16,2.26,15477727,11239167048.49162,76.941,-0.6749209200265653,3.899007628212179
|
|
29
|
+
Chile,10.65,6.58,2.45,35.01,89.94,85.73,4.03,0.88,-57.82,-57.86,14.32,4.57,1.48,109.59,86.62,28.33,4.98,18729166,297571693064.2119,12.436000000000007,2.281121034925235,1.4756074992344486
|
|
30
|
+
China,672.87,542.13,63.82,5214.2,10318.51,9531.46,1166.29,782.0,-649.43,-650.1,2667.43,284.08,187.44,12355.24,10313.46,917.02,197.57,1392730000,13894817549380.291,40.848,6.264209640402086,2.491628201405876
|
|
31
|
+
Colombia,63.02,5.09,5.03,18.56,91.75,74.17,12.22,5.32,83.85,82.97,15.21,6.9,4.88,184.1,79.49,29.34,17.11,49661056,334198214706.20874,19.221999999999994,1.0128560422886608,1.9360866028941663
|
|
32
|
+
Comoros,0.28,0.05,0.01,0.07,0.3,0.26,0.01,0.0,0.06,0.06,0.0,0.13,0.09,0.59,0.26,0.05,0.01,832322,1178530633.815469,71.035,1.1402613685999654,2.866282823906572
|
|
33
|
+
Costa Rica,3.99,0.31,0.66,0.14,8.17,7.64,1.57,0.62,-7.27,-7.3,1.1,0.75,0.21,15.81,8.26,5.88,2.08,4999443,62335931464.49788,20.66,1.0459787191145438,1.9827661908802068
|
|
34
|
+
Croatia,2.79,2.08,0.61,3.88,16.08,15.29,1.82,1.29,-4.34,-4.34,2.37,1.25,0.66,22.55,16.58,6.3,1.86,4087843,61375222347.0256,43.053,3.730298166245589,-0.40058769769130514
|
|
35
|
+
Cuba,10.67,0.67,1.73,10.66,26.86,24.4,1.17,0.58,-3.04,-3.05,8.47,3.34,2.79,41.86,24.97,1.79,3.16,11338146,100050000000.0,22.962999999999994,2.2584814606491506,0.06814335288235905
|
|
36
|
+
Cyprus,0.42,0.39,1.8,3.27,6.39,6.31,1.24,0.92,-0.25,-0.25,0.56,0.19,0.1,8.6,7.23,1.99,0.55,1189262,25309818138.875767,33.19,3.964773250405301,0.7696816266129434
|
|
37
|
+
Czech Republic,6.69,10.72,1.22,57.63,106.48,100.75,4.97,1.73,-5.82,-5.82,12.44,3.1,1.29,122.84,102.48,18.67,4.69,10629928,248950103352.13702,26.208,2.854108113309678,0.49310339330087255
|
|
38
|
+
Denmark,10.22,2.77,4.89,11.5,32.96,32.19,1.82,1.19,0.86,0.86,3.67,2.06,1.43,45.87,33.38,12.66,0.88,5793636,356879499797.8963,12.126000000000005,1.670273713719311,0.6290886027040454
|
|
39
|
+
Djibouti,0.71,0.08,0.34,0.05,0.38,0.35,0.19,0.14,0.0,0.0,0.03,0.09,0.05,1.48,0.49,0.15,0.2,958923,3012820409.6331306,22.223,6.731900604188141,1.7238949946309423
|
|
40
|
+
Dominican Republic,9.22,1.56,1.7,11.14,23.91,23.2,3.26,1.92,-1.56,-1.56,3.12,0.8,0.21,39.06,25.12,7.17,2.68,10627147,85555378042.81964,18.926000000000002,5.834537487554982,2.0667779417792165
|
|
41
|
+
Ecuador,12.39,3.74,3.02,7.44,38.2,37.32,3.06,2.21,26.16,26.15,2.36,5.04,4.2,65.68,39.53,18.49,12.03,17084359,107562008000.0,36.179,-0.4834290779221675,2.0025360428472863
|
|
42
|
+
El Salvador,2.43,0.64,0.56,0.89,7.08,6.42,0.74,0.39,1.09,1.08,1.41,0.66,0.0,12.35,6.81,3.48,2.11,6420740,26020850000.0,27.977000000000004,1.8921381204524295,1.5532788566611708
|
|
43
|
+
Equatorial Guinea,0.02,0.21,0.19,0.85,18.69,6.67,0.32,0.0,3.83,3.83,3.89,0.14,0.08,19.27,6.67,0.93,0.23,1308966,13097012189.399487,27.857,-9.600231963279398,4.344626080428362
|
|
44
|
+
Estonia,1.84,0.43,1.14,11.82,16.0,15.7,0.52,0.31,1.95,1.95,0.66,0.61,0.32,18.61,16.0,2.46,0.25,1321977,30616184212.15923,31.12,3.992898207756724,0.5849634902107796
|
|
45
|
+
Eswatini,0.98,0.03,0.01,0.04,1.46,1.09,0.09,0.0,-0.12,-0.13,0.27,0.32,0.04,3.12,1.09,0.71,0.59,1136274,4665424249.061563,76.201,1.3385904778228053,1.748036706282358
|
|
46
|
+
Ethiopia,112.45,0.5,2.32,0.0,51.01,13.08,3.88,3.2,32.44,31.71,4.55,39.08,1.16,172.23,16.28,6.87,4.9,109224410,84269348327.34543,79.237,4.053940151165804,4.8258860336819245
|
|
47
|
+
Fiji,0.37,0.12,0.48,0.4,2.15,1.81,0.17,0.09,-2.54,-2.54,0.29,0.36,0.01,2.82,1.9,0.99,0.13,883490,5581393120.628532,43.752,3.1040947314841816,1.5883764850091096
|
|
48
|
+
Finland,5.92,1.96,3.35,20.91,44.61,43.76,2.07,0.6,6.94,6.94,7.58,2.62,1.8,54.49,44.36,11.51,1.88,5515525,275849574507.6923,14.617999999999995,1.1775430633930881,0.19942296826627376
|
|
49
|
+
France,73.83,64.42,23.31,61.75,310.38,303.48,24.35,6.48,-61.98,-61.98,40.08,17.4,11.8,423.35,309.96,125.42,14.78,67101930,2786502569559.7725,19.555999999999997,1.5138745507297529,0.6031717555384669
|
|
50
|
+
Gabon,0.51,0.21,0.53,1.61,4.83,4.52,1.39,0.09,6.5,6.46,0.5,0.14,0.01,7.46,4.61,0.21,0.73,2119275,16862282413.877844,10.63,-1.7486002392898286,3.045328536996663
|
|
51
|
+
Georgia,2.13,2.16,0.32,1.01,9.77,8.77,1.8,0.69,0.0,0.0,1.79,0.15,0.05,16.9,9.46,3.76,3.2,3726549,17599700090.762005,41.368,4.883854929374735,0.6472306470922372
|
|
52
|
+
Germany,58.3,120.82,34.9,310.35,713.82,696.13,25.34,13.41,-29.48,-29.48,99.33,17.52,7.33,806.09,709.54,158.3,8.63,82905782,3961831911429.222,22.688000000000002,0.9641147157641825,0.3665151559733051
|
|
53
|
+
Ghana,9.73,1.03,0.63,2.94,28.85,15.08,2.28,1.03,-24.89,-24.93,2.31,7.88,0.39,44.5,16.11,8.06,3.64,29767108,65315955122.80766,43.94,3.896614300514372,3.3645122846316906
|
|
54
|
+
Greece,7.88,4.65,10.3,33.86,63.09,61.6,9.19,3.69,1.39,1.39,5.08,1.49,0.84,84.75,65.29,17.17,4.59,10732882,212146107548.99612,20.941999999999993,1.7652298999962568,0.2204969535175588
|
|
55
|
+
Guatemala,10.15,0.98,1.62,5.42,21.51,16.86,1.8,1.36,3.29,3.27,1.95,4.65,0.0,35.4,18.21,8.51,1.94,16346950,73208583758.91052,48.946,1.681706931282335,2.3356472332831184
|
|
56
|
+
Guinea,19.4,0.06,0.09,1.05,6.06,3.12,1.34,0.0,12.28,12.23,0.68,2.94,0.0,28.89,3.12,1.33,2.09,12414292,11857030336.527449,63.86,3.3875152178949577,3.7979088447477647
|
|
57
|
+
Guinea-Bissau,1.97,0.03,0.04,0.03,0.56,0.32,0.16,0.0,1.64,1.49,0.0,0.4,0.15,2.8,0.31,0.11,0.11,1874304,1504630120.992751,56.64,-1.2105516934202427,3.455229979580616
|
|
58
|
+
Guyana,2.25,0.11,0.06,0.93,2.54,2.44,0.09,0.0,14.09,14.08,0.62,0.1,0.0,5.04,2.44,0.78,0.16,779007,4787635821.461159,73.394,3.9329918668643984,0.7438471063911951
|
|
59
|
+
Haiti,4.46,0.27,0.07,0.86,3.61,3.21,0.39,0.12,0.63,0.63,0.62,0.4,0.0,9.93,3.33,1.46,1.47,11123183,15965670198.454798,44.722,0.38074393925235483,2.9744500197514716
|
|
60
|
+
Honduras,7.14,0.63,0.39,3.0,10.41,9.12,1.92,0.66,5.74,5.52,1.13,1.53,0.25,22.4,9.77,4.1,2.92,9587523,24067778953.842033,42.904,2.1281635729176003,2.7925491293765083
|
|
61
|
+
Hungary,7.79,9.98,0.82,13.69,47.32,45.6,2.54,0.78,1.89,1.89,6.81,2.54,1.54,60.92,46.39,13.58,3.26,9775564,160431092908.6455,28.649,5.533427038221575,0.2790859015532988
|
|
62
|
+
India,718.7,118.84,18.53,1241.34,2424.58,2309.22,148.54,125.3,-28.36,-34.27,571.38,133.28,70.9,3374.99,2434.52,305.33,83.17,1352642283,2701111782774.5703,65.97,5.433077451008742,2.309469965982689
|
|
63
|
+
Indonesia,200.24,25.12,5.77,243.36,598.17,552.09,37.34,31.03,734.28,686.44,114.44,31.31,5.95,969.58,583.11,154.01,133.84,267670549,1042271531011.9897,44.675,3.987824860890754,2.3456069739215746
|
|
64
|
+
Iraq,7.39,9.1,2.88,99.55,186.56,183.1,10.43,5.05,0.5,0.5,11.01,1.84,0.0,215.69,188.14,33.65,11.32,38433604,212271807144.36694,29.527,-3.4779254992216835,2.595539511896303
|
|
65
|
+
Ireland,25.35,8.06,3.7,10.57,35.86,35.27,2.98,1.84,-2.79,-2.79,4.15,1.16,0.62,65.09,37.11,11.87,0.91,4867316,385967106117.0993,36.83,7.1803060663523155,1.592515679772696
|
|
66
|
+
Israel,1.6,0.67,4.38,35.65,63.25,59.7,14.64,2.26,0.08,0.08,4.2,1.31,1.04,87.83,61.97,18.04,8.34,8882800,370455651179.95795,7.581999999999994,1.504795492142648,2.015384410585949
|
|
67
|
+
Italy,31.97,63.58,20.23,113.38,329.13,317.14,21.51,7.71,-12.81,-12.82,32.26,15.08,7.72,399.6,324.85,100.2,16.99,60421760,2091117091124.097,29.561999999999998,1.1337731709509313,0.2281978514684041
|
|
68
|
+
Jamaica,0.56,0.37,1.59,2.55,8.28,8.19,0.63,0.32,0.18,0.18,2.92,0.13,0.04,10.02,8.51,2.31,0.54,2934853,15730793852.791348,44.326,1.4037090799496212,1.0114321164721374
|
|
69
|
+
Japan,21.56,106.11,36.25,561.86,1090.42,1080.72,67.97,25.43,-32.05,-32.07,191.68,23.92,16.51,1186.77,1106.15,204.56,6.8,126529100,4954806619995.188,8.384,0.5267389077514508,-0.11421870991359138
|
|
70
|
+
Jordan,1.19,2.02,1.25,9.53,23.47,22.99,5.58,1.71,0.0,0.0,1.62,1.04,0.81,35.81,24.7,9.01,5.57,9965322,42932112676.05634,9.021,0.09819170272623978,2.0728111262727706
|
|
71
|
+
Kazakhstan,25.44,36.84,1.9,120.81,238.08,216.9,5.11,3.55,-2.98,-2.98,36.78,4.65,2.18,274.22,220.45,17.41,5.58,18276452,179339994859.38443,42.572,2.7405363796910507,1.4748558194270363
|
|
72
|
+
Kenya,44.7,1.23,2.3,1.9,28.46,15.94,4.32,2.47,-7.62,-7.62,3.19,12.84,0.33,78.83,18.4,9.29,1.35,51392570,87778582964.13878,72.97,3.8950656715609995,4.052318246053089
|
|
73
|
+
Kuwait,0.52,0.93,5.92,60.38,91.93,88.06,18.09,1.4,0.0,0.0,10.62,0.33,0.0,112.97,89.46,15.87,2.44,4137314,138182400493.58508,0.0,-0.7412471863719787,1.9824371108237457
|
|
74
|
+
Latvia,2.72,0.84,0.58,1.96,7.6,7.19,0.68,0.44,-2.78,-2.78,0.71,0.73,0.44,11.66,7.63,3.24,0.67,1927174,34399206589.8596,31.858000000000004,4.837970041965505,-0.6807342065001911
|
|
75
|
+
Lebanon,0.8,0.68,0.84,15.34,25.48,25.36,5.0,2.35,-0.08,-0.08,1.16,0.18,0.07,34.35,27.71,8.11,3.07,6859408,54961275741.558876,11.406999999999996,-2.498812241650384,0.7706489923357422
|
|
76
|
+
Lesotho,1.35,0.14,0.0,0.0,4.1,2.56,0.14,0.0,0.0,0.0,1.74,1.53,0.0,5.85,2.57,0.68,0.26,2108327,2514146887.9166384,71.84700000000001,-2.0099969435486145,2.313618130008744
|
|
77
|
+
Liberia,0.5,0.0,0.04,0.3,8.19,1.23,0.38,0.09,13.46,13.44,0.1,6.99,0.03,9.2,1.32,0.8,0.13,4818976,3264000000.0,48.849,-1.2298234883922134,3.344079731206284
|
|
78
|
+
Libya,2.97,1.18,1.05,22.66,93.59,58.46,4.82,0.48,0.0,0.0,5.03,0.9,0.0,103.04,58.94,16.77,1.67,6678565,52607888717.948715,19.897999999999996,13.44608674092187,1.8322747604724243
|
|
79
|
+
Lithuania,4.92,1.14,1.02,2.49,11.77,11.14,1.24,0.45,-0.63,-0.63,1.23,0.56,0.23,18.84,11.59,6.05,0.91,2801543,53696648755.434715,32.321,4.933348071965753,-0.7130948442115954
|
|
80
|
+
Luxembourg,0.65,1.62,1.84,0.24,9.06,8.95,0.43,0.37,-0.28,-0.28,0.96,0.13,0.05,10.22,9.32,6.07,0.08,607950,70885325883.09409,9.019000000000005,1.141053796011974,2.208365157023664
|
|
81
|
+
Madagascar,22.67,0.12,0.17,1.26,5.93,3.27,1.06,0.09,10.72,10.12,0.49,2.75,0.1,30.57,3.37,1.31,0.91,26262313,13614412550.87222,62.809,0.48150500684866415,4.484717061457117
|
|
82
|
+
Malawi,7.46,0.01,0.02,0.15,9.36,1.37,1.07,0.2,8.51,8.14,0.16,7.82,0.07,18.32,1.57,0.98,0.44,18143215,9712994564.915964,83.063,1.698212498134339,3.967125323742132
|
|
83
|
+
Malaysia,14.14,3.38,9.1,125.36,252.03,230.02,19.88,9.6,81.44,79.96,35.47,6.26,2.99,306.67,239.62,60.83,20.62,31528033,358715057123.7392,23.964,3.3630114014793833,2.129608478697478
|
|
84
|
+
Maldives,0.0,0.06,0.29,0.68,1.94,1.91,0.3,0.0,0.0,0.0,0.05,0.03,0.0,2.38,1.91,1.12,0.14,515704,5299773143.696234,60.192,4.080881365425725,4.896018120320995
|
|
85
|
+
Mali,34.23,0.06,0.19,2.31,7.89,5.62,1.01,0.0,0.0,0.0,0.25,2.47,0.19,43.74,5.62,2.81,0.61,19077755,17070866299.094511,57.644,1.642559835145562,4.87638854409818
|
|
86
|
+
Mauritania,9.45,0.22,0.05,0.51,4.44,3.99,0.03,0.0,-1.08,-1.08,1.11,0.49,0.26,14.08,4.0,1.9,0.16,4403312,7050987978.120627,46.328,-0.6845285754445314,4.372691702731293
|
|
87
|
+
Mauritius,0.14,0.2,2.82,2.47,4.19,4.14,0.49,0.0,-0.03,-0.03,0.32,0.06,0.01,6.74,4.13,1.14,1.92,1265303,14181930162.41607,59.207,3.7030945968554505,-0.06313938519094787
|
|
88
|
+
Mexico,96.83,21.61,15.67,193.16,495.77,452.79,40.53,19.35,15.38,14.45,66.72,26.05,10.39,679.88,472.14,156.58,46.76,126190782,1222348807283.1956,19.843999999999994,1.0503115707814175,1.4876130006620385
|
|
89
|
+
Moldova,1.71,1.2,0.17,3.26,8.9,7.96,0.74,0.63,0.11,0.11,1.08,0.53,0.32,13.18,8.59,2.1,1.83,2708214,11456728401.306902,57.371,6.109432567795679,-1.5494951606372456
|
|
90
|
+
Mongolia,28.89,1.69,0.12,13.56,23.04,21.13,0.45,0.19,3.1,3.1,1.96,2.35,1.76,52.62,21.32,2.17,0.25,3170214,13108769495.747211,31.555,5.3377684916864325,1.9157823790390687
|
|
91
|
+
Montenegro,0.41,0.05,0.07,1.5,2.82,2.52,0.29,0.0,0.03,0.03,0.2,0.13,0.01,3.8,2.52,0.76,0.28,622227,5506767831.837506,33.187,5.1025206153302065,0.48079334151798353
|
|
92
|
+
Morocco,15.35,7.24,2.77,22.47,65.84,58.9,8.3,7.78,-1.94,-1.94,8.08,6.64,2.85,94.29,66.68,18.26,4.81,36029089,118096227400.09161,37.547,1.8446169855227197,2.127247447901996
|
|
93
|
+
Mozambique,18.1,0.23,0.03,1.27,11.36,5.91,1.58,0.73,75.03,52.83,0.85,2.65,0.01,35.04,6.64,3.56,4.0,29496009,14845870050.70925,64.012,0.4733402000481277,4.405751497741547
|
|
94
|
+
Myanmar,78.38,1.45,0.23,9.76,35.12,31.53,1.0,0.99,111.97,104.41,8.52,9.03,5.66,119.65,32.52,6.13,5.15,53708318,68697759361.23097,69.42099999999999,6.102907198014563,1.4524521811566689
|
|
95
|
+
Namibia,6.41,0.01,0.12,0.03,4.33,3.88,0.67,0.37,10.56,10.56,0.31,1.88,1.44,11.93,4.25,2.1,0.53,2448300,13681065175.486061,49.968,-0.778285244729318,3.9573284375217224
|
|
96
|
+
Nepal,25.74,1.52,0.41,0.0,23.61,11.19,0.92,0.84,3.33,2.95,3.41,13.32,0.9,51.24,12.03,5.36,0.98,28095712,33111525182.713257,80.26,5.8487108283598275,3.729630943742973
|
|
97
|
+
Netherlands,18.57,23.91,47.17,63.63,153.68,150.87,3.5,0.3,1.36,1.36,25.88,8.88,6.63,178.64,151.17,30.83,2.88,17231624,913597086062.5995,8.51,1.7649372641622278,1.036375039121553
|
|
98
|
+
New Zealand,42.3,1.45,4.89,6.36,32.96,31.76,2.18,0.44,-10.61,-10.61,6.28,1.79,1.41,81.33,32.21,16.02,3.89,4900600,212225726657.86444,13.462000000000003,1.3735436466591153,1.8744788997060904
|
|
99
|
+
Nicaragua,11.14,0.62,0.05,1.44,5.98,4.94,0.89,0.27,19.59,19.51,0.62,1.09,0.05,19.07,5.21,2.22,1.06,6465502,13025208219.768518,41.478,-4.569271327070126,1.6371445959415345
|
|
100
|
+
Niger,30.47,0.08,0.15,0.57,7.25,2.27,0.68,0.02,1.24,1.24,0.24,4.42,0.0,45.05,2.29,1.37,6.66,22442831,12846952856.845798,83.575,3.2040106265661876,4.274416048245062
|
|
101
|
+
Nigeria,76.19,1.91,3.11,26.91,197.18,122.15,23.98,8.52,46.08,45.99,7.46,35.72,0.54,311.45,130.67,67.47,14.1,195874685,397190484464.3077,49.656,-0.6797247077684858,4.238852264616853
|
|
102
|
+
Norway,5.13,1.37,2.31,15.02,38.11,36.58,3.0,0.77,-18.92,-18.92,6.17,1.64,0.95,47.34,37.35,12.53,1.09,5311916,436999692591.45404,17.751999999999995,0.45355083146829145,1.1195328116205598
|
|
103
|
+
Oman,1.75,15.05,8.64,25.3,75.07,71.66,4.4,1.71,0.02,0.02,13.72,2.69,2.47,82.3,73.37,12.24,1.09,4829476,79788768968.94902,15.460999999999999,-2.498232232135507,4.609969828963864
|
|
104
|
+
Pakistan,186.22,20.82,2.76,59.76,210.75,194.23,25.03,14.14,7.0,7.0,55.66,3.88,0.87,431.22,208.37,56.98,9.23,212228288,314567541558.33887,63.334,3.6810344617775854,2.6703400093137106
|
|
105
|
+
Panama,3.54,0.62,16.46,1.95,9.94,9.28,2.03,0.85,4.4,4.4,1.86,0.69,0.04,18.01,10.14,4.81,2.5,4176868,64928300000.0,32.291,1.8593357375531667,2.2019829969957834
|
|
106
|
+
Papua New Guinea,4.77,0.17,0.25,2.89,13.31,7.46,0.27,0.0,41.12,41.0,1.87,0.95,0.39,22.97,7.46,2.13,4.63,8606324,24109509852.740246,86.831,-2.229167922574007,2.4848090646439625
|
|
107
|
+
Paraguay,30.03,0.23,0.2,0.0,9.46,8.07,1.96,0.35,46.12,45.97,0.22,1.39,0.0,49.17,8.42,7.62,7.72,6956069,40225448340.632164,38.415,1.8836318237444942,1.7517103781678527
|
|
108
|
+
Peru,26.17,4.06,3.71,13.44,53.49,50.3,5.23,3.98,89.9,89.79,8.12,1.02,0.25,96.28,54.28,24.18,11.39,31989265,222574697255.52243,22.093000000000004,2.19794844938977,1.9585886214278914
|
|
109
|
+
Philippines,61.37,10.03,5.13,70.44,138.51,132.36,18.68,9.88,2.48,2.46,15.39,6.48,0.65,232.34,142.24,35.64,13.77,106651394,346842094174.51306,53.093,4.867308729356253,1.8767911992321327
|
|
110
|
+
Poland,32.16,42.68,3.85,157.46,331.78,305.75,15.68,7.0,-32.91,-32.91,31.26,17.12,10.87,389.65,312.74,63.48,10.03,37974750,587408980271.7101,39.942,5.35391559355611,-0.07842803523454586
|
|
111
|
+
Portugal,7.02,2.85,6.68,20.83,48.17,47.25,5.28,2.53,0.32,0.29,5.54,2.06,1.2,66.82,49.78,16.82,6.35,10283822,242194788533.53748,34.789,3.0141242574460705,0.7008054474884151
|
|
112
|
+
Qatar,0.33,0.42,9.12,53.65,95.38,88.08,2.98,2.1,0.0,0.0,21.2,4.37,0.0,99.83,90.17,11.73,1.14,2781682,183334953813.20877,0.8649999999999949,-0.8379140384379156,2.1262522866070754
|
|
113
|
+
Romania,15.59,9.03,0.42,29.81,82.35,71.57,5.38,3.31,-22.88,-22.88,12.52,3.5,2.11,109.01,74.88,18.11,5.69,19473970,241457403085.0416,46.002,5.090111106706985,-0.47260826977732284
|
|
114
|
+
Saudi Arabia,6.31,5.08,21.94,225.44,507.0,491.73,96.75,22.87,0.0,0.0,125.12,1.97,0.0,638.12,514.6,136.02,28.06,33702757,786521831573.3334,16.156000000000006,0.6057233356995511,2.0661932033053785
|
|
115
|
+
Senegal,11.01,0.52,0.63,3.93,11.57,8.08,3.34,1.78,4.37,4.33,1.14,3.46,0.0,29.99,9.86,2.49,4.07,15854324,23116699808.172344,52.808,3.295346151175508,3.744291879276486
|
|
116
|
+
Serbia,5.71,2.21,0.47,31.92,49.39,44.79,1.77,0.75,-0.09,-0.09,3.93,2.67,0.39,62.6,45.54,6.35,5.73,6982604,50640650221.46222,43.908,5.067594881402897,-0.2785722370209686
|
|
117
|
+
Sierra Leone,4.01,0.03,0.02,0.07,1.6,1.03,0.16,0.0,3.38,3.35,0.11,0.91,0.33,7.19,1.02,0.49,1.42,7650149,4085114794.2232366,57.945,1.2593398142301595,3.1379569444987903
|
|
118
|
+
Singapore,0.02,0.6,181.27,25.82,48.78,47.36,14.62,0.0,0.03,0.03,14.01,0.43,0.01,66.64,47.36,6.92,3.22,5638676,375981539145.9075,0.0,3.0124774434973745,0.4697042987141205
|
|
119
|
+
Slovenia,1.62,0.88,0.82,4.82,14.23,13.64,0.8,0.41,0.35,0.34,1.94,0.6,0.28,17.17,14.05,5.72,0.51,2073894,54135187443.81362,45.459,4.006705136351513,0.8551894557056994
|
|
120
|
+
Solomon Islands,0.07,0.0,0.04,0.09,0.38,0.37,0.13,0.0,45.41,45.41,0.02,0.03,0.02,0.94,0.37,0.23,0.35,652856,1574599182.6469665,76.251,1.2653035907678571,4.580006314214862
|
|
121
|
+
Somalia,22.16,0.12,0.24,0.33,2.09,0.69,0.28,0.0,17.35,17.35,0.08,1.4,0.0,26.97,0.69,0.15,2.44,15008225,4720727283.20485,55.029,-0.07942652530796579,4.130040198114454
|
|
122
|
+
South Africa,30.03,33.84,12.4,281.88,436.1,428.05,22.48,5.21,7.07,6.55,46.76,13.93,8.64,513.44,433.25,56.86,24.84,57792520,368288939768.32227,33.645,-0.5780515870031735,2.127672998352435
|
|
123
|
+
Spain,41.36,25.46,36.22,89.94,254.03,248.89,18.45,9.45,-13.88,-13.89,33.62,11.33,7.56,326.94,258.34,92.31,13.1,46797754,1421459363680.6702,19.679000000000002,1.9824019789486158,0.7384811672713235
|
|
124
|
+
Sri Lanka,5.82,1.03,3.53,8.14,23.63,20.61,2.37,1.03,1.91,1.91,0.85,3.66,0.64,35.24,21.63,9.95,3.42,21670000,87954272082.10678,81.524,2.1949597721197023,1.5475740945304033
|
|
125
|
+
Sudan,75.59,0.59,0.74,5.32,27.8,18.64,2.52,1.56,21.01,21.0,1.48,9.58,0.44,109.63,20.2,10.8,3.72,41801532,34522586970.00181,65.358,0.38697262899086127,3.180531960014197
|
|
126
|
+
Suriname,0.67,0.1,0.14,0.95,2.86,2.02,0.16,0.06,9.36,9.36,0.06,0.34,0.3,3.78,2.08,0.61,0.1,575987,3996247906.1976547,33.94,3.948688807284512,0.9856641993539303
|
|
127
|
+
Sweden,7.24,1.52,8.58,8.61,35.59,34.52,2.48,1.48,-16.31,-16.32,6.91,1.99,0.98,46.35,36.0,16.49,1.04,10175214,555455371487.0894,12.569000000000003,0.772577449000039,1.4881506748737874
|
|
128
|
+
Switzerland,5.54,11.34,5.53,3.08,36.26,35.72,3.42,1.76,-2.24,-2.24,4.92,0.87,0.56,46.02,37.48,15.82,0.79,8514329,735889205256.251,26.203000000000003,2.2573614166740015,0.785417652319277
|
|
129
|
+
Tajikistan,6.41,1.06,0.09,1.49,7.01,6.8,0.91,0.53,-0.13,-0.13,1.91,1.18,1.11,15.21,7.33,1.23,0.87,9100847,7765014424.337792,72.866,4.992100906478527,3.015336048005832
|
|
130
|
+
Tanzania,58.23,0.41,0.43,2.31,39.04,10.34,2.04,1.24,70.19,64.1,1.93,25.76,0.08,105.38,11.58,5.62,6.06,56313444,57003713748.231606,66.22399999999999,2.3550834882442473,5.143296284249471
|
|
131
|
+
Thailand,68.82,6.73,18.86,105.57,263.51,241.12,71.9,16.74,14.27,13.04,43.94,18.58,8.91,416.95,257.86,75.88,12.72,69428454,506611070188.3615,50.051,3.8614822888173705,1.8262912995411704
|
|
132
|
+
Timor-Leste,0.94,0.0,0.01,0.43,5.17,0.64,0.02,0.0,0.47,0.46,0.0,0.13,0.12,6.19,0.64,0.09,0.06,1267975,1559894900.0,69.422,-2.9825308173926715,3.1723988467051627
|
|
133
|
+
Togo,2.95,0.11,0.2,0.21,2.85,1.44,1.66,0.81,0.82,0.81,0.11,1.41,0.0,8.42,2.26,1.01,0.95,7889095,7112200725.002317,58.298,2.4397420894579795,3.7492409451330486
|
|
134
|
+
Trinidad and Tobago,0.3,0.38,1.9,12.36,17.59,17.48,3.77,0.28,0.13,0.13,1.95,0.11,0.0,22.9,17.76,2.5,1.24,1389841,23679919654.98907,46.816,-0.35017181747487314,0.377348197295108
|
|
135
|
+
Tunisia,4.57,2.88,0.91,9.47,28.25,26.39,5.14,3.59,-3.79,-3.79,4.96,2.37,1.3,41.1,29.98,7.63,3.14,11565203,39770478673.16483,31.055,1.493922626131706,1.5863033204077344
|
|
136
|
+
Turkey,49.59,50.1,14.27,159.04,388.32,374.13,47.91,38.84,-28.65,-28.65,72.12,15.43,9.5,502.52,412.97,83.37,16.71,82340090,778377023568.884,24.857,1.4289148773244449,2.1635137191198903
|
|
137
|
+
Turkmenistan,9.22,17.31,1.45,25.91,112.41,70.4,2.06,1.33,0.0,0.0,2.35,12.03,11.79,125.08,71.73,11.77,1.39,5850902,40765428571.42857,48.407,4.507687030552717,2.462852155116084
|
|
138
|
+
Uganda,29.52,0.24,0.32,0.22,22.43,5.17,0.99,0.97,15.84,15.82,1.11,17.44,0.18,54.87,6.13,3.42,1.93,42729032,32912338571.34034,76.226,2.2806414874147407,6.186430301998961
|
|
139
|
+
Ukraine,30.19,26.11,0.92,90.95,220.88,181.83,8.98,3.54,-12.08,-12.19,35.62,5.68,3.94,274.51,185.37,25.21,14.46,44622518,130901858421.72018,30.647999999999996,3.932894948858177,-0.3134650384761512
|
|
140
|
+
United Arab Emirates,2.04,0.8,74.87,73.3,232.37,194.71,8.45,5.59,0.0,0.0,80.77,6.67,0.0,263.24,200.3,37.67,20.37,9630966,422215043594.28186,13.477999999999994,-0.3205903176318685,1.8211232183411918
|
|
141
|
+
United Kingdom,50.7,87.01,42.8,106.64,364.85,354.39,19.14,4.41,-10.96,-10.96,31.96,11.16,6.1,452.08,358.8,120.66,17.39,66460344,2857316524862.6064,16.602000000000004,0.6409266656618513,0.9121610824417962
|
|
142
|
+
United States,385.25,550.68,144.85,2103.17,5271.21,4940.08,233.91,41.21,-229.27,-231.73,458.79,94.75,46.25,6023.62,4981.3,1762.24,133.24,326838199,20611860934000.0,17.744,2.455679198846042,0.767437430461766
|
|
143
|
+
Uruguay,26.34,0.48,0.78,0.76,6.54,6.22,1.27,0.29,-1.77,-1.77,0.87,0.79,0.48,36.16,6.52,3.63,2.01,3449290,64515038268.13733,4.665999999999997,0.1095580058536143,0.46590701199294593
|
|
144
|
+
Uzbekistan,35.99,26.93,0.0,52.95,185.79,108.68,6.69,3.41,-3.37,-3.37,11.39,1.82,1.66,235.51,112.09,15.02,7.04,32956100,50392607758.23237,49.522,3.6306700144970563,1.59445249215377
|
|
145
|
+
Vietnam,70.99,15.79,4.3,109.13,248.02,227.57,37.13,30.29,-12.09,-12.5,63.91,4.21,1.38,376.53,257.86,36.32,20.4,95545959,245213686369.1568,64.081,6.016398379303681,2.979418773239718
|
|
146
|
+
World,5817.65,2882.54,1311.6,15590.95,37224.95,33746.74,2902.68,1502.0,1387.56,1192.81,6158.32,1452.02,623.71,47552.14,35248.74,8257.73,1606.86,7592475615,86343514250201.53,44.728289909979516,1.9068178576488748,1.9323097577732824
|
|
147
|
+
Zambia,24.46,0.13,0.12,2.72,10.98,6.69,1.64,1.05,52.56,32.74,1.51,4.58,0.3,40.67,7.74,2.03,3.6,17351714,26311637646.653854,56.479,1.0479212196250671,4.172817413078456
|
|
148
|
+
Zimbabwe,11.15,0.23,0.22,6.6,15.79,11.68,1.85,0.58,87.38,87.16,1.19,4.19,0.79,31.38,12.27,2.87,2.59,14438812,19523622341.613316,67.791,2.0477001806153936,1.3234971488431562
|
srdkit/diagnostics.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
r"""Diagnostics, sensitivity, power and simplification of SRD analyses.
|
|
2
|
+
|
|
3
|
+
An SRD ranking of solutions is only as trustworthy as its stability under the
|
|
4
|
+
choices and perturbations it depends on. The functions of this module answer the
|
|
5
|
+
questions a careful analysis asks after the SRD values are computed:
|
|
6
|
+
|
|
7
|
+
* :func:`object_influence` — which objects drive the result? (leave-one-object-out
|
|
8
|
+
change of every SRD value and of the order of the solutions);
|
|
9
|
+
* :func:`reference_sensitivity` — does the conclusion depend on the reference
|
|
10
|
+
rule? (SRD under several references, Kendall's coefficient of concordance *W*
|
|
11
|
+
of the resulting orders);
|
|
12
|
+
* :func:`tie_sensitivity` — does the tie convention matter?
|
|
13
|
+
* :func:`noise_robustness` — how stable is the order under measurement noise?
|
|
14
|
+
(probability that the best solution stays best, rank stability of each solution);
|
|
15
|
+
* :func:`power_analysis` — how many objects are needed to recognise a solution of a
|
|
16
|
+
given quality as better than random? (simulation with a Gaussian-copula model);
|
|
17
|
+
* :func:`reduce_criteria` — which criteria can be dropped without changing the
|
|
18
|
+
fused reference? (greedy backward elimination by SRD; simplification of
|
|
19
|
+
the decision problem in the spirit of P-PFA).
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import numpy as np
|
|
25
|
+
import pandas as pd
|
|
26
|
+
from scipy import stats
|
|
27
|
+
|
|
28
|
+
from ._utils import as_frame, as_rng, srd_max
|
|
29
|
+
from .core import srd
|
|
30
|
+
from .distribution import null_distribution
|
|
31
|
+
from .ranking import rank_vector
|
|
32
|
+
from .reference import make_reference
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def kendall_w(orders: pd.DataFrame) -> float:
|
|
36
|
+
"""Kendall's coefficient of concordance of rankings in the columns of ``orders`` (rows = items)."""
|
|
37
|
+
R = orders.apply(lambda c: pd.Series(rank_vector(c.to_numpy()), index=c.index)).to_numpy()
|
|
38
|
+
n, m = R.shape
|
|
39
|
+
if n < 2 or m < 2:
|
|
40
|
+
return 1.0
|
|
41
|
+
S = ((R.sum(axis=1) - m * (n + 1) / 2) ** 2).sum()
|
|
42
|
+
return float(12 * S / (m ** 2 * (n ** 3 - n)))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def object_influence(X, reference="mean", ties: str = "average") -> dict:
|
|
46
|
+
"""Leave-one-object-out influence on the normalized SRD values.
|
|
47
|
+
|
|
48
|
+
Returns ``delta`` (objects x solutions: change of normalized SRD when the
|
|
49
|
+
object is removed), ``order_changes`` (number of pairs of solutions whose order
|
|
50
|
+
flips) and ``best_changes`` (whether the best solution changes).
|
|
51
|
+
"""
|
|
52
|
+
df = as_frame(X)
|
|
53
|
+
full = srd(df, reference=reference, ties=ties)
|
|
54
|
+
base = full.normalized
|
|
55
|
+
order0 = full.order
|
|
56
|
+
rows, flips, best = {}, {}, {}
|
|
57
|
+
for obj in df.index:
|
|
58
|
+
sub = df.drop(index=obj)
|
|
59
|
+
ref = reference if isinstance(reference, str) or callable(reference) else np.asarray(reference)[df.index != obj]
|
|
60
|
+
r = srd(sub, reference=ref, ties=ties)
|
|
61
|
+
rows[obj] = r.normalized - base
|
|
62
|
+
pos0 = {c: i for i, c in enumerate(order0)}
|
|
63
|
+
pos1 = {c: i for i, c in enumerate(r.order)}
|
|
64
|
+
cols = list(base.index)
|
|
65
|
+
flips[obj] = sum(1 for i in range(len(cols)) for j in range(i + 1, len(cols))
|
|
66
|
+
if (pos0[cols[i]] - pos0[cols[j]]) * (pos1[cols[i]] - pos1[cols[j]]) < 0)
|
|
67
|
+
best[obj] = r.best != full.best
|
|
68
|
+
return {"delta": pd.DataFrame(rows).T, "order_changes": pd.Series(flips, name="order_changes"),
|
|
69
|
+
"best_changes": pd.Series(best, name="best_changes")}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def reference_sensitivity(X, references=("mean", "median", "min", "max", "borda", "consensus"), ties: str = "average") -> dict:
|
|
73
|
+
"""SRD of every solution under several references and the concordance of the resulting orders."""
|
|
74
|
+
df = as_frame(X)
|
|
75
|
+
tab = {}
|
|
76
|
+
for r in references:
|
|
77
|
+
try:
|
|
78
|
+
tab[str(r)] = srd(df, reference=r, ties=ties).normalized
|
|
79
|
+
except ValueError:
|
|
80
|
+
continue
|
|
81
|
+
T = pd.DataFrame(tab)
|
|
82
|
+
return {"srd": T, "kendall_w": kendall_w(T), "best": T.idxmin()}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def tie_sensitivity(X, reference="mean", methods=("average", "min", "max", "dense")) -> pd.DataFrame:
|
|
86
|
+
"""Normalized SRD under different tie conventions."""
|
|
87
|
+
df = as_frame(X)
|
|
88
|
+
return pd.DataFrame({m: srd(df, reference=reference, ties=m).normalized for m in methods})
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def noise_robustness(X, reference="mean", noise: float = 0.05, n_rep: int = 500, random_state=None, ties: str = "average") -> dict:
|
|
92
|
+
"""Stability of the SRD order under Gaussian noise added to every value.
|
|
93
|
+
|
|
94
|
+
``noise`` is the standard deviation as a fraction of each column's standard
|
|
95
|
+
deviation. Returns the probability that each solution is the best, the mean
|
|
96
|
+
and standard deviation of its rank among the solutions, and the distribution of
|
|
97
|
+
its normalized SRD.
|
|
98
|
+
"""
|
|
99
|
+
df = as_frame(X)
|
|
100
|
+
rng = as_rng(random_state)
|
|
101
|
+
sd = df.std(ddof=1).replace(0, 1).to_numpy()
|
|
102
|
+
cols = list(df.columns)
|
|
103
|
+
ranks, vals, best = [], [], []
|
|
104
|
+
ext_ref = None if (isinstance(reference, str) or callable(reference)) else np.asarray(reference, float)
|
|
105
|
+
for _ in range(n_rep):
|
|
106
|
+
noisy = df + rng.normal(0, 1, df.shape) * noise * sd
|
|
107
|
+
ref = reference if ext_ref is None else ext_ref
|
|
108
|
+
r = srd(noisy, reference=ref, ties=ties)
|
|
109
|
+
v = r.normalized.to_numpy()
|
|
110
|
+
vals.append(v)
|
|
111
|
+
ranks.append(stats.rankdata(v))
|
|
112
|
+
best.append(r.best)
|
|
113
|
+
V = pd.DataFrame(vals, columns=cols)
|
|
114
|
+
Rk = pd.DataFrame(ranks, columns=cols)
|
|
115
|
+
pbest = pd.Series(best).value_counts(normalize=True).reindex(cols, fill_value=0.0)
|
|
116
|
+
out = pd.DataFrame({"p_best": pbest, "mean_rank": Rk.mean(), "sd_rank": Rk.std(ddof=1), "srd_mean": V.mean(),
|
|
117
|
+
"srd_sd": V.std(ddof=1)})
|
|
118
|
+
return {"table": out.sort_values("mean_rank"), "srd_samples": V}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def power_analysis(n_values=(5, 7, 10, 15, 20, 30, 50), rho_values=(0.2, 0.4, 0.6, 0.8), alpha: float = 0.05,
|
|
122
|
+
n_sim: int = 2000, random_state=None) -> pd.DataFrame:
|
|
123
|
+
r"""Probability that a solution is found better than random (below XX1) by CRRN.
|
|
124
|
+
|
|
125
|
+
The solution and the reference are standard bivariate normal scores with
|
|
126
|
+
correlation :math:`\rho`; for every :math:`n` the exact critical value of SRD
|
|
127
|
+
is used. Returns a table (rows = n, columns = rho) of rejection rates.
|
|
128
|
+
"""
|
|
129
|
+
rng = as_rng(random_state)
|
|
130
|
+
out = {}
|
|
131
|
+
for rho in rho_values:
|
|
132
|
+
col = {}
|
|
133
|
+
for n in n_values:
|
|
134
|
+
d = null_distribution(n=int(n))
|
|
135
|
+
crit = d.ppf(alpha)
|
|
136
|
+
if d.cdf(crit) > alpha: # largest value with P(D <= v) <= alpha
|
|
137
|
+
below = d.values[np.cumsum(d.probs) <= alpha + 1e-12]
|
|
138
|
+
crit = below.max() if below.size else -1
|
|
139
|
+
y = rng.standard_normal((n_sim, int(n)))
|
|
140
|
+
x = rho * y + np.sqrt(1 - rho ** 2) * rng.standard_normal((n_sim, int(n)))
|
|
141
|
+
ry = np.argsort(np.argsort(y, axis=1), axis=1)
|
|
142
|
+
rx = np.argsort(np.argsort(x, axis=1), axis=1)
|
|
143
|
+
D = np.abs(rx - ry).sum(axis=1)
|
|
144
|
+
col[int(n)] = float(np.mean(D <= crit))
|
|
145
|
+
out[rho] = col
|
|
146
|
+
tab = pd.DataFrame(out)
|
|
147
|
+
tab.index.name = "n"
|
|
148
|
+
tab.columns.name = "rho"
|
|
149
|
+
return tab
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def required_n(rho: float, power: float = 0.8, alpha: float = 0.05, n_max: int = 200, n_sim: int = 2000, random_state=0) -> int:
|
|
153
|
+
"""Smallest number of objects for which a solution with correlation ``rho`` is detected with the given power."""
|
|
154
|
+
for n in range(4, n_max + 1):
|
|
155
|
+
p = power_analysis((n,), (rho,), alpha, n_sim, random_state).iloc[0, 0]
|
|
156
|
+
if p >= power:
|
|
157
|
+
return n
|
|
158
|
+
return -1
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def reduce_criteria(X, reference="mean", tolerance: float = 0.05, min_keep: int = 2, ties: str = "average") -> dict:
|
|
162
|
+
"""Greedy backward elimination of criteria that do not change the fused reference.
|
|
163
|
+
|
|
164
|
+
In every step the criterion whose removal changes the ranking of the reference
|
|
165
|
+
least (normalized SRD between the reduced and the full reference) is dropped,
|
|
166
|
+
as long as that change stays below ``tolerance``. Returns the kept criteria and
|
|
167
|
+
the elimination path.
|
|
168
|
+
"""
|
|
169
|
+
df = as_frame(X)
|
|
170
|
+
full = rank_vector(make_reference(df, reference, ties=ties), ties=ties)
|
|
171
|
+
n = df.shape[0]
|
|
172
|
+
keep = list(df.columns)
|
|
173
|
+
path = []
|
|
174
|
+
while len(keep) > min_keep:
|
|
175
|
+
best_c, best_d = None, np.inf
|
|
176
|
+
for c in keep:
|
|
177
|
+
rest = [k for k in keep if k != c]
|
|
178
|
+
q = rank_vector(make_reference(df[rest], reference, ties=ties), ties=ties)
|
|
179
|
+
d = np.abs(q - full).sum() / srd_max(n)
|
|
180
|
+
if d < best_d:
|
|
181
|
+
best_c, best_d = c, d
|
|
182
|
+
if best_d > tolerance:
|
|
183
|
+
break
|
|
184
|
+
keep.remove(best_c)
|
|
185
|
+
path.append({"removed": best_c, "reference_change": best_d, "remaining": len(keep)})
|
|
186
|
+
return {"kept": keep, "path": pd.DataFrame(path)}
|
srdkit/distances.py
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
r"""Rank distances: the generalized SRD family.
|
|
2
|
+
|
|
3
|
+
SRD is the :math:`L_1` (footrule) distance between a rank vector and the
|
|
4
|
+
reference ranks. Replacing the footrule by another distance between rankings
|
|
5
|
+
gives a family of SRD-like measures, all usable with :func:`srdkit.srd`
|
|
6
|
+
(``distance=...``), :func:`srdkit.pairwise_srd` and :func:`srdkit.crrn`:
|
|
7
|
+
|
|
8
|
+
============== =========================================================== ============================
|
|
9
|
+
name definition maximum
|
|
10
|
+
============== =========================================================== ============================
|
|
11
|
+
``footrule`` :math:`\sum_i |r_i-q_i|` (SRD) :math:`\lfloor n^2/2\rfloor`
|
|
12
|
+
``spearman`` :math:`\sum_i (r_i-q_i)^2` :math:`n(n^2-1)/3`
|
|
13
|
+
``kendall`` discordant pairs (+1/2 per pair tied in one ranking only) :math:`n(n-1)/2`
|
|
14
|
+
``cayley`` minimum number of transpositions, :math:`n-\#\text{cycles}` :math:`n-1`
|
|
15
|
+
``ulam`` :math:`n-` longest increasing subsequence :math:`n-1`
|
|
16
|
+
``hamming`` number of objects with different ranks :math:`n`
|
|
17
|
+
``chebyshev`` :math:`\max_i |r_i-q_i|` :math:`n-1`
|
|
18
|
+
============== =========================================================== ============================
|
|
19
|
+
|
|
20
|
+
Comparisons of SRD with Kendall's and Spearman's coefficients are reported by
|
|
21
|
+
Héberger and Škrbić (2012) and Sipos et al. (2018); the latter also combine the
|
|
22
|
+
Cayley distance with the footrule. Top-*k* lists follow Fagin, Kumar and Sivakumar
|
|
23
|
+
(2003); position- and element-weighted footrules follow Kumar and Vassilvitskii
|
|
24
|
+
(2010) and are in :mod:`srdkit.weighted`.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import bisect
|
|
30
|
+
|
|
31
|
+
import numpy as np
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def footrule(r, q) -> float:
|
|
35
|
+
"""Spearman's footrule (SRD): sum of absolute rank differences.
|
|
36
|
+
|
|
37
|
+
>>> footrule([1, 2, 3, 4], [4, 3, 2, 1])
|
|
38
|
+
8.0
|
|
39
|
+
"""
|
|
40
|
+
return float(np.abs(np.asarray(r, float) - np.asarray(q, float)).sum())
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def spearman(r, q) -> float:
|
|
44
|
+
"""Sum of squared rank differences (the numerator of Spearman's rho)."""
|
|
45
|
+
return float(((np.asarray(r, float) - np.asarray(q, float)) ** 2).sum())
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def kendall(r, q) -> float:
|
|
49
|
+
"""Kendall (Kemeny) distance: discordant pairs, and 1/2 for every pair tied in exactly one ranking.
|
|
50
|
+
|
|
51
|
+
>>> kendall([1, 2, 3], [3, 2, 1])
|
|
52
|
+
3.0
|
|
53
|
+
>>> kendall([1, 2, 3], [1.5, 1.5, 3])
|
|
54
|
+
0.5
|
|
55
|
+
"""
|
|
56
|
+
r = np.asarray(r, float)
|
|
57
|
+
q = np.asarray(q, float)
|
|
58
|
+
dr = np.sign(r[:, None] - r[None, :])
|
|
59
|
+
dq = np.sign(q[:, None] - q[None, :])
|
|
60
|
+
iu = np.triu_indices(r.size, 1)
|
|
61
|
+
a, b = dr[iu], dq[iu]
|
|
62
|
+
disc = np.sum(a * b < 0)
|
|
63
|
+
half = np.sum((a == 0) ^ (b == 0))
|
|
64
|
+
return float(disc + 0.5 * half)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _perm(r, q) -> np.ndarray:
|
|
68
|
+
"""Permutation sigma with sigma[position of i in q] = position of i in r (ties broken by order)."""
|
|
69
|
+
r = np.asarray(r, float)
|
|
70
|
+
q = np.asarray(q, float)
|
|
71
|
+
pr = np.argsort(np.argsort(r, kind="stable"), kind="stable")
|
|
72
|
+
pq = np.argsort(np.argsort(q, kind="stable"), kind="stable")
|
|
73
|
+
sigma = np.empty(r.size, dtype=int)
|
|
74
|
+
sigma[pq] = pr
|
|
75
|
+
return sigma
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def cayley(r, q) -> float:
|
|
79
|
+
"""Cayley distance: minimum number of transpositions turning one ranking into the other.
|
|
80
|
+
|
|
81
|
+
>>> cayley([1, 2, 3, 4], [2, 1, 4, 3])
|
|
82
|
+
2.0
|
|
83
|
+
"""
|
|
84
|
+
s = _perm(r, q)
|
|
85
|
+
seen = np.zeros(s.size, bool)
|
|
86
|
+
cycles = 0
|
|
87
|
+
for i in range(s.size):
|
|
88
|
+
if not seen[i]:
|
|
89
|
+
cycles += 1
|
|
90
|
+
j = i
|
|
91
|
+
while not seen[j]:
|
|
92
|
+
seen[j] = True
|
|
93
|
+
j = s[j]
|
|
94
|
+
return float(s.size - cycles)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def ulam(r, q) -> float:
|
|
98
|
+
"""Ulam distance: ``n`` minus the length of the longest increasing subsequence.
|
|
99
|
+
|
|
100
|
+
>>> ulam([1, 2, 3, 4], [2, 3, 4, 1])
|
|
101
|
+
1.0
|
|
102
|
+
"""
|
|
103
|
+
s = _perm(r, q)
|
|
104
|
+
tails: list[int] = []
|
|
105
|
+
for v in s:
|
|
106
|
+
k = bisect.bisect_left(tails, v)
|
|
107
|
+
if k == len(tails):
|
|
108
|
+
tails.append(v)
|
|
109
|
+
else:
|
|
110
|
+
tails[k] = v
|
|
111
|
+
return float(s.size - len(tails))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def hamming(r, q) -> float:
|
|
115
|
+
"""Number of objects whose ranks differ."""
|
|
116
|
+
return float(np.sum(~np.isclose(np.asarray(r, float), np.asarray(q, float))))
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def chebyshev(r, q) -> float:
|
|
120
|
+
"""Largest absolute rank difference."""
|
|
121
|
+
return float(np.abs(np.asarray(r, float) - np.asarray(q, float)).max())
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def lp_distance(p: float):
|
|
125
|
+
"""The :math:`L_p` rank distance ``(sum |r - q|^p)^(1/p)`` as a function."""
|
|
126
|
+
|
|
127
|
+
def f(r, q):
|
|
128
|
+
return float((np.abs(np.asarray(r, float) - np.asarray(q, float)) ** p).sum() ** (1.0 / p))
|
|
129
|
+
|
|
130
|
+
f.__name__ = f"l{p:g}"
|
|
131
|
+
return f
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def topk_footrule(r, q, k: int, location: float | None = None, ascending: bool = True) -> float:
|
|
135
|
+
r"""Footrule between two top-*k* lists with location parameter :math:`\ell` (Fagin et al., 2003).
|
|
136
|
+
|
|
137
|
+
Objects outside the top *k* of a ranking get the rank :math:`\ell` (default
|
|
138
|
+
:math:`k+1`). With ``ascending=True`` the top of a ranking is rank 1.
|
|
139
|
+
"""
|
|
140
|
+
r = np.asarray(r, float)
|
|
141
|
+
q = np.asarray(q, float)
|
|
142
|
+
n = r.size
|
|
143
|
+
if not ascending:
|
|
144
|
+
r, q = n + 1 - r, n + 1 - q
|
|
145
|
+
ell = k + 1 if location is None else location
|
|
146
|
+
rr = np.where(r <= k, r, ell)
|
|
147
|
+
qq = np.where(q <= k, q, ell)
|
|
148
|
+
return float(np.abs(rr - qq).sum())
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def cayley_footrule(r, q, lam: float = 0.5) -> float:
|
|
152
|
+
"""Convex combination of the normalized footrule and Cayley distances (between 0 and 1).
|
|
153
|
+
|
|
154
|
+
A simple member of the family of combined footrule-Cayley measures proposed by
|
|
155
|
+
Sipos et al. (2018); ``lam = 1`` gives the normalized footrule, ``lam = 0`` the
|
|
156
|
+
normalized Cayley distance.
|
|
157
|
+
"""
|
|
158
|
+
n = len(r)
|
|
159
|
+
f = footrule(r, q) / max((n * n) // 2, 1)
|
|
160
|
+
c = cayley(r, q) / max(n - 1, 1)
|
|
161
|
+
return float(lam * f + (1 - lam) * c)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
DISTANCES = {"footrule": footrule, "srd": footrule, "l1": footrule, "spearman": spearman, "kendall": kendall,
|
|
165
|
+
"cayley": cayley, "ulam": ulam, "hamming": hamming, "chebyshev": chebyshev,
|
|
166
|
+
"cayley_footrule": cayley_footrule}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def get_distance(distance):
|
|
170
|
+
"""Return ``(function, name)`` for a distance name or callable."""
|
|
171
|
+
if callable(distance):
|
|
172
|
+
return distance, getattr(distance, "__name__", "custom")
|
|
173
|
+
key = str(distance).lower()
|
|
174
|
+
if key not in DISTANCES:
|
|
175
|
+
raise ValueError(f"unknown distance {distance!r}; available: {sorted(DISTANCES)}")
|
|
176
|
+
name = "footrule" if key in ("srd", "l1") else key
|
|
177
|
+
return DISTANCES[key], name
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def distance_max(name: str, n: int) -> float:
|
|
181
|
+
"""Largest value of a rank distance for ``n`` objects without ties (normalizing constant)."""
|
|
182
|
+
n = int(n)
|
|
183
|
+
table = {"footrule": (n * n) // 2, "spearman": n * (n * n - 1) / 3, "kendall": n * (n - 1) / 2,
|
|
184
|
+
"cayley": n - 1, "ulam": n - 1, "hamming": n, "chebyshev": n - 1, "cayley_footrule": 1.0}
|
|
185
|
+
if name in table:
|
|
186
|
+
return float(table[name]) if table[name] else 1.0
|
|
187
|
+
if name.startswith("l") and name[1:].replace(".", "").isdigit():
|
|
188
|
+
p = float(name[1:])
|
|
189
|
+
k = np.arange(1, n + 1)
|
|
190
|
+
return float((np.abs(k - k[::-1]) ** p).sum() ** (1 / p))
|
|
191
|
+
# custom callable: the reversed ranking is the natural extreme
|
|
192
|
+
return float(n * n // 2) if n > 1 else 1.0
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def distance_matrix(R, distance="footrule") -> np.ndarray:
|
|
196
|
+
"""Pairwise distance matrix between the columns of a rank matrix."""
|
|
197
|
+
f, _ = get_distance(distance)
|
|
198
|
+
R = np.asarray(R, float)
|
|
199
|
+
m = R.shape[1]
|
|
200
|
+
D = np.zeros((m, m))
|
|
201
|
+
for a in range(m):
|
|
202
|
+
for b in range(a + 1, m):
|
|
203
|
+
D[a, b] = D[b, a] = f(R[:, a], R[:, b])
|
|
204
|
+
return D
|