-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlayer.py
42 lines (30 loc) · 1.04 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
34
35
36
37
38
39
40
41
42
import numpy as np
from activation import func
class Layer:
def __init__(self, n_neuron: int):
self.n_neuron = n_neuron
self.input_data = None
self.output_data = None
self.error = None
def __call__(self, n_input: int):
pass
def calc_output(self, input_data):
pass
class Input(Layer):
def __init__(self, n_neuron: int):
super().__init__(n_neuron)
self.trainable = False
self.activation = func["linear"]
def __call__(self, n_input: int):
self.weight = np.eye(n_input, self.n_neuron)
def calc_output(self, input_data):
return input_data.copy()
class Dense(Layer):
def __init__(self, n_neuron: int, activation: str):
super().__init__(n_neuron)
self.trainable = True
self.activation = func[activation]
def __call__(self, n_input: int):
self.weight = np.random.randn(n_input, self.n_neuron) * np.sqrt(2.0 / n_input)
def calc_output(self, input_data):
return np.matmul(input_data, self.weight)