This file contains 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 numpy as np | |
import matplotlib.pyplot as plt | |
NUM_FEATURES = 2 | |
NUM_ITER = 100 | |
learning_rate = 0.1 | |
x = np.array([[0,0],[0,1],[1,0],[1,1]], np.float32) | |
y = np.array([0, 0, 0, 1], np.float32) |
This file contains 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
for i in range(NUM_ITER): | |
y_pred = np.dot(x, W) + b | |
#apply activation | |
y_pred[y_pred > 0] = 1 | |
y_pred[y_pred <= 0] = 0 | |
#calculate error | |
err = y - y_pred | |
This file contains 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
#test | |
x_test = [[0,0],[0,1],[1,0],[1,1]] | |
for x_test_item in x_test : | |
y_test = np.dot(x_test_item, W) + b | |
y_test = 1 if y_test > 0 else 0 | |
print(str(x_test_item[0]) + ' AND ' + str(x_test_item[1]) + ' = ' + str(y_test)) |
This file contains 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
# plot lineary separable class (logic AND) | |
plot_x = np.array([np.min(x[:, 0] - 0.2), np.max(x[:, 1]+0.2)]) | |
plot_y = - 1 / W[1] * (W[0] * plot_x + b) | |
print('W:' + str(W)) | |
print('b:' + str(b)) | |
print('plot_y: '+ str(plot_y)) | |
plt.scatter(x[:, 0], x[:, 1], c=y, s=100, cmap='viridis') |
This file contains 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
for i in range(NUM_ITER): | |
y_pred = np.dot(x, W) + b | |
#activation sigmoid | |
y_pred = 1.0 / (1.0 + np.exp(-y_pred)) | |
err = y - y_pred | |
delta_W = learning_rate * np.dot(np.transpose(x) , err) |
This file contains 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 | |
Month_list = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'] | |
CO_TS = [] | |
CO_TS_LIST = [] | |
for Month in Month_list : | |
print("Read ISPU-di-Provinsi-DKI-Jakarta-Bulan-" + Month + ".csv") | |
CSV_CO_TS = pd.read_csv("ISPU-di-Provinsi-DKI-Jakarta-Bulan-" + Month + ".csv", |
This file contains 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 matplotlib.pyplot as plt | |
fig, axes = plt.subplots(nrows=len(Month_list), ncols=1) | |
fig.subplots_adjust(hspace=0.5) | |
CO_TS = CO_TS[['tanggal', 'co']] | |
CO_TS.index = pd.to_datetime(CO_TS.tanggal) | |
CO_TS.drop(["tanggal"], axis=1, inplace=True) |
This file contains 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
DALIY_CO = CO_TS["CO_rolling_mean"] \ | |
.groupby(CO_TS.index.day) \ | |
.agg(['min', 'max', 'mean']) | |
DALIY_CO.index.name = "Day" | |
ax = DALIY_CO.plot(title='Daily CO Aggregate') | |
ax.legend(loc="lower right") | |
ax.set_ylabel('ug/m3') | |
plt.fill_between(x=DALIY_CO.index, |
This file contains 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 scipy.integrate import odeint, ode | |
import numpy as np | |
import matplotlib.pyplot as plt | |
np.set_printoptions(suppress=True, precision=10) |
This file contains 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 dy(y, t, zeta, w0): | |
x, p = y[0], y[1] | |
dx = p | |
dp = -2 * zeta * w0 * p - w0**2 * x | |
return [dx, dp] |
OlderNewer