-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.py
More file actions
59 lines (28 loc) · 952 Bytes
/
Copy pathvalidation.py
File metadata and controls
59 lines (28 loc) · 952 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
import numpy as np
import argparse
def our_sign(x):
if x>= 0:
return 1
else:
return -1
def net_out(x,w11,w12,w10,w21,w22,w20):
x1 = x[0]
x2 = x[1]
O1 = our_sign(x1*w11 + x2*w12 + w10)
O2 = our_sign(x2*w21 + x2*w22 + w20)
O3 = our_sign(1.0*O1 + 1.0*O2 - 1.5)
return O3
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Input weight, should be w11, w12, w10, w21, w22, w20')
parser.add_argument('--weights', nargs='+', type=float)
args = parser.parse_args()
weight = args.weights
# print(weight)
w11,w12,w10,w21,w22,w20 = weight
X = [[0.5,0.3],[0.4,0.3],[0.3,0.35],[0.4,0.4],[0.45,0.45],[0.5,0.35],[0.55,0.45],[0.4,0.55]]
y = [-1,-1,-1,-1,1,1,1,1]
error = 0
for i in range(8):
if y[i] != net_out(X[i],w11,w12,w10,w21,w22,w20):
error += 1
print("The total score is {}".format(1-error/8))