Example #1
0
def make_plot():
    x = []
    #battle#
    y1 = []  #originalが勝つ割合
    y2 = []  #svdが勝つ割合
    y3 = []  #引き分けの割合
    #frobenius#
    y4 = []
    X = get_np.reshape(27, 27, 27)
    norm = np.sqrt(np.sum(X * X))
    for i in range(0, 28):
        #battle#
        y1.append(main.battle(get_np, tucker(get_np, i)[0])[0])
        y2.append(main.battle(get_np, tucker(get_np, i)[0])[1])
        y3.append(main.battle(get_np, tucker(get_np, i)[0])[2])
        #frobenius#
        Y = tucker(get_np, i)[0].reshape((27, 27, 27))
        rate = tucker(get_np, i)[1]
        norm1 = np.sqrt(np.sum((X - Y) * (X - Y)))
        x.append(rate)
        y4.append(norm1 / norm)
    #battle#
    plt.xlabel("compression ratio")
    plt.plot(x, y1, color='red')
    plt.plot(x, y2, color='blue')
    plt.plot(x, y3, color='green')
    #frobenius#
    plt.plot(x, y4, color='black')

    plt.show()
Example #2
0
def save_file():
    with open("task2.dat", "w") as f:
        for i in range(0, 28):
            #圧縮率
            x = tucker(get_np, i)[1]
            #battle
            y1 = []
            y2 = []
            y3 = []
            for _ in range(5):
                y1.append(main.battle(get_np,
                                      tucker(get_np, i)[0])[0])  #originalが勝つ割合
                y2.append(main.battle(get_np,
                                      tucker(get_np, i)[0])[1])  #svdが勝つ割合
                y3.append(main.battle(get_np,
                                      tucker(get_np, i)[0])[2])  #引き分けの割合
            y1_m = np.mean(y1)
            y2_m = np.mean(y2)
            y3_m = np.mean(y3)
            y1_std = np.std(y1)
            y2_std = np.std(y2)
            y3_std = np.std(y3)
            #frobenius
            y4 = tucker(get_np, i)[2]
            f.write("{} {} {} {} {} {} {} {}\n".format(x, y1_m, y2_m, y3_m, y4,
                                                       y1_std, y2_std, y3_std))
Example #3
0
def cmpr(rate, num_svd, num_hosvd):  #圧縮率、svd特異値数、hosvd特異値数
    y1 = main.battle(hosvd(get_np, num_hosvd)[0],
                     svd(get_np, num_svd)[0])[0]  #hosvdの勝率
    y2 = main.battle(hosvd(get_np, num_hosvd)[0],
                     svd(get_np, num_svd)[0])[1]  #svdの勝利
    y3 = main.battle(hosvd(get_np, num_hosvd)[0],
                     svd(get_np, num_svd)[0])[2]  #引き分け
    return [rate, y1, y2, y3]
Example #4
0
def save_file():
	with open("task1.dat", "w") as f:
		for r in range(0, 82):            
			#圧縮率
			x = approx(get_np, r)[1]
			#battle          
			y1 = []
			y2 = []
			y3 = []
			for _ in range(5):     #5回分のループ
				y1.append(main.battle(get_np, approx(get_np, r)[0])[0])    #originalが勝つ割合
				y2.append(main.battle(get_np, approx(get_np, r)[0])[1])    #svdが勝つ割合
				y3.append(main.battle(get_np, approx(get_np, r)[0])[2])    #引き分けの割合
			y1_m = np.mean(y1)
			y2_m = np.mean(y2)
			y3_m = np.mean(y3)
			y1_std = np.std(y1)
			y2_std = np.std(y2)
			y3_std = np.std(y3)
			#frobenius#  
			y4 = approx(get_np, r)[2]               
			f.write("{} {} {} {} {} {} {} {}\n".format(x, y1_m, y2_m, y3_m, y4, y1_std, y2_std, y3_std))
Example #5
0
def make_plot():              
    #battle#
    x = []
    y1 = []                                  #originalが勝つ割合
    y2 = []                                  #svdが勝つ割合
    y3 = []                                  #引き分けの割合
    #frobenius#
    y4 = []
    X = get_np.reshape(81,243)     #もとの行列をreshape         
    u, s, v = linalg.svd(X)                              #svd
    norm = np.sqrt(np.sum(X * X))                        #sのフロベニウスノルム
    for r in range(0, 82):                      
        #battle#
        y1.append(main.battle(get_np, approx(get_np, r))[0])
        y2.append(main.battle(get_np, approx(get_np, r))[1])
        y3.append(main.battle(get_np, approx(get_np, r))[2])
        #frobenius#  
        ur = u[:, :r]
        sr = np.diag(np.sqrt(s[:r]))                #sの平方根
        vr = v[:r, :]
        A = ur @ sr
        B = sr @ vr
        Y = A @ B                                   #近似した行列
        norm1 = np.sqrt(np.sum((X-Y) * (X-Y)))     #フロベニウスノルム
        rate = (A.size+B.size) / X.size
        y4.append(norm1 / norm)
        x.append(rate)                         #残した特異値の割合 
    plt.xlabel("compression ratio")
    ######plt.ylabel("ratio")
    #battle#
    plt.plot(x, y1, color = 'red')
    plt.plot(x, y2, color = 'blue')
    plt.plot(x, y3, color = 'green')
    #frobenius#
    plt.plot(x, y4, color = 'black')

    plt.show()