-
Notifications
You must be signed in to change notification settings - Fork 0
/
dense_model_example.py
37 lines (32 loc) · 1.03 KB
/
dense_model_example.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
import numpy as np
from muskie.models import *
from muskie.layers import *
from muskie.data import *
from muskie.activation_functions import *
from muskie.processing import *
from muskie.optimizers import *
from muskie.loss_functions import *
inputs = np.reshape([[0,0], [0,1], [1,0], [1,1]], (4,2,1))
labels = np.reshape([[1], [0], [0], [1]], (4,1,1))
data = Data(inputs, labels)
model = ClassificationModel([
Dense(input_size=2, output_size=3, activation=Tanh()),
Dense(1),
])
model.summary()
x1 = model.forward(np.reshape([0,0], (2,1)))
x2 = model.forward(np.reshape([0,1], (2,1)))
x3 = model.forward(np.reshape([1,0], (2,1)))
x4 = model.forward(np.reshape([1,1], (2,1)))
train(model=model, data=data, epochs=20000, optimizer=SGD(lr=0.1), loss=MSE())
print("BEFORE TRAINING:")
print(x1)
print(x2)
print(x3)
print(x4)
print("")
print("AFTER TRAINING:")
print(model.forward(np.reshape([0,0], (2,1))))
print(model.forward(np.reshape([0,1], (2,1))))
print(model.forward(np.reshape([1,0], (2,1))))
print(model.forward(np.reshape([1,1], (2,1))))