This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def calc_v_new(v_last, y, y_prediction, z_prediction): | |
| delta_k = np.transpose(f_activation_derivation_output(y_prediction)*(np.reshape(y, (y.shape[0], 1)) - y_prediction)) | |
| for j in range(m): | |
| v_new[:,j] = v_last[:,j] + learning_rate*np.dot(delta_k,z_prediction[:,j]) | |
| return v_new, delta_k | |
| def calc_w_new(w_last, v_new, delta_k, z_prediction, x_input): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def train_model(train_count, w_train, v_train, b_j_train, b_k_train, y_train, x_train): | |
| for l in range(train_count): | |
| z_prediction = calc_z_j(x_train, w_train, b_j_train) | |
| z_prediction = f_activation(z_prediction) | |
| y_prediction = calc_y_k(z_prediction, v_train, b_k_train) | |
| y_prediction = f_activation_output(y_prediction) | |
| v_train, delta_k = calc_v_new(v_train, y_train, y_prediction, z_prediction) | |
| w_train, delta_j = calc_w_new(w_train, v_train, delta_k, z_prediction, x_train) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| v, w, b_k, b_j = train_model(TRAIN_ITER, w, v, b_j, b_k, y, x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test(x_test, w, v, b_j, b_k): | |
| z_prediction = np.dot(x_test, np.transpose(w)) + b_j | |
| f_z_prediction = f_activation(z_prediction) | |
| y_prediction = np.dot(f_z_prediction, np.transpose(v)) + b_k | |
| f_y_prediction = f_activation_output(y_prediction) | |
| return f_y_prediction | |
| y_prediction_test = np.zeros(len(x), np.float32) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| t = np.linspace(1, 500, 500) | |
| ODE_Target = np.transpose(np.array([t, Critical_Dumped], np.float32)) | |
| ODE_Output = np.transpose(np.array([t[n_sampling:], y_prediction_test[:,0]], np.float32)) | |
| ODE_Target_PD = pd.DataFrame(data=ODE_Target[:,:], | |
| index=ODE_Target[:,0], | |
| columns=['t', 'x actual']) | |
| ODE_Output_PD = pd.DataFrame(data=ODE_Output[:,:], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| #input sampling timeseries | |
| n_sampling = 5 | |
| #define param | |
| n = n_sampling |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CO_TS_TRAIN = CO_TS[CO_TS.index.month < 12] #january - november time series as train data | |
| CO_TS_TEST = CO_TS[CO_TS.index.month == 12] #december time series as test data | |
| CO_TS_TRAIN_Arr = CO_TS_TRAIN.to_numpy() | |
| CO_TS_TEST_Arr = CO_TS_TEST.to_numpy() | |
| CO_TS_TRAIN_Arr = np.reshape(CO_TS_TRAIN_Arr, (CO_TS_TRAIN_Arr.shape[0])) | |
| CO_TS_TEST_Arr = np.reshape(CO_TS_TEST_Arr, (CO_TS_TEST_Arr.shape[0])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def split_sequence(sequence, n_steps): | |
| _X, _y = list(), list() | |
| for i in range(len(sequence)): | |
| # find the end of this pattern | |
| end_ix = i + n_steps | |
| # check if we are beyond the sequence | |
| if end_ix > len(sequence)-1: | |
| break | |
| # gather input and output parts of the pattern | |
| seq_x, seq_y = sequence[i:end_ix], sequence[end_ix] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.models import Sequential | |
| from keras.layers import Dense | |
| from keras.optimizers import Adam |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| os.environ['CUDA_VISIBLE_DEVICES'] = '-1' |