-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhopfild.py
57 lines (42 loc) · 1003 Bytes
/
hopfild.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
import np
def f(x):
return 1 if x >= 0 else -1
x = [];
w = [];
x.append( np.matrix((-1, 1, -1, 1)) )
x[0] = x[0].transpose()
x.append( np.matrix((1, -1, 1, 1)) )
x[1] = x[1].transpose()
x.append( np.matrix((-1, 1, -1, -1)) )
x[2] = x[2].transpose()
for i in range(len(x)):
w.append( x[i]*x[i].transpose() )
W = w[0]
for i in range(1, len(w)):
W = W + w[i]
for i in range(len(W)):
W[i].transpose()[i] = np.matrix([[0]])
border = 50
finished = False
times = 0
coll = []
print("Print 4 numbers: it'll be the vector to identificate")
for i in range(4):
a = int(input())
coll.append(a)
y = np.matrix(coll)
print("y ==",y)
y = y.transpose()
while not finished and times < border:
y = W*y
for i in range(4):
y[i] = np.matrix((f(y[i])))
for i in range(3):
if bool ((y == x[i]).transpose().all(True)):
finished = True
print(times, y.transpose())
times+=1
if finished:
print(y)
else:
print("Cannot identificate")