-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayer.py
More file actions
28 lines (25 loc) · 895 Bytes
/
layer.py
File metadata and controls
28 lines (25 loc) · 895 Bytes
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
import numpy as np
import functions as fn
class Layer:
s_rand_from = -1
s_rand_to = 1
def __init__(self, prev_layer_size: int, layer_size: int, func):
self.func = func
if func == fn.sig:
self.der_func = fn.der_sig
elif func == fn.ReLU:
self.der_func = fn.ReLU
elif func == fn.softmax:
self.der_func = fn.der_softmax
elif func == fn.tanh:
self.der_func = fn.tanh
else:
raise Exception("Unknown activation function")
self.W = np.random.uniform(Layer.s_rand_from, Layer.s_rand_to,
size=(layer_size, prev_layer_size))
self.bias = np.zeros(layer_size)
self.z = None
self.a = None
def calculate(self, a_prev: np.array):
self.z = np.dot(self.W, a_prev) + self.bias
self.a = self.func(self.z)