Beispiel #1
0
def main():
    (x, y) = LSM.data()
    (xwn, ywn) = LSM.data(Noise=True)
    lsm = LSM.LSM_L2(6)
    lsm.fit(x, y)
    lsm2 = LSM.LSM_L2(6)
    lsm2.fit(xwn, ywn)
    tics = 2 * pi * arange(0, 1, 0.02)
    lw = 5  #line width
    plt.subplot(211)
    plt.legend()
    plt.plot(x, y, 'ro', ms=10)
    plt.plot(tics, sin(tics), linewidth=lw, label="sin")
    plt.plot(tics, lsm.predict(tics), linewidth=lw, label="fitting")
    plt.legend(loc='lower right')

    plt.subplot(212)
    plt.xlim(0, 2 * pi)
    plt.ylim(-2, 2)
    plt.legend()
    plt.plot(xwn, ywn, 'ro', ms=10)
    plt.plot(tics, sin(tics), linewidth=lw, label="sin")
    plt.plot(tics, lsm2.predict(tics), linewidth=lw, label="fitting")
    plt.legend(loc='lower right')
    plt.show()
Beispiel #2
0
def main():
    (x,y) = LSM.data()
    (xwn, ywn) = LSM.data(Noise=True)
    lsm = LSM.LSM_L2(6)
    lsm.fit(x,y)
    lsm2 = LSM.LSM_L2(6)
    lsm2.fit(xwn,ywn)
    tics = 2*pi*arange(0,1,0.02);
    lw = 5 #line width
    plt.subplot(211)
    plt.legend()
    plt.plot(x,y, 'ro', ms=10)
    plt.plot(tics,sin(tics), linewidth=lw, label="sin")
    plt.plot(tics,lsm.predict(tics), linewidth=lw, label="fitting");
    plt.legend(loc = 'lower right')

    plt.subplot(212)
    plt.xlim(0,2*pi)
    plt.ylim(-2,2)
    plt.legend()
    plt.plot(xwn,ywn, 'ro', ms=10)
    plt.plot(tics,sin(tics), linewidth=lw, label="sin")
    plt.plot(tics,lsm2.predict(tics), linewidth=lw, label="fitting");
    plt.legend(loc = 'lower right')
    plt.show()
Beispiel #3
0
Datei: L2.py Projekt: PRMLiA/tsho
def main():
    (x,y) = LSM.data()
    (xwn, ywn) = LSM.data(Noise=True)
    lsm = LSM.LSM_L2(M=7, l=2.)
    tics = 2*pi*arange(0,1,0.02);
    lw = 5 #line width

    ls = power(7., range(-2,3))
    print(ls)
    for idcs in range(len(ls)):
        plt.subplot(len(ls),1,idcs+1)
        plt.xlim(0,2*pi+2)
        plt.ylim(-2,2)
        plt.legend()
        plt.plot(xwn,ywn, 'ro', ms=10)
        plt.plot(tics,sin(tics), linewidth=lw, label="sin")
        lsm.l = ls[idcs]
        lsm.fit(xwn,ywn)
        plt.plot(tics,lsm.predict(tics), linewidth=lw, label='l={:.1}'.format(ls[idcs]));
        plt.legend(loc = 'lower right')
    plt.show()
Beispiel #4
0
def main():
    (x, y) = LSM.data()
    (xwn, ywn) = LSM.data(Noise=True, NL=0.3, N=10)
    lsm = LSM.LSM_L2(M=7, l=2.)
    tics = 2 * pi * arange(0, 1, 0.02)
    lw = 5  #line width

    ls = array([0.0, 0.1, 10, 100])
    print(ls)
    for idcs in range(len(ls)):
        plt.subplot(len(ls), 1, idcs + 1)
        plt.xlim(0, 2 * pi + 2)
        plt.ylim(-2, 2)
        plt.legend()
        plt.plot(xwn, ywn, 'ro', ms=10)
        plt.plot(tics, sin(tics), linewidth=lw, label="sin")
        lsm.l = ls[idcs]
        lsm.fit(xwn, ywn)
        plt.plot(tics,
                 lsm.predict(tics),
                 linewidth=lw,
                 label='l={:.1}'.format(ls[idcs]))
        plt.legend(loc='lower right')
    plt.show()
Beispiel #5
0
# データをプロット
plt.plot(data_x, data_y, "o", label="data")


# 次数Nを決定
N = 3

# 次数0からNまで実行
for n in range(N+1) :

    # 実行する次数
    print("N="+str(n))

    # LSMで誤差と重みベクトルcoeを計算
    error, coe = LSM.LSM(data, int(n+1))
    print("error:"+str(error))
    print("coe:"+str(coe[::-1]))

    # ここで,このモデルのAICを計算
    l = AIC.l_MAX(list(coe[::-1]),data_x,data_y)
    AIC_n = AIC.AIC(l,n+1)
    print("l="+str(l)+", AIC("+str(n)+")="+str(AIC_n))

    # LSMで得た近似線をプロット
    test_x = np.arange(min(data_x), max(data_x), 0.01)
    plt.plot(test_x, LSM.quation_LSM(coe, test_x), label="polynomial of degree "+str(n)+", AIC("+str(n)+")="+str(AIC_n))

plt.title("Compare LSM of degree")
plt.legend()
plt.grid()
Beispiel #6
0
# print(data)

# データをわかりやすい配列に格納(pltに使いやすくしたいから)
data_x = []
data_y = []
for i in data:
    data_x.append(i[0])
    data_y.append(i[1])

# 次数Nを決定
N = 3

print("N=" + str(N))

# LSMで誤差と重みベクトルcoeを計算
error, coe = LSM.LSM(data, int(N + 1))
print("error:" + str(error))
print("coe:" + str(coe[::-1]))

# ここで,このモデルのAICを計算
l = AIC.l_MAX(list(coe[::-1]), data_x, data_y)
print("l=" + str(l) + ",AIC(" + str(N) + ")=" + str(AIC.AIC(l, N + 1)))

# データをプロット
plt.plot(data_x, data_y, "o")

# LSMで得た近似線をプロット
test_x = np.arange(min(data_x), max(data_x), 0.01)
plt.plot(test_x, LSM.quation_LSM(coe, test_x))

plt.grid()
Beispiel #7
0
    data_y.append(i[1])

# データをプロット
plt.plot(data_x, data_y, "o", label="data")

# 次数Nを決定
N = 6

# 次数0からNまで実行
for n in range(N + 1):

    # 実行する次数
    print("N=" + str(n))

    # LSMで誤差と重みベクトルcoeを計算
    error, coe = LSM.LSM(data, int(n + 1))
    print("error:" + str(error))
    print("coe:" + str(coe[::-1]))

    # ここで,このモデルのAICを計算
    l = AIC.l_MAX(list(coe[::-1]), data_x, data_y)
    AIC_n = AIC.AIC(l, n + 1)
    print("l=" + str(l) + ", AIC(" + str(n) + ")=" + str(AIC_n))

    # LSMで得た近似線をプロット
    test_x = np.arange(min(data_x), max(data_x), 0.01)
    plt.plot(test_x,
             LSM.quation_LSM(coe, test_x),
             label="polynomial of degree " + str(n) + ", AIC(" + str(n) +
             ")=" + str(AIC_n))