-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path散点图提升计算.py
125 lines (90 loc) · 9.19 KB
/
散点图提升计算.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 8 19:30:40 2019
@author: lenovo
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
#ours = [0.10024496123659585, 0.09354314313935586, 0.07407808081193545, 0.08919712807191389, 0.10413952052243239, 0.113505231508731, 0.08153949613570159, 0.1044618424014144, 0.12443843489715589, 0.15497076074235985, 0.1086634599692958, 0.09467884915877307, 0.15455938528558694, 0.24319607767593315, 0.23506213294938702, 0.15293916997841203, 0.17739542410837603, 0.24449711936870688, 0.26178895437622396, 0.23677268838571958, 0.3133531328090492, 0.22401339718666707, 0.2854629367209235, 0.35804499248222976, 0.4172276623314521, 0.37263737660794094, 0.5214294602751846, 0.4202032807479467]
#greedy = [0.12240443473185927, 0.10766173677020616, 0.13150386599936545, 0.1327995714369105, 0.14597495811500197, 0.1638217534958707, 0.16382926857460067, 0.14060840777023523, 0.17115427302800804, 0.16063207583772776, 0.16648446798960967, 0.17536096745502314, 0.21009987683108636, 0.20054415051900015, 0.20742271569094445, 0.2191758883277369, 0.24810432123124423, 0.26879624941249664, 0.24705958568505237, 0.2937189184483314, 0.31133284770977826, 0.3542021132474643, 0.35993107845342487, 0.4324831483222513, 0.4133678737913164, 0.4646442125926673, 0.5201087002424643, 0.5019294548896294]
#SLSQP = [0.10035438921980393, 0.11493885343659774, 0.09472707501058339, 0.12318993050975395, 0.09513239866033366, 0.1231647001560773, 0.1336497330754065, 0.15639100387275856, 0.12480254264195911, 0.16605425195904067, 0.14161592672040074, 0.19761129076813383, 0.17950690897301783, 0.2823773957942145, 0.36026278002574863, 0.252658128417247, 0.3049320130751769, 0.2869863719580523, 0.42706316005974154, 0.36635228380268475, 0.4055453261716603, 0.42144973465072183, 0.43672797804102137, 0.4145279384810011, 0.44643013042565227, 0.48669902637160944, 0.6600504097031041, 0.4623571733384382]
#ours = [0.04169161128299922, 0.03320371425168285, 0.09436282901013186, 0.08161419298421738, 0.053684906191328464, 0.11516547742070485, 0.06580764562334504, 0.07225244100643688, 0.06499096375997857, 0.11973315926372971, 0.06035669461064326, 0.057615177912121326, 0.07779657989574015, 0.0768038711464363, 0.07401188273343538, 0.09667443671091422, 0.07884895167400298, 0.1339285502623831, 0.12081728602887384, 0.13572411916707122, 0.18470627273699988, 0.11865626370134512, 0.29076025649973075, 0.16443241652359672, 0.16003710213107977, 0.12240043256901986, 0.17314224788252977, 0.252368356560792, 0.2934017391849454, 0.17085990905429155, 0.11177884192505397, 0.2513899665706227, 0.2464680788622693, 0.3282271350965035, 0.24580462067820413, 0.17624452821611156, 0.41407201492423373, 0.24856835249773349]
#greedy = [0.054009626389345734, 0.1192346871444846, 0.13471164165563632, 0.1243032205414241, 0.1756136441947413, 0.19563707026216517, 0.15842920708270078, 0.19341876539023561, 0.10946533203607549, 0.13938144810463582, 0.1367756400705873, 0.12354055707206542, 0.2214623801272389, 0.1333725115490742, 0.10146957216191477, 0.18713388244503174, 0.22533863699280157, 0.23766155326764832, 0.23249612181567278, 0.14767870746569187, 0.3221809506562572, 0.16393580556532222, 0.3977740083320679, 0.34537972727610694, 0.23472937481366749, 0.21209557023545952, 0.43170508942703895, 0.3699395260681242, 0.4869075702898413, 0.19215774642499764, 0.3287547150981947, 0.2202278217068585, 0.28204225847354975, 0.3624732524723895, 0.3229063810530195, 0.2912710328248892, 0.42157213086310197, 0.3050637352360973]
#SLSQP = [0.06952076049945813, 0.041720004094942545, 0.05409020359665723, 0.09876641477315058, 0.22027830708553658, 0.09616701555664256, 0.07333654249485479, 0.12383918940051, 0.10608692304605713, 0.08260216578453419, 0.07745852900231927, 0.127712966934398, 0.11724805789870427, 0.06671167627679, 0.08089215917357324, 0.15750542182481206, 0.0870928281646653, 0.1709274577806848, 0.20673898915459005, 0.16436163813134388, 0.3285201868923452, 0.11744384731810179, 0.31323554530553216, 0.22185944050322504, 0.13995998930937467, 0.15965626404255281, 0.3594785764697133, 0.30570909556754533, 0.32967399953431487, 0.22006357994793047, 0.22137311106157923, 0.15007667044802964, 0.2652109178576656, 0.39348669415859716, 0.3307438316142932, 0.24461013775010382, 0.46614560590339654, 0.36185767699079385]
#ours = [0.0708120720763593, 0.0699684078215062, 0.0879910310359461, 0.12212216457777965, 0.10668022495297451, 0.14919226538396382, 0.19846097250846242, 0.24450579215398333, 0.2548913107751952, 0.23672620111544954, 0.2790945332145305, 0.4461736648509766, 0.4632798318621548, 0.7188186817360114, 0.7319278103447062, 0.8257550158450275, 0.8534208190107441, 0.8704555365287586, 0.8728621086677952, 0.8872448891672862]
#greedy = [0.15079730402041508, 0.1478196651740949, 0.15784634224708735, 0.1656864722179789, 0.19655352673749912, 0.18142862889948846, 0.19208471145071288, 0.23308163579872448, 0.28303715834830745, 0.3134423165815039, 0.40018702991933763, 0.4380625823443755, 0.503192951237532, 0.6969852681332256, 0.7119786812725465, 0.8066795767722468, 0.8188929349016556, 0.850367818425358, 0.8622333794530418, 0.8797120689007427]
#SLSQP = [0.13224917061777602, 0.10969509777286912, 0.10172033957275864, 0.20233705191188775, 0.21235494505538055, 0.3214900348019043, 0.25409058311677096, 0.28720984141705425, 0.35634988451721483, 0.31533945144637776, 0.38921887184666437, 0.4244573776430511, 0.587952321375666, 0.726094519711277, 0.7278260516243563, 0.7996433261929435, 0.8716078056082063, 0.8426618094991476, 0.8606217507924601, 0.8868187142029432]
#ours = [0.021967797781402554, 0.020922567766596963, 0.030838414144104986, 0.025297625478038, 0.015765497072154223, 0.023023441328102655, 0.026213319073492492, 0.04348281177148512, 0.03732709562489976, 0.06980476851154574, 0.031566294851538425, 0.10542600592028017, 0.06402528566204266, 0.1848931964696335, 0.14145218296047318, 0.14274916957341593, 0.21018353402606996, 0.25722811747520224, 0.3687707080599728, 0.4892859390957988]
#greedy = [0.03596909117312512, 0.04854049393002029, 0.06287771685884394, 0.03232910960421073, 0.026543032854965128, 0.06448830252471156, 0.09679959905535684, 0.08055293217754773, 0.0454937907731813, 0.06594378409171575, 0.07600651345094475, 0.1358139387272717, 0.10598154508909843, 0.17322260105714155, 0.15028947867410414, 0.20544845913603665, 0.2553564903404872, 0.3023456473494287, 0.530958414848703, 0.49871626020754045]
#SLSQP = [0.027409917259274157, 0.019113219633357152, 0.05905637246504443, 0.02459354165668893, 0.0691577002624458, 0.046075999106214974, 0.05273203538291769, 0.03712011583720495, 0.03572977266978045, 0.07056882539745943, 0.07623281511913085, 0.06377904194654674, 0.09269235019869272, 0.19239645167441216, 0.16594898900603075, 0.23766569581113967, 0.19620125592030715, 0.32102292598667354, 0.5013689477210479, 0.5320696522292041]
fname = 'plotData_distribution_zipf_new2.txt'
file=open(fname, 'r')
lines=list(file.readlines())
temp_file=open('temp_file.txt','w')
for line in lines:
new_line=line[1:len(line)-2]
print(new_line,file=temp_file)
temp_file.close()
data=np.loadtxt('temp_file.txt',delimiter=',')
print(fname)
ours = data[0]
greedy = data[1]
SLSQP = data[2]
length = len(ours)
g_part_ave_up = 0
s_part_ave_up = 0
g_max_up = 0
g_min_up = 1
s_max_up = 0
s_min_up = 1
g_ave_up = 0
s_ave_up = 0
for i in range(length//3):
g_part_ave_up += (greedy[i] - ours[i]) / greedy[i]
s_part_ave_up += (SLSQP[i] - ours[i]) / SLSQP[i]
g_part_ave_up /= (length//3)
s_part_ave_up /= (length//3)
print("small,相对于greedy提升:", g_part_ave_up)
print("small,相对于SLSQP提升:", s_part_ave_up)
g_part_ave_up = 0
s_part_ave_up = 0
for i in range(length//3,length//3*2):
g_part_ave_up += (greedy[i] - ours[i]) / greedy[i]
s_part_ave_up += (SLSQP[i] - ours[i]) / SLSQP[i]
g_part_ave_up /= (length//3)
s_part_ave_up /= (length//3)
print("medium,相对于greedy提升:", g_part_ave_up)
print("medium,相对于SLSQP提升:", s_part_ave_up)
g_part_ave_up = 0
s_part_ave_up = 0
for i in range(length//3 * 2, length):
g_part_ave_up += (greedy[i] - ours[i]) / greedy[i]
s_part_ave_up += (SLSQP[i] - ours[i]) / SLSQP[i]
g_part_ave_up /= (length - length//3*2)
s_part_ave_up /= (length - length//3*2)
print("large,相对于greedy提升:", g_part_ave_up)
print("large,相对于SLSQP提升:", s_part_ave_up)
g_part_ave_up = 0
s_part_ave_up = 0
for i in range(length):
g_tmp_up = (greedy[i] - ours[i]) / greedy[i]
s_tmp_up = (SLSQP[i] - ours[i]) / greedy[i]
if(g_tmp_up > g_max_up):
g_max_up = g_tmp_up
if(g_tmp_up < g_min_up):
g_min_up = g_tmp_up
if(s_tmp_up > s_max_up):
s_max_up = s_tmp_up
if(s_tmp_up < s_min_up):
s_min_up = s_tmp_up
g_ave_up += g_tmp_up
s_ave_up += s_tmp_up
g_ave_up /= length
s_ave_up /= length
print("全局,相对于greedy最小提升:",g_min_up)
print("全局,相对于greedy最大提升:",g_max_up)
print("全局,相对于greedy平均提升:",g_ave_up)
print("全局,相对于SLSQP最小提升:",s_min_up)
print("全局,相对于SLSQP最大提升:",s_max_up)
print("全局,相对于SLSQP平均提升:",s_ave_up)