def _forward(z: np.array, W: np.array, b: np.array, activation: str) -> np.array: """Propagate the signal from the previous to the next layer.""" a = np.dot(z, W) + b if activation == 'sigmoid': return sigmoid(a) elif activation == 'identity': return identity(a)
def forword(network, x): W1, W2, W3 = network['W1'], network['W2'], network['W3'] b1, b2, b3 = network['b1'], network['b2'], network['b3'] a1 = np.dot(x, W1) + b1 z1 = activation.sigmoid(a1) a2 = np.dot(z1, W2) + b2 z2 = activation.sigmoid(a2) a3 = np.dot(z2, W3) + b3 y = activation.identity(a3) return y
#入力 X = np.array([1.0, 0.5]) #一層の重み W1 = np.array([[0.1, 0.3, 0.5], [0.2, 0.4, 0.6]]) #一層のバイアス B1 = np.array([0.1, 0.2, 0.3]) #一層のの重み付き和 A1 = np.dot(X, W1) + B1 #活性化関数で変換 Z1 = activation.sigmoid(A1) #二層の重み W2 = np.array([[0.1, 0.4], [0.2, 0.5], [0.3, 0.6]]) #二層のバイアス B2 = np.array([0.1, 0.2]) #二層の重み付き和 A2 = np.dot(Z1, W2) + B2 #活性化関数で変換 Z2 = activation.sigmoid(A2) #三層の重み W3 = np.array([[0.1, 0.3], [0.2, 0.4]]) #三層のバイアス B3 = np.array([0.1, 0.2]) #三層の重み付き和 A3 = np.dot(Z2, W3) + B3 #活性化関数で変換 Y = activation.identity(A3) print(Y)
def test_identity_deriv(): """Test identity activation function derivative""" x = np.array([[0, 1, 3], [-1, 0, -5], [1, 0, 3], [10, -9, -7]]) assert np.array_equal(identity(x, deriv=True), np.ones([4, 3]))
def test_identity(): """Test identity activation function""" x = np.array([[0, 1, 3], [-1, 0, -5], [1, 0, 3], [10, -9, -7]]) assert np.array_equal(identity(x), x)