-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhopfield.py
49 lines (44 loc) · 1.05 KB
/
hopfield.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
import sys
from ast import literal_eval
# Przykład:
# python3 hopfield.py [1,1,1] ((0,-0.666666,0.666666),(-0.666666,0,-0.666666),(0.666666,-0.666666,0))
x = literal_eval(sys.argv[1])
w = literal_eval(sys.argv[2])
for i in range(len(w)):
if len(w[i]) != len(x):
print("Błędne wymiary macierzy!")
exit()
for j in range(len(w[i])):
if w[i][i] < 0:
print("Niespełnione warunki stabilizacji!")
exit()
if w[i][j] != w[j][i]:
print("Niespełnione warunki stabilizacji!")
exit()
def testOutput(x1,x2):
for i in range(len(x1)):
if(x1[i]!=x2[i]):
return False
return True
t = 0
print("t:0")
print("x:",x)
print("------------")
xList = list([x.copy()])
matching = False
while(not matching):
for i in range(len(w)):
suma = 0
t = t+1
print("t:",t)
for j in range(len(w[i])):
suma = suma + x[j]*w[i][j]
print("Suma:",suma)
if suma>0:
x[i] = 1
else:
x[i] = -1
xList.append(x.copy())
print(xList[t])
matching = testOutput(xList[t-len(w)],xList[t])
print("Stablizacja uzyskana!")