-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
67 lines (50 loc) · 1.2 KB
/
test.py
File metadata and controls
67 lines (50 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
def sigmoid(x):
return 1/(1+np.exp(-x))
def MSE(y, y_hat):
return 1/2 * (y_hat - y)**2
def Simple_dev_MSE(y, y_hat):
return y - y_hat
def Dev_sigmoid(x):
return sigmoid(x)*(1-sigmoid(x))
# INPUT
x = np.array([0, 1])
y_hat = 1
# HIDDEN LAYER PARAMS
w = np.array([[0.74, 0.60],
[0.40, 0.30]])
b1 = np.array([-0.01, -0.03])
# OUTPUT LAYER PARAMS
v = np.array([0.12, 0.15])
b2 = np.array([-0.05])
h_3 = w @ x.T + b1
h = sigmoid(h_3)
z_3 = v @ h + b2
y = sigmoid(z_3)
print("h1, h2: ", h_3)
print("z_h_3: ", h)
print("h3: ", z_3)
print("Y: ", y)
print("MSE: ", MSE(y, y_hat))
l_prime = Simple_dev_MSE(y, y_hat)
y_prime = Dev_sigmoid(z_3)*l_prime
z_3_prime = v*y_prime
z_h_prime = Dev_sigmoid(h_3) * z_3_prime
w_prime = np.outer(z_h_prime, x)
print("L Prime: ",l_prime)
print("Y Prime: ",y_prime)
print("Z_3 Prime: ",z_3_prime)
print("z_h Prime: ",z_h_prime)
print("W Prime: ",w_prime)
w -= w_prime
v -= z_3_prime
h_3 = w @ x.T + b1
h = sigmoid(h_3)
z_3 = v @ h + b2
y = sigmoid(z_3)
print("h1, h2: ", h_3)
print("z_h_3: ", h)
print("h3: ", z_3)
print("Y: ", y)
print("MSE: ", MSE(y, y_hat))
print("W: ", w)