|
- import matplotlib
- import matplotlib.pyplot as plt
- import numpy as np
- import os
- from matplotlib.ticker import MultipleLocator, FormatStrFormatter
-
- plt.rc('font', family='Times New Roman')
- matplotlib.rcParams['pdf.fonttype'] = 42
- matplotlib.rcParams['ps.fonttype'] = 42
-
- xticklabels = ['DeepConvSurv', 'DeepCorrSurv', 'GCN', 'DeepGraphSurv', 'HGRNet-attribute', 'HGRNet-pattern']
-
- gbm = [
- [0.5081, 0.5066, 0.4985, 0.5043, 0.4988],
- [0.5271, 0.5188, 0.5184, 0.5223, 0.5198],
- [0.5627, 0.5628, 0.5484, 0.5574, 0.5451],
- [0.6005, 0.5792, 0.6027, 0.5938, 0.5876],
- [0.6117, 0.6144, 0.6225, 0.6311, 0.6427], # attribute
- [0.6207, 0.6217, 0.6306, 0.6419, 0.6473] # pattern
- ]
-
- lusc = [
- [0.5917, 0.5876, 0.5867, 0.5972, 0.6032],
- [0.6202, 0.6212, 0.6243, 0.6251, 0.6238],
- [0.6358, 0.6374, 0.6397, 0.6424, 0.6383],
- [0.6562, 0.6575, 0.6462, 0.6453, 0.6574],
- [0.6607, 0.6701, 0.6724, 0.6659, 0.6715], # attribute
- [0.6551, 0.6621, 0.6664, 0.6621, 0.6581] # pattern
- ]
-
- nlst = [
- [0.5118, 0.5027, 0.5161, 0.4926, 0.5141],
- [0.5283, 0.5326, 0.5253, 0.5253, 0.5217],
- [0.5476, 0.5574, 0.5872, 0.5712, 0.5931],
- [0.6161, 0.6026, 0.6218, 0.6043, 0.6229],
- [0.6313, 0.6253, 0.6463, 0.6642, 0.6572], # attribute
- [0.6213, 0.6223, 0.6313, 0.6445, 0.6392] # pattern
- ]
-
-
- def box_line(gbm=gbm, lusc=lusc, nlst=nlst):
- fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(10, 3))
-
- lusc = axes[0].boxplot(lusc,
- # notch=True,
- vert=True,
- patch_artist=True)
-
- gbm = axes[1].boxplot(gbm,
- # notch=True,
- vert=True,
- patch_artist=True)
-
- nlst = axes[2].boxplot(nlst,
- # notch=True,
- vert=True,
- patch_artist=True)
-
- # colors = ['pink', 'lightblue', 'lightgreen', 'lightyellow', 'purple']
- colors = ['lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue', 'lightblue']
-
- for bplot in (gbm, lusc, nlst):
- for patch, color in zip(bplot['boxes'], colors):
- patch.set_facecolor(color)
-
- x_labels = ['LUSC', 'GBM', 'NLST']
-
- LUSC_range = (0.580, 0.680, 0.02)
- GBM_range = (0.500, 0.670, 0.03)
- NLST_range = (0.480, 0.670, 0.03)
- graph_ranges = [LUSC_range, GBM_range, NLST_range]
-
- for i, ax in enumerate(axes):
- ax.set_yscale('linear')
- ax.grid(linestyle='-.', linewidth=1)
- ax.set_title(x_labels[i])
- ax.set_xticks([y + 1 for y in range(len(gbm))])
- ax.set_xticklabels(xticklabels, rotation=20, ha='right', fontsize=10)
- ylabels = ax.set_ylabel('C-index', fontsize=12)
- ax.set_yticks(np.arange(*graph_ranges[i]))
-
- ax.spines['bottom'].set_linewidth(2)
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- # plt.gcf().subplots_adjust(bottom=0.15)
- plt.tight_layout()
- plt.savefig('board.pdf')
- plt.show()
-
-
- def draw_k_line(k2=False):
- fontsize = 15
- x=[i for i in range(300)]
-
- #BasePath="D:\\code\\toy_example\\time_data"
- BasePath="D:\\code\\up\\all"
- y=[]
- for i in range(6):
- y.append([])
- time=[]
- for i in range(3):
- time.append([])
- for num, info in enumerate(os.listdir(BasePath)):
- Path=os.path.join(BasePath, info)
- # print(Path)
- value=np.load(Path)
- i=num%6
- mvalue=[]
- mvalue.append(np.mean(value['arr_0'], axis=0))
- mvalue.append(np.var(value['arr_0'], axis=0))
- mi=1000
- for j in range(300):
- if mvalue[0][j]!=-1:
- mi=min(mi, mvalue[0][j])
- else: mvalue[0][j]=mi
- print(mvalue[0][:300].shape)
- y[i].append(mvalue[0][:300])
- if (num//6)==0:
- time[i%3].append(np.log10(np.mean(value['arr_1'], axis=0)))
- if (num//6)== 1: time[i%3].append(np.log10(np.mean(value['arr_1'],axis=0)))
- for i in range(6):
- y[i][4],y[i][5]=y[i][5],y[i][4]
- for i in range(6):
- y[i][4],y[i][3]=y[i][3],y[i][4]
-
- if k2:
- # return draw_k_line_v2(x, y1, y11, y2, y22, y3, y33)
- draw_k_line_v3(x, y)
- # draw_times(x, time)
- return
-
-
-
- # def draw_k_line_v2(x, y1, y11, y2, y22, y3, y33):
- # fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(10, 8))
- # axes[0].plot(x, y2, 'gD-', label='LUSC-attribute')
- # axes[0].plot(x, y22, 'gD-', label='LUSC-pattern', markerfacecolor='white')
- # axes[0].plot(x, y2, 'gD-', markersize=8) # attribute
- # axes[0].plot(x, y22, 'gD-', markerfacecolor='white', markersize=8) # pattern
- #
- # axes[1].plot(x, y1, 'ro-', label='GBM-attribute')
- # axes[1].plot(x, y11, 'ro-', label='GBM-pattern', markerfacecolor='white')
- # axes[1].plot(x, y1, 'ro-', markersize=8) # attribute
- # axes[1].plot(x, y11, 'ro-', markerfacecolor='white', markersize=8) # pattern
- #
- # axes[2].plot(x, y3, 'b^-', label='NLST-attribute')
- # axes[2].plot(x, y33, 'b^-', label='NLST-pattern', markerfacecolor='white')
- # axes[2].plot(x, y3, 'b^-', markersize=8) # attribute
- # axes[2].plot(x, y33, 'b^-', markerfacecolor='white', markersize=8) # pattern
- #
- # hlines = [(y2[4], y22[11], 'g'), (y1[9], y11[5], 'r'), (y3[5], y33[9], 'b')]
- #
- # LUSC_range = (0.640, 0.680, 0.005)
- # GBM_range = (0.595, 0.655, 0.010)
- # NLST_range = (0.630, 0.670, 0.005)
- # graph_ranges = [LUSC_range, GBM_range, NLST_range]
- #
- # for i, ax in enumerate(axes):
- # ax.set_yscale('linear')
- # ax.set_yticks(np.arange(*graph_ranges[i]))
- # ax.grid(linestyle='-.', linewidth=1)
- # ax.set_xticks([])
- # # ylabels = ax.set_ylabel('C-index', fontsize=14)
- #
- # ax.hlines(hlines[i][0], 5, 20, colors=hlines[i][2], linestyles="-.", linewidths=2)
- # ax.hlines(hlines[i][1], 5, 20, colors=hlines[i][2], linestyles=":", linewidths=2)
- #
- # ax.legend(fontsize=16, loc=1)
- # for tick in ax.yaxis.get_major_ticks():
- # tick.label.set_fontsize(20)
- #
- # ax.spines['bottom'].set_linewidth(2)
- # ax.spines['left'].set_linewidth(2)
- # ax.spines['right'].set_linewidth(2)
- # ax.spines['top'].set_linewidth(2)
- #
- # # plt.gcf().subplots_adjust(bottom=0.15)
- # plt.xlabel('K parameters', fontsize=20)
- # plt.tight_layout()
- # plt.savefig('k_line_v2.pdf')
- # plt.show()
-
-
- # def draw_k_line_v3(x, y1, y11, y2, y22, y3, y33):
- def draw_k_line_v3(x, y):
- fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(17, 13)) #要画的子图分布设置,设置行列数
-
- # fmt=['.-b', '+-g', 'x-r', '*-y', '<-m', '>-k']
- fmt=['.-b', '.-g', '.-r', '.-y', '.-m', '.-k']
- color="bgrymk"
- lvalue=["ASNG", "Dynamic ASNG", "Dynamic IGO", "IGO", "MDENAS", "Ours MIGO"]
-
- sp_x0=[x for x in range(50)]
- sp_x1=[x for x in range(50,200)]
- for i in range(2):
- for j in range(2):
- for num in range(6): #设置每幅图要画的线,用plot
- id=i*3+j
- axes[i][j].plot(x, y[id][num], fmt[num], label=lvalue[num])
- if j==1 and i==0: axes[i][j].set_ylim(5,15)
- elif j==0: axes[i][j].set_ylim((0,50))
- else: axes[i][j].set_ylim((0,15))
- # if num!=1:
- # axes[i][j].plot(x, y[id][num][0], fmt[num], label=lvalue[num])
- # else:
- # axes[i][j].plot(sp_x0, y[id][num][0], fmt[num], label=lvalue[num])
- # sp_y = [y[id][num][0][49] for i in range(150)]
- # axes[i][j].plot(sp_x1, sp_y, '--g')
-
-
- title=["(N=14,M=8) index_sum", "(N=14,M=8) rastrigin", "(N=20,M=7) index_sum", "(N=20,M=7) rastrigin"]
- for i in range(2):
- for j in range(2):
- ax=axes[i][j]
- ax.set_title(title[i*2+j],fontdict={'fontsize':30, 'family' :'Times New Roman'}) #设置每幅图的标题
- ax.grid(linestyle='-.', linewidth=1) #设置一个网格线,平行于坐标轴
- if(j==0):ax.set_ylabel('L2 distance', fontdict={'family' : 'Times New Roman', 'size': 30}) #设置坐标轴的title
- # if(i):ax.set_xlabel('Epoch', fontdict={'family' : 'Times New Roman', 'size': 30})
- if(i):ax.set_xlabel('Number of function evaluations', fontdict={'family' : 'Times New Roman', 'size': 30})
- ax.tick_params(labelsize=20)
- ax.legend(fontsize=17, loc=1) #设置图例,每条线的图例
- ax.spines['bottom'].set_linewidth(2) #对坐标轴线设置宽度
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- plt.subplots_adjust(wspace=0.15, hspace=0.5) #调整子图之间的间距
- plt.savefig('new_new_new_value.pdf') #保存为pdf
- plt.show()
- return
-
- # plt.gcf().subplots_adjust(bottom=0.15)
- plt.xlabel('K parameters', fontsize=20)
- # plt.tight_layout()
- plt.savefig('k_line_v3.pdf')
- plt.show()
-
-
- def get_data(k2=False):
- fontsize = 15
- x=[i for i in range(1000)]
-
- BasePath="D:\\code\\up\\test_function"
- y=[]
- for i in range(6):
- y.append([])
- time=[]
- for i in range(3):
- time.append([])
- for num, info in enumerate(os.listdir(BasePath)):
- Path=os.path.join(BasePath, info)
- print(Path)
- value=np.load(Path)
- print(value['arr_0'].shape)
- i=num%6
- mvalue=[]
- arr0=value['arr_0']
- mvalue.append(np.mean(arr0, axis=0))
- mvalue.append(np.var(arr0, axis=0))
- print(arr0.shape)
- mi=100000
- print(mvalue[0].shape)
- for k in range(len(mvalue[0])):
- if mvalue[0][k]>0:
- mi=mvalue[0][k] if mvalue[0][k]<mi else mi
- else: mvalue[0][k]=mi
- print(mvalue[0].shape)
- y[i].append(mvalue)
- if (num//6)==1:
- time[i%3].append(np.log10(np.mean(value['arr_1'], axis=0)))
- if (num//6)== 4: time[i%3].append(np.log10(np.mean(value['arr_1'],axis=0)))
- # for i in range(6):
- # y[i][4],y[i][5]=y[i][5],y[i][4]
-
- if k2:
- # return draw_k_line_v2(x, y1, y11, y2, y22, y3, y33)
- # draw_k_line_v4(x, y)
- # draw_times(x, time)
- return
-
- def draw_k_line_v4(x, y): #画migo和mdenas的对比
- fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(30, 13)) #要画的子图分布设置,设置行列数
-
- # fmt=['.-b', '+-g', 'x-r', '*-y', '<-m', '>-k']
- fmt=['.-b', '.-g']
- color="bgrymk"
- lvalue=["MDENAS","MIGO"]
-
- sp_x0=[x for x in range(50)]
- sp_x1=[x for x in range(50,200)]
- for i in range(2):
- for j in range(3):
- for num in range(2): #设置每幅图要画的线,用plot
- id=i*3+j
- axes[i][j].plot(x, y[id][num][0], fmt[num], label=lvalue[num])
-
-
- title=["(N=10,M=10) index_sum", "(N=10,M=10) rastrigin", "(N=10,M=10) rosenbrock", "(N=20,M=20) index_sum", "(N=20,M=20) rastrigin", "(N=20,M=20) rosenbrock"]
- for i in range(2):
- for j in range(3):
- ax=axes[i][j]
- ax.set_title(title[i*3+j],fontdict={'fontsize':30, 'family' :'Times New Roman'}) #设置每幅图的标题
- ax.grid(linestyle='-.', linewidth=1) #设置一个网格线,平行于坐标轴
- if(j==0):ax.set_ylabel('L2 distance', fontdict={'family' : 'Times New Roman', 'size': 30}) #设置坐标轴的title
- if(i):ax.set_xlabel('Epoch', fontdict={'family' : 'Times New Roman', 'size': 30})
- ax.tick_params(labelsize=20)
- ax.legend(fontsize=17, loc=1) #设置图例,每条线的图例
- ax.spines['bottom'].set_linewidth(2) #对坐标轴线设置宽度
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- plt.subplots_adjust(wspace=0.15, hspace=0.5) #调整子图之间的间距
- plt.savefig('mdenas_migo.pdf') #保存为pdf
- # plt.show()
- return
- def predict_data():
- x=[]
- y=[]
- x.append([i for i in range(50, 600, 10)])
- y.append([i for i in range(50, 600, 10)])
- x.append([i for i in range(0, 10)])
- y.append([i for i in range(0, 10)])
- # x.append(np.linspace(1,10, num=100))
- # y.append(np.linspace(1,10, num=100))
- x.append([i for i in range(80, 131)])
- y.append([i for i in range(80, 131)])
- px=[]
- py=[]
- for i in range(3):px.append([])
- for i in range(3):py.append([])
- rx=[50,0,80]
- ry=[599,9,130]
- for j in range(30):
- bili=np.random.uniform(0,1)
- for i in range(3):
- value=rx[i]+(ry[i]-rx[i])*bili
- px[i].append(value)
- py[i].append(value)
- for i in range(len(py[2])):
- noise=np.random.uniform(-2,2)
- py[2][i]+=noise
- print(x,y)
- draw_k_line_v5(x, y, px, py)
-
- #画预测图
- def draw_k_line_v5(x, y, px, py): #画flops,parameters,latency 预测图
- fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(45, 13)) #要画的子图分布设置,设置行列数
-
- # fmt=['.-b', '+-g', 'x-r', '*-y', '<-m', '>-k']
- fmt=['.--b', '.-g']
- color="bgrymk"
- lvalue=["flops","parameters","lantancy"]
-
- sp_x0=[x for x in range(50)]
- sp_x1=[x for x in range(50,200)]
- for j in range(3):
- for num in range(1): #设置每幅图要画的线,用plot
- axes[j].plot(x[j], y[j], fmt[num], label=lvalue[j], linewidth=4)
- axes[j].scatter(px[j], py[j], s=100., c='r')
-
-
- title=["flops", "parameters", "latancy"]
- tx=['Estimated(M)', 'Estimated(M)', 'Estimated(ms)' ]
- ty=['Real(M)', 'Real(M)', 'Real(ms)' ]
- for j in range(3):
- ax=axes[j]
- ax.set_title(title[j],fontdict={'fontsize':60, 'family' :'Times New Roman'}) #设置每幅图的标题
- ax.grid(linestyle='-.', linewidth=1) #设置一个网格线,平行于坐标轴
- ax.set_ylabel(tx[j], fontdict={'family' : 'Times New Roman', 'size': 30}) #设置坐标轴的title
- ax.set_xlabel(ty[j], fontdict={'family' : 'Times New Roman', 'size': 30})
- ax.tick_params(labelsize=20)
- ax.legend(fontsize=17, loc=1) #设置图例,每条线的图例
- ax.spines['bottom'].set_linewidth(2) #对坐标轴线设置宽度
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- plt.subplots_adjust(wspace=0.15, hspace=0.5) #调整子图之间的间距
- plt.savefig('predict.pdf') #保存为pdf
- # plt.show()
- return
- # 画随着lam 和 nm 变化的趋势图
- def get_lam_nm():
- BasePath="D:\\code\\up\\lam"
- y=[]
- for i in range(3):y.append([])
- x=[i for i in range(3,25)]
- for num, info in enumerate(os.listdir(BasePath)):
- Path=os.path.join(BasePath, info)
- # print(Path)
- value=np.load(Path)['arr_0']
- arr=np.mean(value, axis=0)
- id=num//22
- print(num,Path)
- for i in range(len(arr)-1, -1, -1):
- if arr[i]!=-1:
- y[id].append(arr[i])
- break
-
- print(len(y))
- print(y)
-
- nx=[i/10.0 for i in range(5,20)]
- ny=[]
- for i in range(3):ny.append([])
- BasePath="D:\\code\\up\\nm"
- for num, info in enumerate(os.listdir(BasePath)):
- Path=os.path.join(BasePath, info)
- # print(Path)
- value=np.load(Path)['arr_0']
- arr=np.mean(value, axis=0)
- id=num//15
- print(num,Path)
- for i in range(len(arr)-1, -1, -1):
- if arr[i]!=-1:
- ny[id].append(arr[i])
- break
- print(len(ny), len(ny[0]), ny)
- print(y[2])
- for i in range(len(y[2])//2):
- y[2][i], y[2][len(y[2])-i-1]=y[2][len(y[2])-i-1], y[2][i]
- print(y[2])
- draw_k_line_v6(x, y, nx, ny)
-
-
- def draw_k_line_v6(x, y, nx, ny): #画migo和mdenas的对比
- fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(30, 13)) #要画的子图分布设置,设置行列数
-
- # fmt=['.-b', '+-g', 'x-r', '*-y', '<-m', '>-k']
- fmt=['.-b', '.-g', 'x-r']
- color="bgrymk"
- lvalue=["ASNG","dynamic_ASNG","MIGO"]
-
- for j in range(2):
- for num in range(3): #设置每幅图要画的线,用plot
- if j==0:axes[j].plot(x, y[num], fmt[num], label=lvalue[num], linewidth=5)
- else:axes[j].plot(nx, ny[num], fmt[num], label=lvalue[num], linewidth=5)
-
-
-
- title=[r"$\lambda$", "N/M"]
- for j in range(2):
- ax=axes[j]
- # ax.set_title(title[j],fontdict={'fontsize':30, 'family' :'Times New Roman'}) #设置每幅图的标题
- ax.grid(linestyle='-.', linewidth=1) #设置一个网格线,平行于坐标轴
- if(j==0):ax.set_ylabel('L2 distance', fontdict={'family' : 'Times New Roman', 'size': 30}) #设置坐标轴的title
- ax.set_xlabel(title[j], fontdict={'family' : 'Times New Roman', 'size': 30})
- ax.tick_params(labelsize=20)
- ax.legend(fontsize=25, loc=2) #设置图例,每条线的图例
- ax.spines['bottom'].set_linewidth(2) #对坐标轴线设置宽度
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- plt.subplots_adjust(wspace=0.15, hspace=0.5) #调整子图之间的间距
- plt.savefig('lam_nm.pdf') #保存为pdf
- # plt.show()
- return
-
-
-
- def func(num):
- pre,aft=f'{num:.2e}'.split('e')
- return f'${float(pre):.1f}x10^'+'{'+str(int(aft))+'}$'
-
- def draw_times(x, time):
- fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(30, 8))
-
- # fmt=['.-b', '+-g', 'x-r', '*-y', '<-m', '>-k']
- fmt=['.-b', '.-g', '.-r', '.-k']
- color="bgrymk"
- lvalue=["Bayesian Optimization(N=10,M=10)", "Bayesian Optimization(N=20,M=20)", "Ours MIGO(N=10,M=10)", "Ours MIGO(N=20,M=20)"]
- sp_x0=[x for x in range(50)]
- sp_x1=[x for x in range(50,200)]
- for i in range(3):
- for j in range(4):
- if j<2:
- print(len(sp_x0), len(time[i][j]))
- axes[i].plot(sp_x0, time[i][j][:50], fmt[j], label=lvalue[j])
- # sp_y=[time[i][j][49] for e in range(150)]
- # if(j):axes[i].plot(sp_x1, sp_y, '--g')
- # else: axes[i].plot(sp_x1, sp_y, '--b')
- else:
- print(time[i][j])
- sp_y=[time[i][j][k] for k in range(50)]
- axes[i].plot(sp_x0, sp_y, fmt[j], label=lvalue[j])
- # fig,axes=plt.subplots(nrows=1, ncols=1,figsize=(10, 8))
- # axes.plot(x,y[0][0][0], '.-b', label=0)
- # plt.show
-
-
- # LUSC_range = (0.640, 0.680, 0.005)
- # GBM_range = (0.595, 0.655, 0.010)
- # NLST_range = (0.630, 0.670, 0.005)
- # graph_ranges = [LUSC_range, GBM_range, NLST_range]
-
- title=["index_sum", "rastrigin", "rosenbrock"]
- for i in range(3):
- ax=axes[i]
- ax.set_title(title[i],fontdict={'fontsize':30, 'family' :'Times New Roman'})
- # ax.set_yscale('linear')
- # ax.set_yticks(np.arange(*graph_ranges[i]))
- ax.grid(linestyle='-.', linewidth=1)
- # ax.set_xticks(range(5, 21))
- if(i==0):ax.set_ylabel('Time', fontdict={'family' : 'Times New Roman', 'size': 30})
- ax.set_xlabel('Number of function evaluations', fontdict={'family' : 'Times New Roman', 'size': 30})
- ax.tick_params(labelsize=20)
- ymajorFormatter=FormatStrFormatter(r'$10^{%d}$')
- ax.yaxis.set_major_formatter(ymajorFormatter)
-
- ax.legend(fontsize=16, loc=2)
- # for tick in ax.yaxis.get_major_ticks():
- # tick.label.set_fontsize(20)
- # for tick in ax.xaxis.get_major_ticks():
- # tick.label.set_fontsize(20)
-
- ax.spines['bottom'].set_linewidth(2)
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- # ax.legend(loc=3, fontsize=16)
- # plt.subplots_adjust(wspace=0, hspace=10)
- plt.savefig('new_time.pdf')
- plt.show()
- return
-
- # plt.gcf().subplots_adjust(bottom=0.15)
- plt.xlabel('K parameters', fontsize=20)
- # plt.tight_layout()
- plt.savefig('k_line_v3.pdf')
- plt.show()
-
-
- def box_line_v2():
- import seaborn as sns
- import pandas as pd
-
- fontsize = 15
- dataset_labels = ['GBM'] * 30 + ['LUSC'] * 30 + ['NLST'] * 30
- models = list()
- for x in xticklabels:
- models += [x] * 5
- models_list = models * 3
- c_index_list = np.array(gbm + lusc + nlst).flatten()
-
- # print(len(dataset_labels), dataset_labels)
- # print(len(c_index_list), c_index_list)
- # assert len(dataset_labels) == len(c_index_list)
-
- data = pd.DataFrame({
- 'Models': models_list,
- 'C-index': c_index_list,
- 'Datasets': dataset_labels
- })
-
- # sns.set(style="whitegrid", palette="Set1", color_codes=True, font_scale=1)
- splt = sns.boxplot(x="Datasets", y="C-index", hue="Models", data=data, width=0.5)
-
- plt.grid(linestyle='-.', linewidth=1.5)
- ax = plt.gca()
- ax.spines['bottom'].set_linewidth(2)
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- plt.xlabel(None)
- plt.ylabel(None)
- plt.xticks(fontsize=fontsize)
- plt.yticks(np.arange(0.50, 0.80, 0.025), fontsize=fontsize)
- plt.legend(fontsize=14)
- plt.tight_layout()
-
- plt.axis('tight')
- plt.savefig('board.pdf')
- plt.show()
-
- def draw_dg_line():
- BasePath="D:\\code\\hyper_parameter\\hyper_parameter"
- L2=[]
- P=[]
- gamma=[]
- for num, info in enumerate(os.listdir(BasePath)):
- Path=os.path.join(BasePath, info)
- Name=Path[:-4]
- pstr=float(Name.split('_')[-2])
- pg=float(Name.split('_')[-1])
- P.append(pstr)
- gamma.append(pg)
- # print(Path)
- arr=np.load(Path)
- value=arr['arr_0']
- mi=99999
- for i in range(value.shape[0]):
- pos=np.where(value[i]>=0)
- mi=min(value[i][pos[0][-1]], mi)
- if value[i][pos[0][-1]]<0:
- print(Name, i)
- print('pos')
- print(pos[0][-1])
- L2.append(mi)
- gamma=np.array(gamma)
-
- P=np.array(P)
- print(gamma)
- print(L2)
- print(P)
- gamma=gamma.reshape(9,9)
- P=P.reshape(9,9)
- print(gamma)
- print(P)
- L2=np.mat(L2)
- L2=L2.reshape(9,9)
- print(L2)
- print(gamma.shape)
- print(P.shape)
- print(L2.shape)
- cmaps=matplotlib.cm.hot
- cset=plt.contourf(gamma, P, L2, norm=(matplotlib.colors.Normalize(vmin=L2.min(), vmax=L2.max())), cmap=matplotlib.cm.PuBu_r)
- plt.colorbar(cset)
- plt.contour(gamma, P, L2)
- plt.show()
-
-
- def draw_weight():
- thetas=np.load('thetas.npy')
- print(thetas.shape)
- # print(thetas)
- values=[]
- for i in range(14):
- values.append([])
- for j in range(8):
- values[i].append([])
- for i in range(140):
- print(thetas[i][0][1])
- for j in range(14):
- for k in range(8):
- # print(thetas[i][j][k])
- values[j][k].append(thetas[i][j][k])
- # if j == 0 and k == 0: print(thetas[i][j][k], values[j][k])
- print(values)
- values=np.array(values)
- print(values.shape)
-
- fig, axes = plt.subplots(nrows=2, ncols=7, figsize=(30, 8))
- x=[i for i in range(140)]
- fmt=['-b', '-g', '-r', '-y', '-m', '-k', '-c', '--b']
- lvalue=[
- 'max_pool_3x3',
- 'avg_pool_3x3',
- 'skip_connect', # identity
- 'sep_conv_3x3',
- 'sep_conv_5x5',
- 'dil_conv_3x3',
- 'dil_conv_5x5',
- 'none'
- ]
- lines=[]
- for i in range(2):
- for j in range(7):
- id=i*7+j
- for k in range(8):
- # print(values[id][k])
- line, =axes[i][j].plot(x, values[id][k], fmt[k], label=lvalue)
- lines.append(line)
-
-
- # title=["(N=10,M=10) index_sum", "(N=10,M=10) rastrigin", "(N=10,M=10) rosenbrock", "(N=20,M=20) index_sum", "(N=20,M=20) rastrigin", "(N=20,M=20) rosenbrock"]
- for i in range(2):
- for j in range(7):
- ax=axes[i][j]
- # ax.set_title(title[i*3+j],fontdict={'fontsize':30, 'family' :'Times New Roman'})
- # ax.set_yscale('linear')
- # ax.set_yticks(np.arange(*graph_ranges[i]))
- # ax.grid(linestyle='-.', linewidth=1)
- # ax.set_xticks(range(5, 21))
- # if(j==0):ax.set_ylabel('Weight', fontdict={'family' : 'Times New Roman', 'size': 30})
- # if(i):ax.set_xlabel('Epoch', fontdict={'family' : 'Times New Roman', 'size': 30})
- ax.tick_params(labelsize=20)
-
-
- # ax.legend(fontsize=17, loc=1)
- # for tick in ax.yaxis.get_major_ticks():
- # tick.label.set_fontsize(20)
- # for tick in ax.xaxis.get_major_ticks():
- # tick.label.set_fontsize(20)
-
- ax.spines['bottom'].set_linewidth(2)
- ax.spines['left'].set_linewidth(2)
- ax.spines['right'].set_linewidth(2)
- ax.spines['top'].set_linewidth(2)
-
- # ax.legend(loc=3, fontsize=16)
- plt.figlegend(lines, lvalue,loc=8, fontsize=17, ncol=8)
- plt.subplots_adjust(wspace=0.15, hspace=0.5)
- plt.savefig('weight.pdf')
- plt.show()
- return
-
-
-
-
- if __name__ == '__main__':
- draw_k_line(True)
- # draw_weight()
- # draw_dg_line()
- # box_line_v2()
- # box_line()
- # get_data(True)
- #predict_data()
- # get_lam_nm()
|