-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodes14.py
40 lines (31 loc) · 1.17 KB
/
Nodes14.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
import time
import numpy as np
from numpy import random
def mean_squared_error(a, b=0):
return 0.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 ])
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 = 14 # the number of nodes
while 1:
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)) ) )
if error < 1:
break
else:
print(f"Minimum error is {error}")
iteration += 1
used_time = time.time() - start_time
if used_time > 3600 * 8:
break
print(f"used_time is: {used_time}")