示例#1
0
batch_size = 1
time_steps = 35

LSTM = LSTM(input_size=1, state_size=10, hidden_sum=1, output_size=1, time_steps=35, batch_size=batch_size,
            learning_rate=0.001)

data = to_input(matrix)
input_data = data[0]
cost_data = data[1]
for j in range(2):
    print("第%d轮训练" %(j+1))
    for i in range(len(input_data) - 1):
        batch_x = np.reshape(input_data[i], [batch_size, time_steps, 1])
        batch_y = np.reshape(input_data[i + 1], [batch_size, time_steps])
        batch_c = np.reshape(cost_data[i], [batch_size, time_steps])
        cost = LSTM.Persistent_opt(batch_x, batch_y, batch_c)
        print(cost)
        data_output = np.reshape(LSTM.output(batch_x, batch_y, batch_c), [35])
        print("R2:", r2_score(np.reshape(batch_y, [35]), data_output))

data1 = to_input(matrix1)
input_data1 = data1[0]
cost_data1 = data1[1]
for j in range(2):
    print("第%d轮训练" %(j+1))
    for i in range(len(input_data1) - 1):
        batch_x = np.reshape(input_data1[i], [batch_size, time_steps, 1])
        batch_y = np.reshape(input_data1[i + 1], [batch_size, time_steps])
        batch_c = np.reshape(cost_data1[i], [batch_size, time_steps])
        cost = LSTM.Persistent_opt(batch_x, batch_y, batch_c)
        print(cost)