In [1]:
%pylab inline
import pandas as pd
from pandas import Series, DataFrame
import pickle
plt.rc('figure', figsize=(12, 8))
In [2]:
with open("data.tl",'r') as f:
result_list=pickle.load(f)
In [3]:
def convertdic(result_list):
res=[{}]
for row in result_list:
for i,d in enumerate(res):
if row[-1] not in d.keys():
d[row[-1]]=row[:-1]
break
if i==len(res)-1:
res.append({row[-1]:row[:-1]})
break
return res
def draw(title,tail):
bs=[row[:tail] for row in result_list if row[tail]==title]
bs=np.array(bs)
lmax=max(bs[:,-1])
bs=bs/bs.max(0)
bs=bs*[1,1,1,1,lmax]
bs=convertdic(bs)
df=DataFrame(bs[0],index=['countiter','countevals','result','time(s)'])
df=df.stack().unstack(0)
df.columns.name='values'
df.index.name='lambda'
df.plot(kind='bar',stacked=False,colormap='jet',alpha=0.9,title=title,figsize=(12,8));
df.plot(kind='area',stacked=False,colormap='jet',alpha=0.5,title=title,figsize=(12,8),xticks=np.arange(5,lmax,10));
def drawSigmaLines(t,xl):
sigmas=[[row[-3],row[-1]] for row in result_list if row[-2]==t]
ss=map(list,zip(*sigmas))[1]
M=max(map(len,ss))
for s in sigmas:
for i in range(M-len(s[1])):
s[1].append(None)
df1=DataFrame({s[0]:s[1] for s in sigmas})
df1.columns.name='sigma'
df1.index.name='lambda'
df1.plot(title=t,fontsize=10,linewidth=2,alpha=0.8,colormap='rainbow',xlim=(0,xl))
In [4]:
#bukin函数
draw('bukin',-1)
In [5]:
#rosen函数
draw('rosen',-1)
In [6]:
#griwank函数
draw('griewank',-1)
In [7]:
with open("data1.tl",'r') as f:
result_list=pickle.load(f)
In [8]:
#sphere函数
draw('sphere',-2)
drawSigmaLines('sphere',300)
In [9]:
#cigar函数
draw('cigar',-2)
drawSigmaLines('cigar',300)
In [10]:
#elli函数
draw('elli',-2)
drawSigmaLines('elli',300)