-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathforward.py
More file actions
executable file
·54 lines (33 loc) · 963 Bytes
/
Copy pathforward.py
File metadata and controls
executable file
·54 lines (33 loc) · 963 Bytes
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
#!/usr/bin/env python
import numpy as np
from activation import *
def forward(Theta, X, active):
N = X.shape[0]
# Add the bias column
X_ = np.concatenate((np.ones((N, 1)), X), 1)
# Multiply by the weights
z = np.dot(X_, Theta.T)
# Apply the activation function
a = active.f(z)
return a
def predict(model, X):
h = X.copy()
for i in range(0, len(model), 2):
theta = model[i]
activation = model[i+1]
h = forward(theta, h, activation)
return np.argmax(h, 1)
def accuracy(y_, y):
return np.mean((y_ == y.flatten()))*100.
if __name__ == "__main__":
Theta1 = np.load('input/Theta1.npy')
Theta2 = np.load('input/Theta2.npy')
X = np.load('input/X_train.npy')
y = np.load('input/y_train.npy')
model = []
model.append(Theta1)
model.append(Sigmoid)
model.append(Theta2)
model.append(Sigmoid)
y_ = predict(model, X)
print(accuracy(y_, y))