human
I am working on the file "CMA-ES/分段函数平滑拟合/分段平滑拟合.ipynb".
The first task is:
实验
划分七段用CMA线性拟合14个参数
Can you write Python code for it?
assistant
#Here is the Python code you requested.

def realLineFunc(param):
    def f(x):
        if x<-5:
            return np.poly1d([param[0],param[1]])(x)
        elif x<-3:
            return np.poly1d([param[2],param[3]])(x)
        elif x<-1:
            return np.poly1d([param[4],param[5]])(x)
        elif x<1:
            return np.poly1d([param[6],param[7]])(x)
        elif x<3:
            return np.poly1d([param[8],param[9]])(x)
        elif x<5:
            return np.poly1d([param[10],param[11]])(x)
        else:
            return np.poly1d([param[12],param[13]])(x)
    return f
def mse(x,y,param):
    s=0
    for j in range(0,14,2):
        for i in range(int(j/2)*10,int(j/2+1)*10,1):
            s+=(y[i]-fittingFunc(param[j:j+2])(x[i]))**2
    return math.sqrt(s/200.0) 
 #间断点
def evalfunc1(param):
    s=mse(X,Y,param)/RANGE
    a=0
    for j in range(2,14,2):
        a+=E(abs(fittingFunc(param[j-2:j])(X[(j/2)*10])-fittingFunc(param[j:j+2])(X[(j/2)*10]))/RANGE-ALPHA)-1
    return s+a
#间断点一阶导数
def evalfunc2(param):
    s=mse(X,Y,param)/RANGE
    b=0
    for j in range(2,14,2):
        b+=(E((abs(math.atan(param[j-2])-math.atan(param[j]))-BETA))-1)/(100*math.e)
    return s+b
#考虑两种
def evalfunc3(param):
    s=mse(X,Y,param)/RANGE
    a=0
    for j in range(2,14,2):
        a+=E(abs(fittingFunc(param[j-2:j])(X[(j/2)*10])-fittingFunc(param[j:j+2])(X[(j/2)*10]))/RANGE-ALPHA)-1
    b=0
    for j in range(2,14,2):
        b+=(E((abs(math.atan(param[j-2])-math.atan(param[j]))-BETA)/(100*math.e))-1)
    return s+a+b
#不考虑其他因素
def evalfunc(param):
    s=mse(X,Y,param)/RANGE
    return s

def draw(title):
    global X
    res=cmaUser(evalfunc)
    res1=cmaUser(evalfunc1)
    res2=cmaUser(evalfunc2)
    res3=cmaUser(evalfunc3)

    plt.figure(1) 
    plt.plot(X,Y,'b.',alpha=0.6,label="measure point")
    X1=np.insert(X,0,[-5.01,-3.01,-1.01,0.99,2.99,4.99])
    X1.sort()
    plt.plot(X1,map(realLineFunc(res),X1),c="red",lw=2,ls="-",alpha=0.7,label="interval")
    plt.plot(X1,map(realLineFunc(res1),X1),c="blue",lw=2,ls="-",alpha=0.7,label="continuity1")
   ...