-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
71 lines (45 loc) · 1.53 KB
/
tests.py
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
68
69
70
71
from operator import xor
from types import new_class
from mlp_vectorized import MultilayerPerceptronClassifier
from data_util import *
def xor_test():
N = 100
X, y = get_XOR_data(N)
class_labels = np.argmax(y[:], axis=1)
mlp = MultilayerPerceptronClassifier(X, y, net_shape=(2, 2, 2))
mlp.add_layer(2)
mlp.add_layer(2)
mlp.add_layer(2)
mlp.train(a=0.1, lr=0.001, epochs=10000)
predictions = mlp.predict(X,flat=True)
print("Accuracy:", np.sum(class_labels==predictions)/len(y))
plot_xor_boundaries(mlp, X)
def poly_test():
N = 100
X, y = get_poly_data(N)
class_labels = np.argmax(y[:], axis=1)
mlp = MultilayerPerceptronClassifier(X, y, net_shape=(2, 2, 2))
mlp.add_layer(2)
mlp.add_layer(2)
mlp.add_layer(2)
mlp.train(a=0.5, lr=0.01, epochs=10000)
predictions = mlp.predict(X,flat=True)
print("Accuracy:", np.sum(class_labels==predictions)/len(y))
plot_poly_boundaries(mlp, X, N)
def multi_class_test():
N = 100
X, y = get_multi_class_data(9, N)
class_labels = np.argmax(y[:], axis=1)
mlp = MultilayerPerceptronClassifier(X, y, net_shape=(2, 20, 20, 9))
mlp.add_layer(2)
mlp.add_layer(20)
mlp.add_layer(20)
mlp.add_layer(9)
mlp.train(a=0.3, lr=0.01, epochs=1000)
predictions = mlp.predict(X,flat=True)
print("Accuracy:", np.sum(class_labels==predictions)/len(y))
plot_multi_class_boundaries(mlp, X, N, 9)
if __name__ == "__main__":
#xor_test()
#poly_test()
multi_class_test()