In [5]:
import numpy as np
In [16]:
class Layer():
# m: ニューロンの数
# n: 入力の数
def __init__(self, m, n):
self._output = None
self._w = np.random.rand(m, n)
# input: 入力の値: 行列: np.array
def output(self, inputs):
s = self._w.dot(inputs)
return self._activation(s)
# n: ニューロンの数
# s: 出力
def _activation(self, s):
self._output = 1 / (1 + np.exp(-1 * s))
return self._output
if __name__ == '__main__':
# layer1
l1 = Layer(4, 3)
input1 = np.array([[1.], [2.], [4.]])
output1 = l1.output(input1)
print(output1)
# layer2
l2 = Layer(1, 4)
output2 = l2.output(output1)
print(output2)
In [ ]: