-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnn.py
36 lines (26 loc) · 766 Bytes
/
nn.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
class NeuralNet:
def __init__(self):
self.layers = {}
self.fwd_layers = []
self.params = []
def init_params(self):
for l in self.fwd_layers:
l.init_params()
l_params = l.get_params()
if l_params is not None:
self.params += l_params
def get_params(self):
return self.params
def reset_gradients(self):
for l in self.fwd_layers:
l.reset_gradient()
def forward(self):
for l in self.fwd_layers:
l.forward()
def backward(self):
for l in reversed(self.fwd_layers):
l.backward()
def add(self, name, l):
self.layers[name] = l
self.fwd_layers.append(l)
return l