This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (68 loc) · 2.24 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
import csv
import recursive_sgd as sgd
from recursive_sgd.model import Model
from recursive_sgd.layers import Linear, AddBias, Sigmoid, ReLU
from recursive_sgd.losses import MSE, CE
import logging
#logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
LEARNING_RATE = 0.03
#np.random.seed(0)
if __name__ == '__main__':
with open("dataset.csv", "r") as f:
dataset = np.array(list(csv.reader(f, delimiter=",")), dtype=np.float64)
#loss = MSE()
loss = CE()
#dataset[dataset[:, 2] == 0, 2] = -1
#dataset = dataset[1:3, :]
#dataset = np.array([[0.1, 0.2, 0.5], [0.3, 0.4, 0.6]])
model = Model()
"""
linear = Linear(2, 2)
linear.W = np.array([[0.15, 0.20], [0.25, 0.30]])
bias = AddBias(2)
bias.b = np.array([[0.35], [0.35]])
model.add_next(linear)
model.add_next(bias)
model.add_next(Sigmoid())
linear = Linear(2, 2)
linear.W = np.array([[0.40, 0.45], [0.50, 0.55]])
bias = AddBias(2)
bias.b = np.array([[0.60], [0.60]])
model.add_next(linear)
model.add_next(bias)
model.add_next(Sigmoid())
#"""
model.add_next(Linear(2, 15));model.add_next(AddBias(15));model.add_next(ReLU())
model.add_next(Linear(15, 15));model.add_next(AddBias(15));model.add_next(Sigmoid())
model.add_next(Linear(15, 15));model.add_next(AddBias(15));model.add_next(ReLU())
model.add_next(Linear(15, 1));model.add_next(AddBias(1));model.add_next(Sigmoid())
sgd.save(model)
#sgd(dataset[:, :2], dataset[:, 2:],
#sgd(np.array([[0.05, 0.10]]),
# np.array([[0.01, 0.99]]),
# model,
# loss,
# batch_size=8,
# batch_size=1,
# epochs=15,
# shuffle=True,
# lr=LEARNING_RATE)
# TESTING
#"""
#x = np.arange(0, 1, 1/100)
#y = np.arange(0, 1, 1/100)
#a = np.transpose([np.tile(x, len(y)), np.repeat(y, len(x))])
#y_test = model.forward(a)
#THR = 0.5
#y_test[y_test >= THR] = 1
#y_test[y_test < THR] = 0
#import matplotlib.pyplot as plt
#plt.scatter(a[:, 0], a[:, 1], c=y_test.flatten().astype(int), s=1)
#plt.show()
# TODO:
# - Add model saving and loading and evaluation mode
# - make python cli interface
#"""