blob: 40d467221e890a3a9dd3d972df45c227f694cee0 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# P-values for the two-sample Kolmogorov-Smirnov distribution:
# D = sup_x |F_m(x) - G_n(x)|
# D+ = sup_x F_m(x) - G_n(x)
# Computed using scipy.stats.kstest using arrays with configured overlap:
# from scipy.stats import kstest
# import random
#
# def ksp(x, size=0):
# """
# Given x representing steps on a 2D path taking the n-th step on x,
# generate y taking the other steps.
# The arrays are used for the KS test:
# x = [2, 3, 6]
# y = [0, 1, 4, 5]
#
# x = [0, 2, 3, 6]
# y = [1, 4, 5]
#
# The optional combined size of x and y can be used to fill y beyond
# the max value in x:
# x = [0, 2, 3, 6], size = 9
# y = [1, 4, 5, 7, 8]
# """
# assert min(x) >= 0
# a = set(x)
# y = [v for v in range(max(size, max(x))) if v not in a]
# x = sorted(list(a))
# (d, p2) = kstest(x, y, method='exact', alternative='two-sided')
# (dp, p1p) = kstest(x, y, method='exact', alternative='greater')
# (dm, p1m) = kstest(x, y, method='exact', alternative='less')
# m, n = len(x), len(y)
# if m > n:
# m, n = n, m
# print(n, m, round(d*n*m), p2, p1p if dp > dm else p1m)
#
# def kspr(n, m, k):
# """
# Output k random samples for the KS statistic for size m+n
# """
# assert m <= n
# x = list(range(m+n))
# while k:
# k = k - 1
# random.shuffle(x)
# ksp(x[0:n], size=m+n)
#
# def kspr2(n, m, k, steps=1):
# """
# Output k random sample for the KS statistic for size m+n
# where steps is the number of random steps away from the most
# extreme d value. With a small k there is not much random
# selection among possible values.
# """
# assert m <= n
# x = list(range(n+steps))
# while k:
# k = k - 1
# random.shuffle(x)
# ksp(x[0:n], size=m+n)
#
# m, n, D*m*n, p(D >= d), p(D+ >= d)
# kspr(100, 40, 20)
40 100 340 0.9773418270040279 0.6329024797499111
40 100 860 0.12677239988246672 0.06339825886035746
40 100 580 0.5473896135904249 0.2794401566979873
40 100 880 0.11154244485514381 0.055778250027573084
40 100 480 0.770492146516542 0.41338818994955673
40 100 460 0.8119415167694873 0.44305520608128046
40 100 700 0.3164264340698098 0.1587740147927427
40 100 900 0.09783730779454616 0.04892267422427221
40 100 640 0.42307844481855844 0.21344392995383454
40 100 680 0.349817735774034 0.17576427607315334
40 100 480 0.770492146516542 0.41338818994955673
40 100 1240 0.006616625176172374 0.0033083126170043243
40 100 500 0.7267073322941818 0.3843233816008394
40 100 780 0.2052795987967731 0.10273149023483952
40 100 420 0.8856659279989376 0.5048023299540044
40 100 480 0.770492146516542 0.41338818994955673
40 100 620 0.46275830805993134 0.23416423523770283
40 100 760 0.22982383866844353 0.1150592615825157
40 100 820 0.16229871881876692 0.08118354558617719
40 100 420 0.8856659279989376 0.5048023299540044
# kspr2(100, 40, 5, steps=30)
100 40 1280 0.0045434627365337 0.00227173137342205
100 40 1380 0.0016788158396986734 0.000839407919897205
100 40 1120 0.018951512042934323 0.009475759289379455
100 40 1100 0.02233981664838027 0.011169915063692467
100 40 1080 0.02625373376387981 0.013126880631872185
# kspr2(100, 40, 5, steps=25)
100 40 1500 0.000456660920000192 0.0002283304600001775
100 40 1500 0.000456660920000192 0.0002283304600001775
100 40 1500 0.000456660920000192 0.0002283304600001775
100 40 1540 0.00028815415241434557 0.00014407707620718067
100 40 1640 8.590792015892992e-05 4.2953960079464965e-05
# kspr2(100, 40, 5, steps=20)
100 40 2020 3.855912283854308e-07 1.9279561419271548e-07
100 40 2000 5.299027236844599e-07 2.6495136184222997e-07
100 40 2080 1.451368666967504e-07 7.25684333483752e-08
100 40 2160 3.730939832822896e-08 1.8654699164114477e-08
100 40 2140 5.271510978784155e-08 2.6357554893920777e-08
# kspr(100, 90, 20)
100 90 660 0.9403465424443764 0.5673160110547633
100 90 1800 0.03830453866332627 0.019152364596527083
100 90 1000 0.5572530591243455 0.28499738340467284
100 90 1600 0.08683950302755603 0.04342261303057448
100 90 1280 0.2630149823414606 0.13178421976099924
100 90 890 0.6981836033061721 0.3666544765572714
100 90 750 0.8640266306725287 0.48568869295379447
100 90 920 0.6600778211517683 0.34362597484673946
100 90 1330 0.2248787518023298 0.11258453521977592
100 90 1120 0.41538876587262696 0.2095295198840798
100 90 970 0.595209186537845 0.3060980999853577
100 90 970 0.595209186537845 0.3060980999853577
100 90 830 0.7740517546485187 0.4162869563189197
100 90 950 0.6212031461485229 0.32090932344109196
100 90 900 0.6854565207494886 0.3588502088357719
100 90 1130 0.4045155234733332 0.20390002705223875
100 90 930 0.6472160884908673 0.336034954438692
100 90 1220 0.31466150497698403 0.15790996062322848
100 90 2170 0.006517639537689413 0.00325881982265406
100 90 1390 0.18483598432221077 0.09248275733380223
# kspr2(100, 90, 5, steps=70)
100 90 2000 0.015330694330104906 0.007665349189785158
100 90 2280 0.0036074485067851053 0.0018037242575994195
100 90 2000 0.015330694330104906 0.007665349189785158
100 90 2340 0.002579705416961608 0.0012898527094708143
100 90 2320 0.0028877356007539663 0.00144386780196359
# kspr2(100, 90, 5, steps=65)
100 90 2600 0.0005435137234678029 0.000271756861734953
100 90 2700 0.00028527869952446285 0.0001426393497622857
100 90 2610 0.0005101662512487007 0.0002550831256251429
100 90 2500 0.0010095208704887539 0.0005047604352605958
# kspr2(100, 90, 5, steps=60)
100 90 3000 3.535335600382311e-05 1.767667800191077e-05
100 90 3760 6.111734406393342e-08 3.055867203196533e-08
100 90 3100 1.673070087351254e-05 8.3653504367559e-06
100 90 3570 3.474759400727338e-07 1.737379700363592e-07
# kspr(100, 100, 20)
100 100 800 0.9084105017744525 0.5286203014039125
100 100 1600 0.1548386665118475 0.07745073909762673
100 100 900 0.8154147124661313 0.44617493329504543
100 100 1800 0.07822115797841851 0.03911245494630259
100 100 1000 0.7020569828664881 0.3691083539077194
100 100 1000 0.7020569828664881 0.3691083539077194
100 100 1300 0.36818778606286096 0.18520368254808692
100 100 800 0.9084105017744525 0.5286203014039125
100 100 1200 0.469506448503778 0.23781836509015705
100 100 1600 0.1548386665118475 0.07745073909762673
100 100 1000 0.7020569828664881 0.3691083539077194
100 100 1000 0.7020569828664881 0.3691083539077194
100 100 700 0.9684099261397212 0.6138816403400273
100 100 1500 0.21117008625127576 0.10569747923911413
100 100 600 0.9942356257694902 0.6987801650679035
100 100 1100 0.5830090612540064 0.2992770437089617
100 100 800 0.9084105017744525 0.5286203014039125
100 100 600 0.9942356257694902 0.6987801650679035
100 100 1000 0.7020569828664881 0.3691083539077194
100 100 800 0.9084105017744525 0.5286203014039125
# kspr2(100, 100, 5, steps=75)
100 100 2900 0.0004117410017938115 0.00020587050089724022
100 100 2500 0.0037294923618311367 0.001864746185927891
100 100 2600 0.002219935934558366 0.0011099679678142208
100 100 2700 0.0012935059781377376 0.0006467529891200971
100 100 3100 0.00012016164291946694 6.008082145973481e-05
# kspr2(100, 100, 5, steps=70)
100 100 3000 0.0002248739317492479 0.00011243696587464657
100 100 3200 6.281176788972264e-05 3.1405883944861374e-05
100 100 3300 3.211428734211389e-05 1.6057143671056943e-05
100 100 3500 7.850159128072286e-06 3.925079564036142e-06
# kspr2(100, 100, 5, steps=65)
100 100 3700 1.7527190839835072e-06 8.763595419917535e-07
100 100 4200 2.749465483696122e-08 1.3747327418480607e-08
# kspr2(100, 100, 5, steps=50)
100 100 5100 3.319419024623016e-12 1.6597095123115084e-12
100 100 5000 1.0024645454361508e-11 5.012322727180755e-12
100 100 5500 3.0406585087050305e-14 1.5203292543525152e-14
# kspr(515, 500, 20)
515 500 8185 0.9493986521608645 0.5815825961416793
515 500 7915 0.9615725209825824 0.601871942028066
515 500 7720 0.9690636734798047 0.6164340097379267
515 500 16515 0.23350385753082842 0.11693559032166966
515 500 14150 0.40736519509165603 0.20544622542022134
515 500 15750 0.28249266048886834 0.14164291536993778
515 500 14365 0.38885041334955517 0.19588222329634966
515 500 8955 0.903603296094672 0.524339532431143
515 500 11925 0.6240870483885734 0.32281246631425675
515 500 12780 0.53645777026934 0.2738050242806958
515 500 16275 0.24813390240790098 0.12430166348195652
515 500 11220 0.697534625783586 0.3666522163820955
515 500 9160 0.8887341900595557 0.5092395404996648
515 500 17940 0.15969123808843258 0.07988534277115025
515 500 21760 0.0493197290292436 0.024660214774062543
515 500 11605 0.6574794674555943 0.34235526509229514
515 500 15625 0.29114337179290417 0.1460196726063174
515 500 20290 0.07961143709393435 0.03980812865846791
515 500 11740 0.6433641257950573 0.3340198635318758
515 500 8285 0.944339176814443 0.574013022376737
# kspr2(515, 500, 5, steps=460)
515 500 37190 4.312475432797974e-05 2.156237716397765e-05
515 500 23725 0.02468528708275912 0.012342665062356865
515 500 21675 0.050750631293065424 0.02537570917296944
515 500 23355 0.028249692522794394 0.014124883326404823
515 500 22965 0.032490717875867006 0.01624542414831844
# kspr2(515, 500, 5, steps=450)
515 500 34880 0.00015657518065977083 7.828759032986811e-05
515 500 26990 0.006851609415818402 0.0034258048291346535
515 500 39945 8.308060387864811e-06 4.154030193930157e-06
515 500 30785 0.0012554915219321185 0.0006277457610908003
515 500 26840 0.007293385130763014 0.003646692721520048
# kspr2(515, 500, 5, steps=400)
515 500 54770 1.511195571110642e-10 7.555977855549027e-11
515 500 53040 6.463156211941191e-10 3.231578105968821e-10
515 500 54650 1.6741114699848586e-10 8.370557349919452e-11
515 500 52575 9.477200035799245e-10 4.738600017896974e-10
515 500 57850 1.0086569364127433e-11 5.04328468206092e-12
# kspr(515, 515, 20)
515 515 14935 0.38807451014746674 0.19548201752017033
515 515 13905 0.479034004163874 0.24297229659389263
515 515 10815 0.7857918829942412 0.4249785344115979
515 515 7725 0.9812801592459972 0.6462745124993984
515 515 9270 0.9119165633386505 0.5333147055834722
515 515 11330 0.7357540649661999 0.3909485959019169
515 515 11330 0.7357540649661999 0.3909485959019169
515 515 12360 0.6313430811283158 0.32700970276632807
515 515 22145 0.055141558408617404 0.02757132855187066
515 515 18540 0.16146324301032314 0.08077314672681853
515 515 13390 0.5281779821581033 0.2693067172881182
515 515 9785 0.8751440285488726 0.49636218852993574
515 515 16995 0.24110048586896543 0.12075921552037354
515 515 11845 0.6838779320846781 0.35824843453465616
515 515 11845 0.6838779320846781 0.35824843453465616
515 515 15450 0.34681483814007347 0.17431974406385833
515 515 13905 0.479034004163874 0.24297229659389263
515 515 12875 0.5791652849910399 0.29733660010790197
515 515 10815 0.7857918829942412 0.4249785344115979
515 515 12875 0.5791652849910399 0.29733660010790197
# kspr2(515, 515, 5, steps=470)
515 515 41200 7.715341729410975e-06 3.857670864705488e-06
515 515 33475 0.0005396263434587486 0.00026981317173342326
515 515 25750 0.015542998382653479 0.007771502515087006
515 515 28325 0.005593644437864241 0.002796822272300457
515 515 24205 0.027379231101175516 0.01368964821727114
# kspr2(515, 515, 5, steps=460)
515 515 31930 0.0011342645522721903 0.0005671322762189362
515 515 29870 0.0028903078353134577 0.0014451539213383023
515 515 33990 0.00041795499923995993 0.00020897749962141217
515 515 33990 0.00041795499923995993 0.00020897749962141217
515 515 28325 0.005593644437864241 0.002796822272300457
# kspr2(515, 515, 5, steps=450)
515 515 42745 2.9641506649539074e-06 1.482075332476954e-06
515 515 35020 0.0002477777699409291 0.00012388888497063505
515 515 34505 0.0003224429461502545 0.00016122147307562554
515 515 37080 8.305069523093185e-05 4.152534761546791e-05
515 515 39655 1.9376317134703097e-05 9.688158567351555e-06
# kspr2(515, 515, 5, steps=440)
515 515 39655 1.9376317134703097e-05 9.688158567351555e-06
515 515 41200 7.715341729410975e-06 3.857670864705488e-06
515 515 40170 1.4311681121416457e-05 7.155840560708231e-06
515 515 42230 4.093676899867059e-06 2.04683844993353e-06
515 515 39140 2.612933882401873e-05 1.3064669412009386e-05
# kspr2(515, 515, 5, steps=400)
515 515 59225 1.161536345492389e-11 5.807681727461947e-12
515 515 61285 1.8302055341507816e-12 9.15102767075391e-13
515 515 61285 1.8302055341507816e-12 9.15102767075391e-13
515 515 59225 1.161536345492389e-11 5.807681727461947e-12
515 515 61800 1.141356522084582e-12 5.706782610422911e-13