-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.py
33 lines (28 loc) · 1.02 KB
/
layer.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
import numpy as np
class Layer:
# Initialize an emtpy layer with no weights
def __init__(self, number_of_neurons: int, activation_function, inputs=None):
"""
Create a layer with Layer(number of neurons, activation function)
"""
self.uid = None
self.number_of_neurons = number_of_neurons
self.activation_function = activation_function
self.inputs = inputs
self.shape = None
self.data_shape = None
self.weights = None
self.__set_weights()
def process(self, inputs):
self.inputs = inputs
self.__set_weights()
out = inputs.dot(self.weights)
out = self.activation_function(out)
return out
def __set_weights(self):
if self.weights is None and self.inputs is not None:
self.data_shape = self.inputs.shape
self.shape = (self.data_shape[-1], self.number_of_neurons)
self.weights = np.random.random(self.shape)
def __set_id__(self, uid):
self.uid = uid