$\lambda$对CMA性能影响研究

摘要: $\lambda$大小影响单次计算时间,根据文档合理的$\lambda$在[5,2n+10]之间,Hansen给出的推荐值为$4+3\times \lfloor ln(N) \rfloor$,本文固定mu=0.5,sigma=0.3,根据不同的$\lambda$对不同函数绘图分析.

第一阶段测试

  • 函数:[rosen,bukin,griewank]
  • 最小值:[0,6.82,0]
  • 维度:[130]
  • $\lambda$:[5,18,20,50,80,110,140]

In [1]:
%pylab inline
import pandas as pd
from pandas import Series, DataFrame
import pickle
plt.rc('figure', figsize=(12, 8))


Populating the interactive namespace from numpy and matplotlib

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)


第二阶段测试

  • 函数:[sphere,cigar,elli]
  • 最小值:[0,0,0]
  • 维度:[208]
  • $\lambda$:[5,10,14,18,20,22,26,60,100,140,180,220]

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)