Skip to content

Instantly share code, notes, and snippets.

View Muhammad-Yunus's full-sized avatar
:octocat:
Working from home

Muhammad Yunus Muhammad-Yunus

:octocat:
Working from home
View GitHub Profile
@Muhammad-Yunus
Muhammad-Yunus / ODE_DHO_init_state.py
Created April 15, 2020 00:54
Python scikit - Ordinary Differential Equation
# 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
@Muhammad-Yunus
Muhammad-Yunus / ODE_DHO_solving.py
Created April 15, 2020 00:57
Python scikit - Ordinary Differential Equation
# 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
@Muhammad-Yunus
Muhammad-Yunus / ODE_DHO_plot.py
Created April 15, 2020 00:59
Python scikit -Ordinary Differential Equation
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();
@Muhammad-Yunus
Muhammad-Yunus / MLP_ODE_init.py
Created April 15, 2020 01:52
MLP ODE Timeseries
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
@Muhammad-Yunus
Muhammad-Yunus / MLP_ODE_Data.py
Created April 15, 2020 01:55
MLP ODE Timeseries
#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,
@Muhammad-Yunus
Muhammad-Yunus / ML_ODE_Split_Data.py
Last active April 15, 2020 01:57
MLP ODE Timeseries
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]
@Muhammad-Yunus
Muhammad-Yunus / MLP_ODE_Init_param.py
Created April 15, 2020 04:33
MLP ODE Timeseries
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)
@Muhammad-Yunus
Muhammad-Yunus / MLP_ODE_Activation.py
Created April 15, 2020 04:44
MLP ODE Timeseries
#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
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]
@Muhammad-Yunus
Muhammad-Yunus / MLP_ODE_ErrorLoss.py
Created April 15, 2020 04:50
MLP ODE Timeseries
def error_calc(target, output):
for k in range(M):
E[k] = 0.5*(target[k] - output[k])**2
return np.sum(E)