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
| # initial state: | |
| y0 = [1.0, 0.0] | |
| # time coordinate to solve the ODE for | |
| t = np.linspace(0, 10, 1000) | |
| w0 = 2*np.pi*1.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
| # solve the ODE problem for three different values of the damping ratio | |
| y1 = odeint(dy, y0, t, args=(0.0, w0)) # undamped | |
| y2 = odeint(dy, y0, t, args=(0.1, w0)) # under damped | |
| y3 = odeint(dy, y0, t, args=(1.1, w0)) # critial damping | |
| y4 = odeint(dy, y0, t, args=(5.0, w0)) # over damped |
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
| fig, ax = plt.subplots() | |
| ax.plot(t[:500], y1[:500,0], 'k', label="undamped", linewidth=0.25) | |
| ax.plot(t[:500], y2[:500,0], 'r', label="under damped") | |
| ax.plot(t[:500], y3[:500,0], 'b', label=r"critical damping") | |
| ax.plot(t[:500], y4[:500,0], 'g', label="over damped") | |
| ax.legend(); |
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 | |
| np.set_printoptions(suppress=True, precision=15) | |
| #input sampling timeseries | |
| n_sampling = 5 | |
| #define param |
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
| #ODE Critical Dumped | |
| Critical_Dumped = np.array( | |
| [1. , 0.9980310417, 0.9921647546, 0.982472909 , | |
| 0.9690414108, 0.9519697845, 0.9313706249, 0.9073689737, | |
| 0.8801016795, 0.849716714 , 0.8163724522, 0.7802369177, | |
| 0.7414870035, 0.7003076647, 0.6568910904, 0.6114358603, | |
| 0.5641460809, 0.5152305196, 0.4649017207, 0.413375126 , | |
| 0.3608681911, 0.3075995058, 0.2537879208, 0.1996516846, | |
| 0.1454075937, 0.0912701602, 0.03745079 , -0.0158429971, | |
| -0.0684083469, -0.1200477968, -0.1705699976, -0.2197903762, |
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
| w = np.ones([m,n], np.float32)*init_arr_item | |
| v = np.ones([M,m], np.float32)*init_arr_item | |
| b_j = np.zeros([m], np.float32)*init_arr_item | |
| b_k = np.zeros([M], np.float32)*init_arr_item | |
| z_pred = np.zeros([y.shape[0], m], np.float32) | |
| y_pred = np.zeros([y.shape[0], M], np.float32) | |
| E = np.zeros(M, np.float32) | |
| v_new = np.zeros([M,m], 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
| #define sigmoid activation function | |
| def f_sigmoid(value): | |
| return 1.0/(1.0+np.exp(-value)) | |
| def f_sigmoid_derivation(value): | |
| return f_sigmoid(value)*(1-f_sigmoid(value)) | |
| #define linear activation function | |
| def f_linear(value): | |
| return value |
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_z_j(x_train, w_train, b_j_train): | |
| for j in range(m): | |
| z_pred[:,j] = np.dot(x_train,w_train[j,:]) + b_j_train[j] | |
| return z_pred | |
| def calc_y_k(z_train, v_train, b_k_train): | |
| for k in range(M): | |
| y_pred[:,k] = np.dot(z_train, v_train[k,:]) + b_k_train[k] | |
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 error_calc(target, output): | |
| for k in range(M): | |
| E[k] = 0.5*(target[k] - output[k])**2 | |
| return np.sum(E) |