-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptimize6.py
More file actions
48 lines (39 loc) · 1.15 KB
/
Copy pathOptimize6.py
File metadata and controls
48 lines (39 loc) · 1.15 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
45
46
47
48
from Optimize5 import Adam, Dense, MSE
import numpy as np
epochs = 10000
batch_size = 32
input_size = 3
output_size = 3
model = Dense(input_size, 16)
model = Dense(16, output_size).add_to(model)
mse = MSE().add_to(model)
model.print_summary()
def f(x):
linear_comb = np.expand_dims(np.sum(x * np.array([1, -2, 3]), 1), 1)
average = np.expand_dims(np.sum(x / input_size, 1), 1)
poly = np.expand_dims(5 - x[:, 1] + 3 * x[:, 2], 1)
y_true = np.concatenate([linear_comb, average, poly], 1)
return y_true
print()
print("TRIAL TIME!!!")
x = np.array([[int(input("Enter a number: ")) for i in range(input_size)]])
print("Input:", x[0])
print("Pred:", model(x)[0])
print("True:", f(x)[0])
print()
for _ in range(epochs):
x = np.random.randn(batch_size, input_size)
y_true = f(x)
y = model(x)
l = mse(y, y_true)
if _ % 100 == 0:
print("Average Loss:", np.sum(l) / np.size(l))
mse.update_weights()
print()
print("TRIAL TIME!!!")
while True:
x = np.array([[int(input("Enter a number: ")) for i in range(input_size)]])
print("Input:", x[0])
print("Pred:", model(x)[0])
print("True:", f(x)[0])
print()