- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodes2.py
More file actions
Latest commit
44 lines (35 loc) · 1.24 KB
/
Copy pathNodes2.py
File metadata and controls
44 lines (35 loc) · 1.24 KB
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
importtime
importnumpyasnp
fromnumpyimportrandom
defmean_squared_error(a, b=0):
return0.5*np.sum((a-b) **2) # np.square(a-b).mean()
iteration=1
input=np.array([ -314.42844, 70.05509 ])
plaintext=np.array([ 97, 98, 97, 110, 100, 111, 110, 101, 100, 10, 81, 99, 72, 60 ])
# out = []
# for i in plaintext:
# out.append(chr(i))
# print(out)
start_time=time.time()
# for i in range(2, len(plaintext) + 1):
# W1 = (3 + 3) * np.random.random_sample((len(input), i)) - 3
# guess = input.dot(W1)
# loss = mean_squared_error(guess, plaintext[ :i ]) + mean_squared_error(plaintext[ i: ])
# print(np.sum(guess == plaintext))
min_loss=len(plaintext)
i=2# the number of nodes
while1:
print(f"Iteration: {iteration}")
W1= (4+4) *np.random.random_sample((len(input), i)) -4
guess=input.dot(W1)
# loss = mean_squared_error(guess, plaintext[ :i ]) + mean_squared_error(plaintext[ i: ])
error=min(min_loss, ( len(plaintext) -len(np.intersect1d(guess, plaintext)) ) )
iferror<1:
break
else:
print(f"Minimum error is {error}")
iteration+=1
used_time=time.time() -start_time
ifused_time>3600*8:
break
print(f"used_time is: {used_time}")